@vuu-ui/vuu-table 0.8.23 → 0.8.24-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 CHANGED
@@ -1,2 +1,3784 @@
1
- "use strict";var nr=Object.create;var Xe=Object.defineProperty;var rr=Object.getOwnPropertyDescriptor;var lr=Object.getOwnPropertyNames;var ir=Object.getPrototypeOf,sr=Object.prototype.hasOwnProperty;var ar=(e,o)=>{for(var t in o)Xe(e,t,{get:o[t],enumerable:!0})},ot=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of lr(o))!sr.call(e,n)&&n!==t&&Xe(e,n,{get:()=>o[n],enumerable:!(r=rr(o,n))||r.enumerable});return e};var ae=(e,o,t)=>(t=e!=null?nr(ir(e)):{},ot(o||!e||!e.__esModule?Xe(t,"default",{value:e,enumerable:!0}):t,e)),ur=e=>ot(Xe({},"__esModule",{value:!0}),e);var dl={};ar(dl,{CheckboxCell:()=>Vo,GroupHeaderCellNext:()=>Ye,HeaderCell:()=>vo,InputCell:()=>Dn,Table:()=>ul,TableCell:()=>wo,TableGroupCell:()=>Ro,ToggleCell:()=>Sn,isShowColumnSettings:()=>No,isShowTableSettings:()=>Fo,noScrolling:()=>un,updateTableConfig:()=>So,useControlledTableNavigation:()=>pl,useTableModel:()=>Ko,useTableScroll:()=>Oo,useTableViewport:()=>$o});module.exports=ur(dl);var pt=require("@vuu-ui/vuu-ui-controls"),dt=require("@vuu-ui/vuu-utils"),bt=ae(require("clsx")),Ie=require("react");var nt=ae(require("clsx")),rt=require("react");var Qe=require("react/jsx-runtime"),tt="vuuColumnHeaderPill",Se=({children:e,className:o,column:t,onRemove:r,removable:n,...l})=>{if(n&&typeof r!="function")throw Error("ColumnHeaderPill onRemove prop must be provided if Pill is removable");let s=(0,rt.useCallback)(i=>{i.preventDefault(),i.stopPropagation(),r==null||r(t)},[t,r]);return(0,Qe.jsxs)("div",{...l,className:(0,nt.default)(tt,o),children:[e,n?(0,Qe.jsx)("span",{className:`${tt}-removeButton`,role:"button","data-icon":"cross",onClick:s}):null]})};var ke=require("react/jsx-runtime"),lt=({column:e,...o})=>{let{name:t,sorted:r}=e,n=typeof r=="number"?r<0?"arrow-down":"arrow-up":r==="A"?"arrow-up":r==="D"?"arrow-down":void 0;return(0,ke.jsxs)(Se,{...o,column:e,children:[(0,ke.jsx)("span",{className:"vuuGroupColumnPill-label",children:t}),n!==void 0?(0,ke.jsx)("span",{"data-icon":n}):null,typeof r=="number"?(0,ke.jsx)("span",{className:"vuuSortPosition",children:Math.abs(r)}):null]})};var Ve=require("react/jsx-runtime"),it=({column:e})=>{if(!e.sorted)return null;let o=typeof e.sorted=="number"?e.sorted<0?"arrow-down":"arrow-up":e.sorted==="A"?"arrow-up":"arrow-down";return(0,Ve.jsxs)(Se,{column:e,children:[(0,Ve.jsx)("span",{"data-icon":o}),typeof e.sorted=="number"?(0,Ve.jsx)("span",{className:"vuuSortPosition",children:Math.abs(e.sorted)}):null]})};var Le=require("react");var at=require("react/jsx-runtime"),st=()=>{},cr="vuuColumnResizerNext",Je=({onDrag:e,onDragEnd:o=st,onDragStart:t=st})=>{let r=(0,Le.useRef)({start:0,now:0}),n=(0,Le.useCallback)(i=>{i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault();let{current:a}=r,u=Math.round(i.clientX),c=u-a.now,p=a.now-a.start;r.current.now=u,c!==0&&e(i,c,p)},[e]),l=(0,Le.useCallback)(i=>{window.removeEventListener("mouseup",l),window.removeEventListener("mousemove",n);let{current:a}=r,u=a.now-a.start;o(i,u)},[o,n]),s=(0,Le.useCallback)(i=>{let{current:a}=r;t(i),a.now=a.start=Math.round(i.clientX),window.addEventListener("mouseup",l),window.addEventListener("mousemove",n),i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault()},[t,n,l]);return(0,at.jsx)("div",{className:cr,onMouseDown:s})};var he=require("react"),Ze=({column:e,onResize:o,rootRef:t})=>{let r=(0,he.useRef)({start:0,now:0}),[n,l]=(0,he.useState)(!1),{name:s}=e,i=(0,he.useCallback)(()=>{if(o&&t.current){let{current:c}=r,{width:p}=t.current.getBoundingClientRect();c.start=c.now=Math.round(p),l(!0),o==null||o("begin",s)}},[s,o,t]),a=(0,he.useCallback)((c,p,f)=>{if(t.current&&o){let{current:g}=r,C=g.start+f;C!==g.now&&C>0&&(o("resize",s,C),g.now=C)}},[s,o,t]),u=(0,he.useCallback)(()=>{if(o){let{current:c}=r;o("end",s,c.now),setTimeout(()=>{l(!1)},80)}},[s,o]);return{isResizing:n,onDrag:a,onDragStart:i,onDragEnd:u}};var ut=require("@vuu-ui/vuu-utils"),ct=ae(require("clsx")),mt=require("react"),xe=(e,o,t)=>(0,mt.useMemo)(()=>{let r=(0,ct.default)(o,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:t&&e.endPin,[`${o}-editable`]:e.editable,[`${o}-right`]:e.align==="right"}),n=(0,ut.getColumnStyle)(e);return{className:r,style:n}},[e,o,t]);var Ae=require("react/jsx-runtime"),ft=require("react"),Co="vuuTableGroupHeaderCell",mr=(e,o)=>e===o?e:o,Ye=({column:e,className:o,onMoveColumn:t,onRemoveColumn:r,onResize:n,...l})=>{let s=(0,Ie.useRef)(null),{isResizing:i,...a}=Ze({column:e,onResize:n,rootRef:s}),[u,c]=(0,Ie.useState)(e.columns),{className:p,style:f}=xe(e,Co,!0),g=u.length>1?{removable:!0,onRemove:r}:void 0,C=(0,Ie.useCallback)((T,m)=>{c(h=>{let x=h.slice(),[k]=x.splice(T,1);if(m===-1){let L=x.concat(k);return t==null||t(L),L}else return x.splice(m,0,k),t==null||t(x),x})},[t]);return(0,dt.useLayoutEffectSkipFirst)(()=>{c(T=>mr(T,e.columns))},[e.columns]),(0,Ae.jsxs)("div",{...l,className:(0,bt.default)(p,o,{[`${Co}-pending`]:e.groupConfirmed===!1}),ref:s,role:"columnheader",style:f,children:[(0,Ae.jsx)(pt.OverflowContainer,{allowDragDrop:!0,className:`${Co}-inner`,height:24,onMoveItem:C,overflowPosition:"start",children:u.map(T=>(0,ft.createElement)(lt,{...g,column:T,key:T.name}))}),(0,Ae.jsx)(Se,{column:e,removable:!0,onRemove:r}),e.resizeable!==!1?(0,Ae.jsx)(Je,{...a}):null]})};var xt=ae(require("clsx")),qe=require("react");var gt=require("@vuu-ui/vuu-popups"),Ct=ae(require("clsx")),ye=require("react");var ht=require("react/jsx-runtime"),pr=e=>{if(e){let{bottom:o,left:t}=e.getBoundingClientRect();return{x:t,y:o+6}}},vt=({className:e,column:o,...t})=>{let r=(0,ye.useRef)(null),[n,l]=(0,ye.useState)(!1),[s]=(0,gt.useContextMenu)(),i=(0,ye.useCallback)(()=>{l(!1)},[]),a=(0,ye.useCallback)(u=>{l(!0),s(u,"column-menu",{column:o,ContextMenuProps:{onClose:i,position:pr(r.current)}})},[o,i,s]);return(0,ht.jsx)("span",{...t,className:(0,Ct.default)("vuuTable-columnMenu",e,{"vuuTable-columnMenu-open":n}),"data-icon":"more-vert",onClick:a,ref:r})};var de=require("react/jsx-runtime"),je="vuuTableHeaderCell",vo=({className:e,column:o,onClick:t,onResize:r,...n})=>{var x;let{HeaderCellContentRenderer:l,HeaderCellLabelRenderer:s}=o,i=(0,qe.useRef)(null),{isResizing:a,...u}=Ze({column:o,onResize:r,rootRef:i}),c=(0,qe.useCallback)(k=>{!a&&(t==null||t(k))},[a,t]),{className:p,style:f}=xe(o,je,!0),g=(0,de.jsx)(vt,{column:o}),C=s?(0,de.jsx)(s,{className:`${je}-label`,column:o}):(0,de.jsx)("div",{className:`${je}-label`,children:(x=o.label)!=null?x:o.name}),T=l?[(0,de.jsx)(l,{column:o},"content")]:[],m=(0,de.jsx)(it,{column:o}),h=o.align==="right"?[m,C].concat(T).concat(g):[g,C,m].concat(T);return(0,de.jsxs)("div",{...n,className:(0,xt.default)(p,e,{[`${je}-resizing`]:a}),onClick:c,ref:i,role:"columnheader",style:f,children:[...h,o.resizeable!==!1?(0,de.jsx)(Je,{...u}):null]})};var Cn=require("@vuu-ui/vuu-popups"),vn=require("@vuu-ui/vuu-ui-controls"),io=require("@vuu-ui/vuu-utils"),hn=require("@salt-ds/core"),Go=ae(require("clsx")),$e=require("react");var ee=require("@vuu-ui/vuu-utils"),yt=ae(require("clsx")),We=require("react");var wt=require("@vuu-ui/vuu-utils"),ho=require("react");var xo=require("react/jsx-runtime"),dr="vuuTableCell",wo=({column:e,columnMap:o,onClick:t,onDataEdited:r,row:n})=>{let{className:l,style:s}=xe(e,dr),{CellRenderer:i,index:a,name:u,valueFormatter:c}=e,p=o[u],f=(0,ho.useCallback)(C=>{if(r){let T=C;return(0,wt.isNumericColumn)(e)&&typeof C=="string"&&(T=e.serverDataType==="double"?parseFloat(C):parseInt(C)),r==null?void 0:r(n,u,T)}else throw Error("TableCell onDataEdited prop not supplied for an editable cell")},[e,u,r,n]),g=(0,ho.useCallback)(C=>{t==null||t(C,e)},[e,t]);return(0,xo.jsx)("div",{"aria-colindex":a,className:l,onClick:t?g:void 0,role:"cell",style:s,children:i?(0,xo.jsx)(i,{column:e,columnMap:o,onCommit:f,row:n}):c(n[p])})};var eo=require("@vuu-ui/vuu-utils"),Tt=require("react");var Rt=ae(require("clsx"));var ze=require("react/jsx-runtime"),{IS_LEAF:br}=eo.metadataKeys,To="vuuTableGroupCell",Ro=({column:e,columnMap:o,onClick:t,row:r})=>{let{columns:n}=e,[l,s]=(0,eo.getGroupValueAndOffset)(n,r,o),{className:i,style:a}=xe(e,To),u=(0,Tt.useCallback)(f=>{t==null||t(f,e)},[e,t]),c=r[br],p=Array(s).fill(0).map((f,g)=>(0,ze.jsx)("span",{className:`${To}-spacer`},g));return(0,ze.jsxs)("div",{className:(0,Rt.default)(i,"vuuTableCell"),role:"cell",style:a,onClick:c?void 0:u,children:[p,c?null:(0,ze.jsx)("span",{className:`${To}-toggle`,"data-icon":"triangle-right"}),(0,ze.jsx)("span",{children:l})]})};var De=require("react/jsx-runtime"),{IDX:fr,IS_EXPANDED:gr,SELECTED:Cr}=ee.metadataKeys,be="vuuTableRow",yo=(0,We.memo)(({className:e,columnMap:o,columns:t,highlighted:r,row:n,offset:l,onClick:s,onDataEdited:i,onToggleGroup:a,virtualColSpan:u=0,zebraStripes:c=!1,...p})=>{let{[fr]:f,[gr]:g,[Cr]:C}=n,T=(0,We.useCallback)(E=>{let I=E.shiftKey,O=E.ctrlKey||E.metaKey;s==null||s(n,I,O)},[s,n]),{True:m,First:h,Last:x}=ee.RowSelected,k=(0,yt.default)(be,e,{[`${be}-even`]:c&&f%2===0,[`${be}-expanded`]:g,[`${be}-highlighted`]:r,[`${be}-selected`]:C&m,[`${be}-selectedStart`]:C&h,[`${be}-selectedEnd`]:C&x}),L={transform:`translate3d(0px, ${l}px, 0px)`},S=(0,We.useCallback)((E,I)=>{((0,ee.isGroupColumn)(I)||(0,ee.isJsonGroup)(I,n,o))&&(E.stopPropagation(),a==null||a(n,I))},[o,a,n]);return(0,De.jsxs)("div",{...p,role:"row",className:k,onClick:T,style:L,children:[(0,De.jsx)("span",{className:`${be}-selectionDecorator vuuStickyLeft`}),u>0?(0,De.jsx)("div",{className:"vuuTableCell",style:{width:u}}):null,t.filter(ee.isNotHidden).map(E=>{let I=(0,ee.isGroupColumn)(E),O=(0,ee.isJsonColumn)(E);return(0,De.jsx)(I?Ro:wo,{column:E,columnMap:o,onClick:I||O?S:void 0,onDataEdited:i,row:n},E.name)}),(0,De.jsx)("span",{className:`${be}-selectionDecorator vuuStickyRight`})]})});yo.displayName="Row";var oo=require("@vuu-ui/vuu-utils"),Ht=ae(require("clsx")),Pt=require("react");var Dt=require("@vuu-ui/vuu-ui-controls"),Ne=require("@vuu-ui/vuu-utils"),Me=require("react"),Mt=({columns:e,onMoveColumn:o,onSortColumn:t,tableConfig:r})=>{let n=(0,Me.useRef)(null),l=(0,Me.useRef)(null),s=(0,Me.useCallback)(f=>{n.current=f,f?l.current=f.closest(".vuuTable-contentContainer"):l.current=null},[]),i=(0,Me.useCallback)(({fromIndex:f,toIndex:g})=>{let C=e[f],T=(0,Ne.moveColumnTo)(e,C,g),m=({name:L})=>S=>S.name===L,h=T.findIndex(m(C)),x=T[h+1],k=x?r.columns.findIndex(m(x)):-1;g>f&&k!==-1?o((0,Ne.moveColumnTo)(r.columns,C,k-1)):o((0,Ne.moveColumnTo)(r.columns,C,k))},[e,o,r.columns]),a=(0,Me.useCallback)(f=>{var x;let C=f.target.closest(".vuuTableHeaderCell"),T=parseInt((x=C==null?void 0:C.dataset.index)!=null?x:"-1"),m=(0,Ne.visibleColumnAtIndex)(e,T),h=f.shiftKey;m&&t(m,h)},[e,t]),{onMouseDown:u,draggable:c,...p}=(0,Dt.useDragDrop)({allowDragDrop:!0,containerRef:n,draggableClassName:"vuuTable",itemQuery:".vuuTableHeaderCell",onDrop:i,orientation:"horizontal",scrollingContainerRef:l});return{draggableColumn:c,draggedColumnIndex:p.draggedItemIndex,onClick:a,onMouseDown:u,setContainerRef:s}};var fe=require("react/jsx-runtime"),Do=(0,Pt.memo)(({classBase:e="vuuTable",columns:o,headings:t,onMoveColumn:r,onMoveGroupColumn:n,onRemoveGroupColumn:l,onResizeColumn:s,onSortColumn:i,tableConfig:a,tableId:u,virtualColSpan:c=0})=>{let{draggableColumn:p,draggedColumnIndex:f,onClick:g,onMouseDown:C,setContainerRef:T}=Mt({columns:o,onMoveColumn:r,onSortColumn:i,tableConfig:a});return(0,fe.jsxs)("div",{className:`${e}-col-headings`,ref:T,children:[t.map((m,h)=>(0,fe.jsx)("div",{className:"vuuTable-heading",children:m.map(({label:x,width:k},L)=>(0,fe.jsx)("div",{className:"vuuTable-headingCell",style:{width:k},children:x},L))},h)),(0,fe.jsxs)("div",{className:`${e}-col-headers`,role:"row",children:[c>0?(0,fe.jsx)("div",{role:"cell",className:"vuuTableCell",style:{width:c}}):null,o.filter(oo.isNotHidden).map((m,h)=>(0,oo.isGroupColumn)(m)?(0,fe.jsx)(Ye,{"aria-colindex":m.index,column:m,"data-index":h,onMoveColumn:n,onRemoveColumn:l,onResize:s},m.name):(0,fe.jsx)(vo,{"aria-colindex":m.index,className:(0,Ht.default)({"vuuDraggable-dragAway":h===f}),column:m,"data-index":h,id:`${u}-col-${h}`,onClick:g,onMouseDown:C,onResize:s},m.name)),p]})]})});Do.displayName="TableHeader";var fn=require("@vuu-ui/vuu-ui-controls"),W=require("@vuu-ui/vuu-utils"),H=require("react");var Et=require("@vuu-ui/vuu-utils"),St=e=>(o,t)=>{let r=[];return e===void 0||(o==="header"||o==="column-menu")&&(r.push(...vr(t,e)),r.push(...wr(t,e)),r.push(...hr(t,e)),r.push(...xr(t)),r.push({action:"column-settings",icon:"cog",label:"Column Settings",options:t}),r.push({action:"table-settings",icon:"cog",label:"DataGrid Settings",options:t})),r};function vr(e,{sort:{sortDefs:o}}){let{column:t}=e,r=[];if(t===void 0)return r;let n=o.length>0;return t.sorted==="A"?r.push({label:"Reverse Sort (DSC)",action:"sort-dsc",options:e}):t.sorted==="D"?r.push({label:"Reverse Sort (ASC)",action:"sort-asc",options:e}):typeof t.sorted=="number"?(t.sorted>0?r.push({label:"Reverse Sort (DSC)",action:"sort-add-dsc",options:e}):r.push({label:"Reverse Sort (ASC)",action:"sort-add-asc",options:e}),n&&Math.abs(t.sorted)<o.length&&r.push({label:"Remove from sort",action:"sort-remove",options:e}),r.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):n?(r.push({label:"Add to sort",children:[{label:"Ascending",action:"sort-add-asc",options:e},{label:"Descending",action:"sort-add-dsc",options:e}]}),r.push({label:"New Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]})):r.push({label:"Sort",children:[{label:"Ascending",action:"sort-asc",options:e},{label:"Descending",action:"sort-dsc",options:e}]}),r}function hr(e,o){let{column:t}=e;if(t===void 0||o.groupBy.length===0)return[];let{name:r,label:n=r}=t;return[{label:`Aggregate ${n}`,children:[{label:"Count",action:"agg-count",options:e},{label:"Distinct",action:"agg-distinct",options:e}].concat((0,Et.isNumericColumn)(t)?[{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 Eo=(e,o)=>({label:`Pin ${o}`,action:`column-pin-${o}`,options:e}),Mo=e=>Eo(e,"left"),Ho=e=>Eo(e,"floating"),Po=e=>Eo(e,"right");function xr(e){let{column:o}=e;if(o===void 0)return[];let{pin:t}=o,r=[{label:"Hide column",action:"column-hide",options:e},{label:"Remove column",action:"column-remove",options:e}];return t===void 0?r.push({label:"Pin column",children:[Mo(e),Ho(e),Po(e)]}):t==="left"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Ho(e),Po(e)]}):t==="right"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Mo(e),Ho(e)]}):t==="floating"&&r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Mo(e),Po(e)]}),r}function wr(e,{groupBy:o}){let{column:t}=e,r=[];if(t===void 0)return r;let{name:n,label:l=n}=t;return o.length===0?r.push({label:`Group by ${l}`,action:"group",options:e}):r.push({label:`Add ${l} to group by`,action:"group-add",options:e}),r}var kt=require("@vuu-ui/vuu-utils"),V=require("@vuu-ui/vuu-utils"),Tr=(e,o)=>{if(e.filterStruct&&o){let[t,r]=(0,kt.removeColumnFromFilter)(o,e.filterStruct);return{filter:r,filterStruct:t}}else return e},{Average:Rr,Count:yr,Distinct:Dr,High:Mr,Low:Hr,Sum:Pr}=V.AggregationType,Lt=({dataSource:e,onPersistentColumnOperation:o})=>r=>{let n=r.options;if(n.column&&e){let{column:l}=n;switch(r.menuId){case"sort-asc":return e.sort=(0,V.setSortColumn)(e.sort,l,"A"),!0;case"sort-dsc":return e.sort=(0,V.setSortColumn)(e.sort,l,"D"),!0;case"sort-add-asc":return e.sort=(0,V.addSortColumn)(e.sort,l,"A"),!0;case"sort-add-dsc":return e.sort=(0,V.addSortColumn)(e.sort,l,"D"),!0;case"group":return e.groupBy=(0,V.addGroupColumn)(e.groupBy,l),!0;case"group-add":return e.groupBy=(0,V.addGroupColumn)(e.groupBy,l),!0;case"column-hide":return o({type:"hideColumns",columns:[l]}),!0;case"column-remove":return e.columns=e.columns.filter(s=>s!==l.name),!0;case"filter-remove-column":return e.filter=Tr(e.filter,l),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=(0,V.setAggregations)(e.aggregations,l,Rr),!0;case"agg-high":return e.aggregations=(0,V.setAggregations)(e.aggregations,l,Mr),!0;case"agg-low":return e.aggregations=(0,V.setAggregations)(e.aggregations,l,Hr),!0;case"agg-count":return e.aggregations=(0,V.setAggregations)(e.aggregations,l,yr),!0;case"agg-distinct":return e.aggregations=(0,V.setAggregations)(e.aggregations,l,Dr),!0;case"agg-sum":return e.aggregations=(0,V.setAggregations)(e.aggregations,l,Pr),!0;case"column-pin-floating":return o({type:"pinColumn",column:l,pin:"floating"}),!0;case"column-pin-left":return o({type:"pinColumn",column:l,pin:"left"}),!0;case"column-pin-right":return o({type:"pinColumn",column:l,pin:"right"}),!0;case"column-unpin":return o({type:"pinColumn",column:l,pin:void 0}),!0;case"column-settings":return o({type:"columnSettings",column:l}),!0;case"table-settings":return o({type:"tableSettings"}),!0;default:}}return!1};var So=(e,o)=>{switch(o.type){case"col-size":return{...e,columns:e.columns.map(t=>t.name===o.column.name?{...t,width:o.width}:t)};case"column-prop":return{...e,columns:e.columns.map(t=>t.name===o.column.name?{...t,[o.property]:o.value}:t)};default:return e}};var Ft=require("@vuu-ui/vuu-utils"),we=require("react");var ko=e=>`.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${e})`,Lo=(e,o)=>`.vuuTable-body > [aria-rowindex='${e+1}'] > [role='cell']:nth-child(${o+1})`,At=(e,[o,t])=>{var l;let r=o===-1?ko(t):Lo(o,t),n=(l=e.current)==null?void 0:l.querySelector(r);return Er(n)&&n.querySelector("button")||n},Er=e=>e==null?void 0:e.classList.contains("vuuTableCell-editable"),It=e=>e.querySelector(".vuuTableInputCell")!==null;function Sr(e){if(e){let o=e.ariaRowIndex;if(o!==null)return parseInt(o,10)-1}return-1}var kr=e=>e.closest('[role="row"]'),zt=e=>Sr(kr(e)),Lr=[void 0,void 0],Nt=(e,o,t=e.closest(".vuuTable-contentContainer"))=>{if(t){let r=t==null?void 0:t.getBoundingClientRect(),n=r.top+o,l=e.getBoundingClientRect();if(l)return l.bottom>r.bottom?["down",l.bottom-r.bottom]:l.top<n?["up",l.top-n]:Lr;throw Error("Whats going on, row not found")}else throw Error("Whats going on, scrollbar container not found")};var Kt=({navigate:e})=>{let o=(0,we.useCallback)(()=>{e()},[e]),t=(0,we.useCallback)(a=>{let u=a.target,c=u.matches("input")?u:u.querySelector("input");c&&(c.focus(),c.select())},[]),r=(0,we.useCallback)(a=>{let c=a.target.querySelector("input");c&&(c.focus(),c.select())},[]),n=(0,we.useCallback)(a=>{let u=a.target;It(u)&&((0,Ft.isCharacterKey)(a.key)?t(a):a.key==="Enter"&&r(a))},[t,r]),l=(0,we.useCallback)(a=>{let u=a.target;(u.matches("input")||u.querySelector("input"))&&(t(a),a.stopPropagation())},[t]),s=(0,we.useCallback)(a=>{a.target.removeEventListener("vuu-commit",o,!0)},[o]),i=(0,we.useCallback)(a=>{a.target.addEventListener("vuu-commit",o,!0)},[o]);return{onBlur:s,onDoubleClick:l,onFocus:i,onKeyDown:n}};var Te=require("@vuu-ui/vuu-utils"),U=require("react");var Fe=require("@vuu-ui/vuu-utils"),{SELECTED:Ao}=Fe.metadataKeys,to=class{constructor({from:o,to:t}){this.rowCount=0;this.setRowCount=o=>{o<this.data.length&&(this.data.length=o),this.rowCount=o};this.range=new Fe.WindowRange(o,t),this.data=new Array(Math.max(0,t-o)),this.rowCount=0}add(o){let[t]=o;if(this.isWithinRange(t)){let r=t-this.range.from;if(this.data[r]=o,o[Ao]){let n=this.data[r-1];(0,Fe.isRowSelectedLast)(n)&&(this.data[r-1]=n.slice(),this.data[r-1][Ao]-=4)}}}getAtIndex(o){return this.range.isWithin(o)&&this.data[o-this.range.from]!=null?this.data[o-this.range.from]:void 0}isWithinRange(o){return this.range.isWithin(o)}setRange({from:o,to:t}){if(o!==this.range.from||t!==this.range.to){let[r,n]=this.range.overlap(o,t),l=new Array(Math.max(0,t-o));for(let s=r;s<n;s++){let i=this.getAtIndex(s);if(i){let a=s-o;l[a]=i}}this.data=l,this.range.from=o,this.range.to=t}}getSelectedRows(){return this.data.filter(o=>o[Ao]!==0)}};var Ar=e=>e.type==="vuu-link-created"||e.type==="vuu-link-removed",Ot=({dataSource:e,onFeatureInvocation:o,onSizeChange:t,onSubscribed:r,range:n=Te.NULL_RANGE,renderBufferSize:l=0})=>{let[,s]=(0,U.useState)(null),i=(0,U.useRef)([]),a=(0,U.useRef)(!0),u=(0,U.useRef)(!1),c=(0,U.useRef)(n),p=(0,U.useMemo)(()=>new to((0,Te.getFullRange)(n,l)),[]),f=(0,U.useCallback)(m=>{for(let h of m)p.add(h);i.current=p.data,a.current?s({}):console.log("ignore update as we're not mounted")},[p]),g=(0,U.useCallback)(m=>{m.type==="subscribed"?r==null||r(m):m.type==="viewport-update"?(typeof m.size=="number"&&(t==null||t(m.size),p.setRowCount(m.size)),m.rows?f(m.rows):typeof m.size=="number"&&(i.current=p.data,u.current=!0)):Ar(m)?o==null||o(m):console.log(`useDataSource unexpected message ${m.type}`)},[p,o,t,r,f]),C=(0,U.useCallback)(()=>p.getSelectedRows(),[p]);(0,U.useEffect)(()=>{var m;return a.current=!0,(m=e.resume)==null||m.call(e),()=>{var h;a.current=!1,(h=e.suspend)==null||h.call(e)}},[e]),(0,U.useEffect)(()=>{var m;e.status==="disabled"?(m=e.enable)==null||m.call(e,g):e==null||e.subscribe({range:(0,Te.getFullRange)(n,l)},g)},[e,g,n,l]);let T=(0,U.useCallback)(m=>{if(!(0,Te.rangesAreSame)(m,c.current)){let h=(0,Te.getFullRange)(m,l);p.setRange(h),e.range=c.current=h,e.emit("range",m)}},[e,p,l]);return{data:i.current,dataRef:i,getSelectedRows:C,range:c.current,setRange:T}};var no=require("react"),$t=e=>{let o=(0,no.useRef)(e);return(0,no.useMemo)(()=>o.current,[])};var Vt=require("@vuu-ui/vuu-utils"),Wt=require("@salt-ds/core"),K=require("react");var Ut=new Set(["Home","End","PageUp","PageDown","ArrowDown","ArrowUp"]),Io=new Set(Ut);Io.add("ArrowLeft");Io.add("ArrowRight");var Ir=(e,o)=>{switch(o){case"cell":return Io.has(e);case"row":return Ut.has(e);default:return!1}},zr=["Home","End","PageUp","PageDown"],Gt=e=>zr.includes(e),Nr=[-1,-1];function Bt(e,[o,t],r,n){return e==="ArrowUp"?o>-1?[o-1,t]:[o,t]:e==="ArrowDown"?o===-1?[0,t]:o===n-1?[o,t]:[o+1,t]:e==="ArrowRight"?t<r?[o,t+1]:[o,t]:e==="ArrowLeft"?t>1?[o,t-1]:[o,t]:[o,t]}var _t=({columnCount:e=0,containerRef:o,disableFocus:t=!1,defaultHighlightedIndex:r,disableHighlightOnFocus:n,highlightedIndex:l,navigationStyle:s,requestScroll:i,onHighlight:a,rowCount:u=0,viewportRowCount:c})=>{var F;let p=(0,K.useRef)([-1,-1]),f=(0,K.useRef)(),g=(0,K.useRef)([-1,0]),C=(0,K.useRef)(),[T,m]=(0,Wt.useControlled)({controlled:l,default:r,name:"UseKeyboardNavigation"});C.current=T;let h=(0,K.useCallback)((v,w=!1)=>{a==null||a(v),m(v)},[a,m]),x=v=>v==null?void 0:v.closest("[role='columnHeader'],[role='cell']"),k=v=>{var w;if(v.role==="columnHeader")return[-1,parseInt((w=v.dataset.idx)!=null?w:"-1",10)];{let b=v.closest("[role='row']");if(b){let y=(0,Vt.getIndexFromRowElement)(b),D=Array.from(b.childNodes).indexOf(v);return[y,D]}}return Nr},L=(0,K.useCallback)(v=>{var w;if(o.current){let b=At(o,v);b&&(b!==f.current&&((w=f.current)==null||w.removeAttribute("tabindex"),f.current=b,b.setAttribute("tabindex","0")),i==null||i({type:"scroll-row",rowIndex:v[0]}),b.focus({preventScroll:!0}))}},[o,i]),S=(0,K.useCallback)((v,w,b=!1)=>{let y=[v,w];g.current=y,s==="row"?m(v):L(y),b&&(p.current=y)},[L,s,m]),E=(0,K.useCallback)((v,[w,b])=>new Promise(y=>{let D=w;switch(v){case"PageDown":{D=Math.min(u-1,w+c),D!==w&&(i==null||i({type:"scroll-page",direction:"down"}));break}case"PageUp":{D=Math.max(0,w-c),D!==w&&(i==null||i({type:"scroll-page",direction:"up"}));break}case"Home":{D=0,D!==w&&(i==null||i({type:"scroll-end",direction:"home"}));break}case"End":{D=u-1,D!==w&&(i==null||i({type:"scroll-end",direction:"end"}));break}}setTimeout(()=>{y([D,b])},35)}),[i,u,c]),I=(0,K.useCallback)(()=>{var v;if(n!==!0&&(v=o.current)!=null&&v.contains(document.activeElement)){let w=x(document.activeElement);w&&(p.current=k(w),s==="row"&&m(p.current[0]))}},[n,o,s,m]),O=(0,K.useCallback)(async v=>{let[w,b]=Gt(v)?await E(v,g.current):Bt(v,g.current,e,u),[y,D]=g.current;(w!==y||b!==D)&&S(w,b,!0)},[e,E,u,S]),G=(0,K.useCallback)(v=>{i==null||i({type:"scroll-row",rowIndex:v})},[i]),_=(0,K.useCallback)(async v=>{let{current:w}=C,[b]=Gt(v)?await E(v,[w!=null?w:-1,0]):Bt(v,[w!=null?w:-1,0],e,u);b!==w&&(h(b),G(b))},[e,E,u,G,h]);(0,K.useEffect)(()=>{l!==void 0&&l!==-1&&G(l)},[l,G]);let Q=(0,K.useCallback)(v=>{u>0&&Ir(v.key,s)&&(v.preventDefault(),v.stopPropagation(),s==="row"?_(v.key):O(v.key))},[u,s,_,O]),ue=(0,K.useCallback)(v=>{let w=v.target,b=x(w);if(b){let[y,D]=k(b);S(y,D)}},[S]),z=(0,K.useCallback)(()=>{h(-1)},[h]),P=(0,K.useCallback)(v=>{let w=zt(v.target);w!==-1&&w!==C.current&&h(w)},[h]),ce=(0,K.useCallback)(()=>{O("ArrowDown")},[O]),Ce=((F=o.current)==null?void 0:F.firstChild)!=null;return(0,K.useEffect)(()=>{if(Ce&&f.current===void 0&&!t){let{current:v}=o,w=(v==null?void 0:v.querySelector(ko(0)))||(v==null?void 0:v.querySelector(Lo(0,0)));w&&(w.setAttribute("tabindex","0"),f.current=w)}},[o,t,Ce]),{highlightedIndexRef:C,navigate:ce,onClick:ue,onFocus:I,onKeyDown:Q,onMouseLeave:s==="row"?z:void 0,onMouseMove:s==="row"?P:void 0}};var me=require("@vuu-ui/vuu-utils"),He=require("react"),{IDX:Fr}=me.metadataKeys,Kr=[],Or=["Enter"," "],Xt=({highlightedIndexRef:e,selectionKeys:o=Or,selectionModel:t,onSelect:r,onSelectionChange:n})=>{let l=(0,He.useRef)(-1),s=(0,He.useRef)(Kr),i=(0,He.useCallback)(c=>o.includes(c.key),[o]),a=(0,He.useCallback)((c,p,f)=>{let{[Fr]:g}=c,{current:C}=l,{current:T}=s,h=((0,me.isRowSelected)(c)?me.deselectItem:me.selectItem)(t,T,g,p,f,C);s.current=h,l.current=g,r==null||r(c),n==null||n(h)},[r,n,t]);return{onKeyDown:(0,He.useCallback)(c=>{if(i(c)){let{current:p}=e;if(p!==void 0&&p!==-1){let f=c.target.querySelector(`[aria-rowindex="${p}"]`);f&&(0,me.dispatchMouseEvent)(f,"click")}}},[e,i]),onRowClick:a}};var Qt=require("@vuu-ui/vuu-popups"),ro=require("@vuu-ui/vuu-utils"),Jt=require("react"),$r=[],Zt=({columns:e,data:o,dataSource:t,getSelectedRows:r})=>{let[n]=(0,Qt.useContextMenu)();return(0,Jt.useCallback)(s=>{let i=s.target,a=i==null?void 0:i.closest("div[role='cell']"),u=i==null?void 0:i.closest("div[role='row']");if(a&&u){let{selectedRowsCount:c}=t,p=(0,ro.buildColumnMap)(e),f=(0,ro.getIndexFromRowElement)(u),g=Array.from(u.childNodes).indexOf(a),C=o.find(([m])=>m===f),T=e[g];n(s,"grid",{columnMap:p,columnName:T,row:C,selectedRows:c===0?$r:r(),viewport:t.viewport})}},[e,o,t,r,n])};var R=require("@vuu-ui/vuu-utils"),Yt=require("@vuu-ui/vuu-ui-controls"),jt=require("react"),{info:zo}=(0,R.logger)("useTableModel"),Gr=100,Br=({serverDataType:e})=>e===void 0,qt=(e,o)=>{let t=o==null?void 0:o.columns.find(({name:r})=>r===e.name);return t?t.serverDataType:e.serverDataType},Vr=["int","long","double"],en=e=>e===void 0?void 0:Vr.includes(e)?"right":"left",No=e=>e.type==="columnSettings",Fo=e=>e.type==="tableSettings",Wr=(e,o)=>{switch(zo==null||zo(`TableModelReducer ${o.type}`),o.type){case"init":return on(o);case"moveColumn":return _r(e,o);case"resizeColumn":return Jr(e,o);case"setTableSchema":return Zr(e,o);case"hideColumns":return Xr(e,o);case"showColumns":return Qr(e,o);case"pinColumn":return Yr(e,o);case"updateColumnProp":return Ke(e,o);case"tableConfig":return nn(e,o);default:return console.log(`unhandled action ${o.type}`),e}},Ko=(e,o)=>{let[t,r]=(0,jt.useReducer)(Wr,{tableConfig:e,dataSource:o},on),{columns:n,headings:l,tableConfig:s,...i}=t;return{columns:n,dispatchColumnAction:r,headings:l,tableAttributes:i,tableConfig:s}};function on({dataSource:e,tableConfig:o}){let{columns:t,...r}=o,{config:n,tableSchema:l}=e,s=t.filter((0,R.subscribedOnly)(n==null?void 0:n.columns)).map(tn(r,l)),i=s.some(R.isPinned)?(0,R.sortPinnedColumns)(s):s,a={columns:i,headings:(0,R.getTableHeadings)(i),tableConfig:o,...r};if(n){let{columns:u,...c}=n;a=nn(a,{type:"tableConfig",...c})}return a}var Ur=(e,o)=>o==="uppercase"?e.toUpperCase():o==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,tn=(e,o)=>(t,r)=>{let{columnDefaultWidth:n=Gr,columnFormatHeader:l}=e,s=qt(t,o),{align:i=en(s),name:a,label:u=(0,R.getColumnLabel)(t),width:c=n,...p}=t,f={...p,align:i,CellRenderer:(0,R.getCellRenderer)(t),HeaderCellContentRenderer:(0,R.getColumnHeaderContentRenderer)(t),HeaderCellLabelRenderer:(0,R.getColumnHeaderLabelRenderer)(t),clientSideEditValidationCheck:(0,R.hasValidationRules)(t.type)?(0,Yt.buildValidationChecker)(t.type.renderer.rules):void 0,index:r+1,label:Ur(u,l),name:a,originalIdx:r,serverDataType:s,valueFormatter:(0,R.getValueFormatter)(t,s),width:c};return(0,R.isGroupColumn)(f)&&(f.columns=f.columns.map(g=>tn(e)(g,r))),f};function _r(e,{column:o,moveBy:t}){let{columns:r}=e;if(typeof t=="number"){let n=r.indexOf(o),l=r.slice(),[s]=l.splice(n,1);return l.splice(n+t,0,s),{...e,columns:l}}return e}function Xr(e,{columns:o}){return o.some(t=>t.hidden!==!0)?o.reduce((t,r)=>r.hidden!==!0?Ke(t,{type:"updateColumnProp",column:r,hidden:!0}):t,e):e}function Qr(e,{columns:o}){return o.some(t=>t.hidden)?o.reduce((t,r)=>r.hidden?Ke(t,{type:"updateColumnProp",column:r,hidden:!1}):t,e):e}function Jr(e,{column:o,phase:t,width:r}){let n="updateColumnProp",l=t!=="end";switch(t){case"begin":return Ke(e,{type:n,column:o,resizing:l});case"end":return Ke(e,{type:n,column:o,resizing:l,width:r});case"resize":return Ke(e,{type:n,column:o,width:r});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${t}`)}}function Zr(e,{tableSchema:o}){let{columns:t}=e;if(t.some(Br)){let r=t.map(n=>{var s;let l=qt(n,o);return{...n,align:(s=n.align)!=null?s:en(l),serverDataType:l}});return{...e,columns:r}}else return e}function Yr(e,o){let{columns:t}=e,{column:r,pin:n}=o,l=t.find(s=>s.name===r.name);return l?(t=(0,R.replaceColumn)(t,{...l,pin:n}),t=(0,R.sortPinnedColumns)(t),{...e,columns:t}):e}function Ke(e,o){let{columns:t,tableConfig:r}=e,{align:n,column:l,hidden:s,label:i,resizing:a,width:u}=o,c=t.find(p=>p.name===l.name);if(c&&((n==="left"||n==="right")&&(t=(0,R.replaceColumn)(t,{...c,align:n})),typeof i=="string"&&(t=(0,R.replaceColumn)(t,{...c,label:i})),typeof a=="boolean"&&(t=(0,R.replaceColumn)(t,{...c,resizing:a})),typeof s=="boolean"&&(t=(0,R.replaceColumn)(t,{...c,hidden:s})),typeof u=="number")){t=(0,R.replaceColumn)(t,{...c,width:u});let p=r.columns.find(f=>f.name===l.name);p&&(r={...r,columns:(0,R.replaceColumn)(r.columns,{...p,width:u})})}return{...e,columns:t,tableConfig:r}}function nn(e,{confirmed:o,filter:t,groupBy:r,sort:n}){let l=r!==void 0,s=typeof(t==null?void 0:t.filter)=="string",i=n&&n.sortDefs.length>0,a=e;return l&&(a={...e,columns:(0,R.applyGroupByToColumns)(a.columns,r,o)}),i&&(a={...e,columns:(0,R.applySortToColumns)(a.columns,n)}),s?a={...e,columns:(0,R.applyFilterToColumns)(a.columns,t)}:a.columns.some(R.isFilteredColumn)&&(a={...e,columns:(0,R.stripFilterFromColumns)(a.columns)}),a}var Pe=require("@vuu-ui/vuu-utils"),M=require("react");var jr=100,rn=200,ln=e=>{let{clientHeight:o,clientWidth:t,scrollHeight:r,scrollWidth:n}=e;return[n-t,r-o]},qr=(e,o)=>{if(e!==void 0){let{scrollTop:t}=e;return o>t?"fwd":"bwd"}},sn=(e,o)=>{let{clientHeight:t,clientWidth:r,scrollHeight:n,scrollLeft:l,scrollTop:s,scrollWidth:i}=e,a=i-r,u=l/(i-r),c=n-t,p=s/(n-t),f=qr(o,s);return f==="fwd"&&p>.99?p=1:f==="bwd"&&p<.02&&(p=0),[l,u,a,s,p,c]},un={scrollToIndex:()=>{},scrollToKey:()=>{}},an=({onAttach:e,onDetach:o})=>{let t=(0,M.useRef)(null);return(0,M.useCallback)(n=>{if(n)t.current=n,e==null||e(n);else if(t.current){let{current:l}=t;t.current=n,o==null||o(l)}},[e,o])},Oo=({columns:e,getRowAtPosition:o,onHorizontalScroll:t,onVerticalScroll:r,onVerticalScrollInSitu:n,scrollingApiRef:l,setRange:s,viewportMeasurements:i})=>{let a=(0,M.useRef)(0),u=(0,M.useRef)(!1),c=(0,M.useRef)({scrollTop:0,scrollLeft:0}),p=(0,M.useRef)(!1),f=(0,M.useRef)({scrollTop:0,scrollLeft:0}),g=(0,M.useRef)(null),C=(0,M.useRef)(null),T=(0,M.useRef)(0),{appliedPageSize:m,isVirtualScroll:h,rowCount:x,totalHeaderHeight:k,viewportWidth:L}=i,S=(0,M.useRef)([]),[,E]=(0,M.useState)({}),I=(0,M.useRef)(0);(0,M.useMemo)(()=>{let[b,y]=(0,Pe.getColumnsInViewport)(e,c.current.scrollLeft,c.current.scrollLeft+L+rn);I.current=y,S.current=b},[L,e]);let O=(0,M.useCallback)(b=>{if(c.current.scrollLeft=b,t==null||t(b),Math.abs(b-T.current)>jr){T.current=b;let[y,D]=(0,Pe.getColumnsInViewport)(e,b,b+L+rn);(0,Pe.itemsChanged)(S.current,y)&&(I.current=D,S.current=y,E({}))}},[e,t,L]),G=(0,M.useCallback)((b,y)=>{c.current.scrollTop=b,r==null||r(b,y);let D=o(b);D!==a.current&&(a.current=D,s({from:D,to:D+x})),n==null||n(0)},[o,r,n,s,x]),_=(0,M.useCallback)(()=>{let{current:b}=C,{current:y}=g,{current:D}=u,{current:Z}=f;if(D)u.current=!1;else if(b&&y){p.current=!0;let[oe,Y,,J,$]=sn(y,Z);Z.scrollLeft=oe,Z.scrollTop=J;let[N,X]=ln(y),te=Math.round(Y*N),ne=$*X;b.scrollTo({left:te,top:ne,behavior:"auto"})}n==null||n(0)},[n]),Q=(0,M.useCallback)(()=>{let{current:b}=p,{current:y}=C,{current:D}=g,{current:Z}=c;if(y&&D){let[oe,Y,J,$,N,X]=sn(y);u.current=!0,b?p.current=!1:(D.scrollLeft=Math.round(Y*J),D.scrollTop=N*X),Z.scrollTop!==$&&G($,N),Z.scrollLeft!==oe&&O(oe)}},[G,O]),ue=(0,M.useCallback)(b=>{g.current=b,b.addEventListener("scroll",_,{passive:!0})},[_]),z=(0,M.useCallback)(b=>{g.current=null,b.removeEventListener("scroll",_)},[_]),P=(0,M.useCallback)(b=>{C.current=b,b.addEventListener("scroll",Q,{passive:!0})},[Q]),ce=(0,M.useCallback)(b=>{C.current=null,b.removeEventListener("scroll",Q)},[Q]),Ce=an({onAttach:P,onDetach:ce}),F=an({onAttach:ue,onDetach:z}),v=(0,M.useCallback)(b=>{let{current:y}=C;if(y){let[D,Z]=ln(y),{scrollLeft:oe,scrollTop:Y}=y;if(u.current=!1,b.type==="scroll-row"){let J=(0,Pe.getRowElementAtIndex)(y,b.rowIndex);if(J!==null){let[$,N]=Nt(J,k);if($&&N)if(h){let X=$==="down"?1:-1;n==null||n(X);let te=a.current+X;a.current=te,s({from:te,to:te+x})}else{let X=oe,te=Y;$==="up"||$==="down"?te=Math.min(Math.max(0,Y+N),Z):X=Math.min(Math.max(0,oe+N),D),y.scrollTo({top:te,left:X,behavior:"smooth"})}}}else if(b.type==="scroll-page"){let{direction:J}=b;if(h){let $=J==="down"?x:-x;n==null||n($);let N=a.current+$;a.current=N,s({from:N,to:N+x})}else{let $=J==="down"?m:-m,N=Math.min(Math.max(0,Y+$),Z);y.scrollTo({top:N,left:oe,behavior:"auto"})}}else if(b.type==="scroll-end"){let{direction:J}=b,$=J==="end"?Z:0;y.scrollTo({top:$,left:y.scrollLeft,behavior:"auto"})}}},[m,h,n,s,k,x]),w=(0,M.useMemo)(()=>({scrollToIndex:b=>{if(g.current){let y=(b-30)*20;g.current.scrollTop=y}},scrollToKey:b=>{console.log(`scrollToKey ${b}`)}}),[]);return(0,M.useImperativeHandle)(l,()=>g.current?w:un,[w]),(0,M.useEffect)(()=>{let{current:b}=a,y={from:b,to:b+x};s(y)},[s,x]),{columnsWithinViewport:S.current,scrollbarContainerRef:F,contentContainerRef:Ce,requestScroll:v,virtualColSpan:I.current}};var Oe=require("@vuu-ui/vuu-utils"),le=require("react"),el=1e7,ol={appliedPageSize:0,contentHeight:0,contentWidth:0,getRowAtPosition:()=>-1,getRowOffset:()=>-1,horizontalScrollbarHeight:0,isVirtualScroll:!1,pinnedWidthLeft:0,pinnedWidthRight:0,rowCount:0,setInSituRowOffset:()=>{},setScrollTop:()=>{},totalHeaderHeight:0,verticalScrollbarWidth:0,viewportBodyHeight:0,viewportWidth:0},$o=({columns:e,headerHeight:o,headings:t,rowCount:r,rowHeight:n,selectionEndSize:l=4,size:s})=>{let i=(0,le.useRef)(0),a=(0,le.useRef)(0),u=Math.min(n*r,el),c=r*n,p=c-u,{pinnedWidthLeft:f,pinnedWidthRight:g,unpinnedWidth:C}=(0,le.useMemo)(()=>(0,Oe.measurePinnedColumns)(e,l),[e,l]),T=(0,le.useRef)(o);(0,le.useMemo)(()=>{T.current=o*(1+t.length)},[o,t.length]);let[m,h,x]=(0,le.useMemo)(()=>{if(p){let[S,E,I]=(0,Oe.virtualRowPositioning)(n,p,a);return[G=>S(G,i.current),E,I]}else return(0,Oe.actualRowPositioning)(n)},[p,n]),k=(0,le.useCallback)((S,E)=>{a.current=E},[]),L=(0,le.useCallback)(S=>{S===0?i.current=0:i.current=Math.max(0,i.current+S)},[]);return(0,le.useMemo)(()=>{if(s){let{current:S}=T,E=15,I=f+C+g,O=I>s.width?E:0,G=(s.height-o)/n,_=Number.isInteger(G)?G:Math.ceil(G),Q=s.height-S,ue=u>Q?E:0,z=_*n*(u/c),P=s.width;return{appliedPageSize:z,contentHeight:u,contentWidth:I,getRowAtPosition:h,getRowOffset:m,isVirtualScroll:x,horizontalScrollbarHeight:O,pinnedWidthLeft:f,pinnedWidthRight:g,rowCount:_,setInSituRowOffset:L,setScrollTop:k,totalHeaderHeight:S,verticalScrollbarWidth:ue,viewportBodyHeight:Q,viewportWidth:P}}else return ol},[h,m,o,x,f,C,g,u,n,L,k,s,c])};var cn=require("@vuu-ui/vuu-layout"),mn=require("@vuu-ui/vuu-utils"),ie=require("react"),pn=({availableColumns:e,onAvailableColumnsChange:o,onConfigChange:t,onCreateCalculatedColumn:r,onDataSourceConfigChange:n,tableConfig:l})=>{let s=(0,cn.useLayoutProviderDispatch)(),i=(0,ie.useRef)(),[a,u]=(0,ie.useState)(e),c=(0,ie.useCallback)((m,h,x)=>{s({type:"set-props",path:"#context-panel",props:{expanded:!0,content:{type:m,props:x},title:h}})},[s]),p=(0,ie.useCallback)(()=>{requestAnimationFrame(()=>{var m;(m=i.current)==null||m.call(i)})},[]),f=(0,ie.useCallback)(m=>{let h=a.concat({name:m.name,serverDataType:(0,mn.getCalculatedColumnType)(m)});u(h),o==null||o(h),requestAnimationFrame(()=>{var x;(x=i.current)==null||x.call(i)}),r(m)},[a,o,r]),g=(0,ie.useCallback)(m=>{c("ColumnSettings","Column Settings",{column:m.column,onCancelCreateColumn:p,onConfigChange:t,onCreateCalculatedColumn:f,tableConfig:l,vuuTable:m.vuuTable})},[p,f,t,c,l]),C=(0,ie.useCallback)(()=>{g({column:{name:"::",serverDataType:"string"},type:"columnSettings",vuuTable:{module:"SIMUL",table:"instruments"}})},[g]),T=(0,ie.useCallback)(m=>{let h=l.columns.find(x=>x.name===m);h&&g({type:"columnSettings",column:h,vuuTable:{module:"SIMUL",table:"instruments"}})},[g,l.columns]);return i.current=(0,ie.useCallback)(()=>{c("TableSettings","DataGrid Settings",{availableColumns:a!=null?a:l.columns.map(({name:m,serverDataType:h})=>({name:m,serverDataType:h})),onAddCalculatedColumn:C,onConfigChange:t,onDataSourceConfigChange:n,onNavigateToColumn:T,tableConfig:l})},[a,C,T,t,n,c,l]),{showColumnSettingsPanel:g,showTableSettingsPanel:i.current}};var lo=e=>e,{KEY:tl,IS_EXPANDED:dn,IS_LEAF:bn}=W.metadataKeys,nl={draggable:void 0,onMouseDown:void 0},rl=()=>nl,ll=(e,o)=>({...e,columns:e.columns.concat(o)}),gn=({allowDragDrop:e=!1,availableColumns:o,config:t,containerRef:r,dataSource:n,disableFocus:l,headerHeight:s=25,highlightedIndex:i,id:a,navigationStyle:u="cell",onAvailableColumnsChange:c,onConfigChange:p,onDragStart:f,onDrop:g,onFeatureInvocation:C,onHighlight:T,onRowClick:m,onSelect:h,onSelectionChange:x,renderBufferSize:k=0,rowHeight:L=20,scrollingApiRef:S,selectionModel:E,size:I})=>{let[O,G]=(0,H.useState)(n.size);if(n===void 0)throw Error("no data source provided to Vuu Table");let _=e?fn.useDragDrop:rl,Q=(0,H.useMemo)(()=>St(n),[n]),ue=(0,H.useCallback)(d=>{G(d)},[]),{columns:z,dispatchColumnAction:P,headings:ce,tableAttributes:Ce,tableConfig:F}=Ko(t,n);(0,W.useLayoutEffectSkipFirst)(()=>{P({type:"init",tableConfig:t,dataSource:n})},[t,n,P]);let v=(0,H.useCallback)(d=>{P({type:"init",tableConfig:d,dataSource:n}),p==null||p(lo(d))},[n,P,p]),w=(0,H.useMemo)(()=>(0,W.buildColumnMap)(n.columns),[n.columns]),b=(0,H.useCallback)(({tableSchema:d})=>{d?P({type:"setTableSchema",tableSchema:d}):console.log("subscription message with no schema")},[P]),{getRowAtPosition:y,getRowOffset:D,setInSituRowOffset:Z,setScrollTop:oe,...Y}=$o({columns:z,headerHeight:s,headings:ce,rowCount:O,rowHeight:L,size:I}),J=$t({from:0,to:Y.rowCount}),{data:$,dataRef:N,getSelectedRows:X,range:te,setRange:ne}=Ot({dataSource:n,onFeatureInvocation:C,renderBufferSize:k,onSizeChange:ue,onSubscribed:b,range:J}),{requestScroll:po,...bo}=Oo({columns:z,getRowAtPosition:y,rowHeight:L,scrollingApiRef:S,setRange:ne,onVerticalScroll:oe,onVerticalScrollInSitu:Z,viewportMeasurements:Y}),_e=(0,H.useCallback)(d=>{P({type:"init",tableConfig:d,dataSource:n}),p==null||p(lo(d))},[n,P,p]),Re=(0,H.useCallback)(d=>{n.config={...n.config,...d}},[n]);(0,H.useEffect)(()=>{n.on("config",(d,A)=>{P({type:"tableConfig",...d,confirmed:A})})},[n,P]);let In=(0,H.useCallback)(d=>{n.columns=n.columns.concat(d.name),v(ll(F,d))},[n,F,v]),Wo=(0,H.useCallback)(d=>{let{columns:A}=d,B=A.map(q=>q.name),j={...F,columns:F.columns.map(q=>B.includes(q.name)?{...q,hidden:!0}:q)};v(j)},[F,v]),Uo=(0,H.useCallback)(d=>{v({...F,columns:(0,W.updateColumn)(F.columns,{...d.column,pin:d.pin})})},[F,v]),{showColumnSettingsPanel:_o,showTableSettingsPanel:Xo}=pn({availableColumns:o!=null?o:F.columns.map(({name:d,serverDataType:A="string"})=>({name:d,serverDataType:A})),onAvailableColumnsChange:c,onConfigChange:_e,onCreateCalculatedColumn:In,onDataSourceConfigChange:Re,tableConfig:F}),zn=(0,H.useCallback)(d=>{if(No(d))_o(d);else if(Fo(d))Xo();else switch(d.type){case"hideColumns":return Wo(d);case"pinColumn":return Uo(d);default:P(d)}},[P,Wo,Uo,_o,Xo]),Nn=Lt({dataSource:n,onPersistentColumnOperation:zn}),Fn=(0,H.useCallback)((d,A=!1,B)=>{n&&(n.sort=(0,W.applySort)(n.sort,d,A,B))},[n]),fo=(0,H.useRef)(),Kn=(0,H.useCallback)((d,A,B)=>{var q,Be,ve;let j=z.find(re=>re.name===A);if(j)if(d==="resize")(q=fo.current)==null||q.forEach(re=>{re.style.width=`${B}px`});else if(d==="end")fo.current=void 0,(0,W.isValidNumber)(B)&&(P({type:"resizeColumn",phase:d,column:j,width:B}),p==null||p(lo(So(F,{type:"col-size",column:j,width:B}))));else{let re=`[aria-colindex='${j.index}']`;fo.current=Array.from((ve=(Be=r.current)==null?void 0:Be.querySelectorAll(`.vuuTableCell${re},.vuuTableHeaderCell${re}`))!=null?ve:[]),P({type:"resizeColumn",phase:d,column:j,width:B})}else throw Error(`useDataTable.handleColumnResize, column ${A} not found`)},[z,P,p,F,r]),On=(0,H.useCallback)((d,A)=>{var q,Be;let B=(0,W.isJsonGroup)(A,d,w),j=d[tl];if(d[dn]){if(n.closeTreeNode(j,!0),B){let ve=z.indexOf(A),re=(q=n.getRowsAtDepth)==null?void 0:q.call(n,ve+1);re&&!re.some(Ee=>Ee[dn]||Ee[bn])&&P({type:"hideColumns",columns:z.slice(ve+2)})}}else if(n.openTreeNode(j),B){let ve=(Be=n.getChildRows)==null?void 0:Be.call(n,j),re=z.indexOf(A)+1,Ee=[z[re]];ve&&ve.some(go=>go[bn])&&Ee.push(z[re+1]),Ee.some(go=>go.hidden)&&P({type:"showColumns",columns:Ee})}},[w,z,n,P]),{highlightedIndexRef:Qo,navigate:$n,onFocus:Jo,onKeyDown:Zo,...Gn}=_t({columnCount:z.filter(d=>d.hidden!==!0).length,containerRef:r,disableFocus:l,highlightedIndex:i,navigationStyle:u,requestScroll:po,rowCount:n==null?void 0:n.size,onHighlight:T,viewportRange:te,viewportRowCount:Y.rowCount}),{onBlur:Bn,onDoubleClick:Vn,onKeyDown:Yo,onFocus:jo}=Kt({navigate:$n}),Wn=(0,H.useCallback)(d=>{Jo(),d.defaultPrevented||jo(d)},[jo,Jo]),Un=Zt({columns:z,data:$,dataSource:n,getSelectedRows:X}),_n=(0,H.useCallback)(d=>{n.groupBy=d.map(A=>A.name)},[n]),Xn=(0,H.useCallback)(d=>{(0,W.isGroupColumn)(d)?n.groupBy=[]:n&&n.groupBy.includes(d.name)&&(n.groupBy=n.groupBy.filter(A=>A!==d.name))},[n]),Qn=(0,H.useCallback)(d=>{n.select(d),x==null||x(d)},[n,x]),{onKeyDown:qo,onRowClick:et}=Xt({highlightedIndexRef:Qo,onSelect:h,onSelectionChange:Qn,selectionModel:E}),Jn=(0,H.useCallback)(d=>{Zo(d),d.defaultPrevented||Yo(d),d.defaultPrevented||qo(d)},[Zo,Yo,qo]),Zn=(0,H.useCallback)((d,A,B)=>{et(d,A,B),m==null||m(d)},[m,et]),Yn=(0,H.useCallback)(d=>{let A={...F,columns:d};P({type:"init",tableConfig:A,dataSource:n}),p==null||p(lo(A))},[n,P,p,F]),jn=(0,H.useCallback)(d=>{g==null||g(d)},[g]),qn=(0,H.useCallback)(async(d,A,B)=>n.applyEdit(d,A,B),[n]),er=(0,H.useCallback)(d=>{let{initialDragElement:A}=d,B=(0,W.getIndexFromRowElement)(A),j=N.current.find(q=>q[0]===B);j&&d.setPayload(j),f==null||f(d)},[N,f]),{onMouseDown:or,draggable:tr}=_({allowDragDrop:e,containerRef:r,draggableClassName:"vuuTable",id:a,onDragStart:er,onDrop:jn,orientation:"vertical",itemQuery:".vuuTableRow"});return{...Gn,"aria-rowcount":n.size,draggableRow:tr,onBlur:Bn,onDoubleClick:Vn,onFocus:Wn,onKeyDown:Jn,onMouseDown:or,columnMap:w,columns:z,data:$,getRowOffset:D,handleContextMenuAction:Nn,headings:ce,highlightedIndex:Qo.current,menuBuilder:Q,onContextMenu:Un,onDataEdited:qn,onMoveColumn:Yn,onMoveGroupColumn:_n,onRemoveGroupColumn:Xn,onRowClick:Zn,onSortColumn:Fn,onResizeColumn:Kn,onToggleGroup:On,scrollProps:bo,tableAttributes:Ce,tableConfig:F,viewportMeasurements:Y}};var se=require("react/jsx-runtime"),ge="vuuTable",{IDX:il,RENDER_IDX:sl}=io.metadataKeys,al=({Row:e=yo,allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:s=!1,highlightedIndex:i,id:a,navigationStyle:u="cell",onAvailableColumnsChange:c,onConfigChange:p,onDragStart:f,onDrop:g,onFeatureInvocation:C,onHighlight:T,onRowClick:m,onSelect:h,onSelectionChange:x,renderBufferSize:k=5,rowHeight:L=20,scrollingApiRef:S,selectionModel:E="extended",showColumnHeaders:I=!0,headerHeight:O=I?25:0,size:G})=>{let _=(0,io.useId)(a),{columnMap:Q,columns:ue,data:z,draggableRow:P,getRowOffset:ce,handleContextMenuAction:Ce,headings:F,highlightedIndex:v,onDataEdited:w,onMoveColumn:b,onMoveGroupColumn:y,onRemoveGroupColumn:D,onResizeColumn:Z,onRowClick:oe,onSortColumn:Y,onToggleGroup:J,menuBuilder:$,scrollProps:N,tableAttributes:X,tableConfig:te,viewportMeasurements:ne,...po}=gn({allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:s,headerHeight:O,highlightedIndex:i,id:_,navigationStyle:u,onAvailableColumnsChange:c,onConfigChange:p,onDragStart:f,onDrop:g,onFeatureInvocation:C,onHighlight:T,onRowClick:m,onSelect:h,onSelectionChange:x,renderBufferSize:k,rowHeight:L,scrollingApiRef:S,selectionModel:E,size:G}),bo=(0,Go.default)(`${ge}-contentContainer`,{[`${ge}-colLines`]:X.columnSeparators,[`${ge}-rowLines`]:X.rowSeparators,[`${ge}-zebra`]:X.zebraStripes}),_e={"--content-height":`${ne.contentHeight}px`,"--content-width":`${ne.contentWidth}px`,"--horizontal-scrollbar-height":`${ne.horizontalScrollbarHeight}px`,"--pinned-width-left":`${ne.pinnedWidthLeft}px`,"--pinned-width-right":`${ne.pinnedWidthRight}px`,"--header-height":`${O}px`,"--row-height":`${L}px`,"--total-header-height":`${ne.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${ne.verticalScrollbarWidth}px`,"--viewport-body-height":`${ne.viewportBodyHeight}px`};return(0,se.jsxs)(Cn.ContextMenuProvider,{menuActionHandler:Ce,menuBuilder:$,children:[(0,se.jsx)("div",{className:`${ge}-scrollbarContainer`,ref:N.scrollbarContainerRef,style:_e,children:(0,se.jsx)("div",{className:`${ge}-scrollbarContent`})}),(0,se.jsx)("div",{className:bo,ref:N.contentContainerRef,style:_e,children:(0,se.jsxs)("div",{...po,className:`${ge}-table`,role:"table",tabIndex:s?void 0:-1,children:[I?(0,se.jsx)(Do,{columns:N.columnsWithinViewport,headings:F,onMoveColumn:b,onMoveGroupColumn:y,onRemoveGroupColumn:D,onResizeColumn:Z,onSortColumn:Y,tableConfig:te,tableId:_,virtualColSpan:N.virtualColSpan}):null,(0,se.jsx)("div",{className:`${ge}-body`,children:z.map(Re=>(0,se.jsx)(e,{"aria-rowindex":Re[0]+1,columnMap:Q,columns:N.columnsWithinViewport,highlighted:v===Re[il],onClick:oe,onDataEdited:w,row:Re,offset:ce(Re),onToggleGroup:J,virtualColSpan:N.virtualColSpan,zebraStripes:X.zebraStripes},Re[sl]))})]})}),P]})},ul=(0,$e.forwardRef)(function({Row:o,allowDragDrop:t,availableColumns:r,className:n,config:l,dataSource:s,disableFocus:i,highlightedIndex:a,id:u,navigationStyle:c,onAvailableColumnsChange:p,onConfigChange:f,onDragStart:g,onDrop:C,onFeatureInvocation:T,onHighlight:m,onRowClick:h,onSelect:x,onSelectionChange:k,renderBufferSize:L,rowHeight:S,scrollingApiRef:E,selectionModel:I,showColumnHeaders:O,headerHeight:G,style:_,...Q},ue){let z=(0,$e.useRef)(null),[P,ce]=(0,$e.useState)();if(l===void 0)throw Error("vuu Table requires config prop. Minimum config is list of Column Descriptors");if(s===void 0)throw Error("vuu Table requires dataSource prop");return(0,se.jsx)(vn.MeasuredContainer,{...Q,className:(0,Go.default)(ge,n),id:u,onResize:ce,ref:(0,hn.useForkRef)(z,ue),children:P?(0,se.jsx)(al,{Row:o,allowDragDrop:t,availableColumns:r,config:l,containerRef:z,dataSource:s,disableFocus:i,headerHeight:G,highlightedIndex:a,id:u,navigationStyle:c,onAvailableColumnsChange:p,onConfigChange:f,onDragStart:g,onDrop:C,onFeatureInvocation:T,onHighlight:m,onRowClick:h,onSelect:x,onSelectionChange:k,renderBufferSize:L,rowHeight:S,scrollingApiRef:E,selectionModel:I,showColumnHeaders:O,size:P}):null})});var so=require("react"),ao=require("@vuu-ui/vuu-ui-controls"),xn=require("@salt-ds/core"),Ge=require("@vuu-ui/vuu-utils"),Bo=require("react/jsx-runtime"),Vo=(0,so.memo)(({column:e,columnMap:o,onCommit:t=ao.WarnCommit,row:r})=>{let n=o[e.name],l=r[n],s=(0,so.useCallback)(i=>async a=>{let u=await t(i);return u===!0&&(0,Ge.dispatchCustomEvent)(a.target,"vuu-commit"),u},[t]);return e.editable?(0,Bo.jsx)(xn.Checkbox,{checked:l,onClick:s(!l)}):(0,Bo.jsx)(ao.CheckboxIcon,{checked:l,disabled:!0})},Ge.dataAndColumnUnchanged);Vo.displayName="CheckboxCell";(0,Ge.registerComponent)("checkbox-cell",Vo,"cell-renderer",{serverDataType:"boolean"});var wn=require("@vuu-ui/vuu-utils"),Tn=require("@salt-ds/core"),Rn=require("@vuu-ui/vuu-ui-controls"),yn=ae(require("clsx"));var co=require("react/jsx-runtime"),uo="vuuTableInputCell",cl=()=>(console.warn("onCommit handler has not been provided to InputCell cell renderer"),Promise.resolve(!0)),Dn=({column:e,columnMap:o,onCommit:t=cl,row:r})=>{let n=o[e.name],{align:l="left",clientSideEditValidationCheck:s}=e,{warningMessage:i,...a}=(0,Rn.useEditableText)({initialValue:r[n],onCommit:t,clientSideEditValidationCheck:s}),u=i&&l==="left"?(0,co.jsx)("span",{className:`${uo}-icon`,"data-icon":"error"}):void 0,c=i&&l==="right"?(0,co.jsx)("span",{className:`${uo}-icon`,"data-icon":"error"}):void 0;return(0,co.jsx)(Tn.Input,{...a,className:(0,yn.default)(uo,{[`${uo}-error`]:i!==void 0}),endAdornment:u,startAdornment:c})};(0,wn.registerComponent)("input-cell",Dn,"cell-renderer",{});var Hn=require("@vuu-ui/vuu-ui-controls"),pe=require("@vuu-ui/vuu-utils"),Pn=ae(require("clsx")),mo=require("react"),En=require("@vuu-ui/vuu-ui-controls");var kn=require("react/jsx-runtime"),Mn="vuuTableToggleCell",ml=({name:e,type:o})=>{if((0,pe.isTypeDescriptor)(o)&&(0,pe.isValueListRenderer)(o.renderer))return o.renderer.values;throw Error(`useLookupValues column ${e} has not been configured with a values list`)},Sn=(0,mo.memo)(function({column:o,columnMap:t,onCommit:r=Hn.WarnCommit,row:n}){let l=ml(o),s=t[o.name],i=n[s],a=(0,mo.useCallback)((u,c)=>r(c).then(p=>(p===!0&&(0,pe.dispatchCustomEvent)(u.target,"vuu-commit"),p)),[r]);return(0,kn.jsx)(En.CycleStateButton,{className:(0,Pn.default)(Mn,`${Mn}-${o.name}`),onCommit:a,value:i,values:l,variant:"cta",children:i})},pe.dataAndColumnUnchanged);(0,pe.registerComponent)("toggle-cell",Sn,"cell-renderer",{});var Ln=require("@vuu-ui/vuu-ui-controls"),An=require("@vuu-ui/vuu-utils"),Ue=require("react"),pl=(e,o)=>{let t=(0,Ue.useRef)(null),[r,n]=(0,Ln.useStateRef)(e),l=(0,Ue.useCallback)(i=>{var a;if(i.key==="ArrowDown")n((u=-1)=>Math.min(o-1,u+1));else if(i.key==="ArrowUp")n((u=-1)=>Math.max(0,u-1));else if(i.key==="Enter"||i.key===" "){let{current:u}=r,c=(a=t.current)==null?void 0:a.querySelector(`[aria-rowindex="${u}"]`);c&&(0,An.dispatchMouseEvent)(c,"click")}},[r,o,n]),s=(0,Ue.useCallback)(i=>{n(i)},[n]);return{highlightedIndexRef:r,onHighlight:s,onKeyDown:l,tableRef:t}};
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ CheckboxCell: () => CheckboxCell,
34
+ GroupHeaderCellNext: () => GroupHeaderCellNext,
35
+ HeaderCell: () => HeaderCell,
36
+ InputCell: () => InputCell,
37
+ Table: () => Table,
38
+ TableCell: () => TableCell,
39
+ TableGroupCell: () => TableGroupCell,
40
+ ToggleCell: () => ToggleCell,
41
+ isShowColumnSettings: () => isShowColumnSettings,
42
+ isShowTableSettings: () => isShowTableSettings,
43
+ noScrolling: () => noScrolling,
44
+ updateTableConfig: () => updateTableConfig,
45
+ useControlledTableNavigation: () => useControlledTableNavigation,
46
+ useTableModel: () => useTableModel,
47
+ useTableScroll: () => useTableScroll,
48
+ useTableViewport: () => useTableViewport
49
+ });
50
+ module.exports = __toCommonJS(src_exports);
51
+
52
+ // src/header-cell/GroupHeaderCellNext.tsx
53
+ var import_vuu_ui_controls = require("@vuu-ui/vuu-ui-controls");
54
+ var import_vuu_utils2 = require("@vuu-ui/vuu-utils");
55
+ var import_clsx3 = __toESM(require("clsx"));
56
+ var import_react5 = require("react");
57
+
58
+ // src/column-header-pill/ColumnHeaderPill.tsx
59
+ var import_clsx = __toESM(require("clsx"));
60
+ var import_react = require("react");
61
+ var import_jsx_runtime = require("react/jsx-runtime");
62
+ var classBase = "vuuColumnHeaderPill";
63
+ var ColumnHeaderPill = ({
64
+ children,
65
+ className,
66
+ column,
67
+ onRemove,
68
+ removable,
69
+ ...htmlAttributes
70
+ }) => {
71
+ if (removable && typeof onRemove !== "function") {
72
+ throw Error(
73
+ "ColumnHeaderPill onRemove prop must be provided if Pill is removable"
74
+ );
75
+ }
76
+ const handleClickRemove = (0, import_react.useCallback)(
77
+ (evt) => {
78
+ evt.preventDefault();
79
+ evt.stopPropagation();
80
+ onRemove == null ? void 0 : onRemove(column);
81
+ },
82
+ [column, onRemove]
83
+ );
84
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { ...htmlAttributes, className: (0, import_clsx.default)(classBase, className), children: [
85
+ children,
86
+ removable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
87
+ "span",
88
+ {
89
+ className: `${classBase}-removeButton`,
90
+ role: "button",
91
+ "data-icon": "cross",
92
+ onClick: handleClickRemove
93
+ }
94
+ ) : null
95
+ ] });
96
+ };
97
+
98
+ // src/column-header-pill/GroupColumnPill.tsx
99
+ var import_jsx_runtime2 = require("react/jsx-runtime");
100
+ var GroupColumnPill = ({
101
+ column,
102
+ ...columnHeaderProps
103
+ }) => {
104
+ const { name, sorted } = column;
105
+ const icon = typeof sorted === "number" ? sorted < 0 ? "arrow-down" : "arrow-up" : sorted === "A" ? "arrow-up" : sorted === "D" ? "arrow-down" : void 0;
106
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(ColumnHeaderPill, { ...columnHeaderProps, column, children: [
107
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "vuuGroupColumnPill-label", children: name }),
108
+ icon !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { "data-icon": icon }) : null,
109
+ typeof sorted === "number" ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: "vuuSortPosition", children: Math.abs(sorted) }) : null
110
+ ] });
111
+ };
112
+
113
+ // src/column-header-pill/SortIndicator.tsx
114
+ var import_jsx_runtime3 = require("react/jsx-runtime");
115
+ var SortIndicator = ({ column }) => {
116
+ if (!column.sorted) {
117
+ return null;
118
+ }
119
+ const icon = typeof column.sorted === "number" ? column.sorted < 0 ? "arrow-down" : "arrow-up" : column.sorted === "A" ? "arrow-up" : "arrow-down";
120
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(ColumnHeaderPill, { column, children: [
121
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { "data-icon": icon }),
122
+ typeof column.sorted === "number" ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("span", { className: "vuuSortPosition", children: Math.abs(column.sorted) }) : null
123
+ ] });
124
+ };
125
+
126
+ // src/column-resizing/ColumnResizer.tsx
127
+ var import_react2 = require("react");
128
+ var import_jsx_runtime4 = require("react/jsx-runtime");
129
+ var NOOP = () => void 0;
130
+ var baseClass = "vuuColumnResizerNext";
131
+ var ColumnResizer = ({
132
+ onDrag,
133
+ onDragEnd = NOOP,
134
+ onDragStart = NOOP
135
+ }) => {
136
+ const positionRef = (0, import_react2.useRef)({ start: 0, now: 0 });
137
+ const onMouseMove = (0, import_react2.useCallback)(
138
+ (e) => {
139
+ if (e.stopPropagation) {
140
+ e.stopPropagation();
141
+ }
142
+ if (e.preventDefault) {
143
+ e.preventDefault();
144
+ }
145
+ const { current: position } = positionRef;
146
+ const x = Math.round(e.clientX);
147
+ const moveBy = x - position.now;
148
+ const distanceMoved = position.now - position.start;
149
+ positionRef.current.now = x;
150
+ if (moveBy !== 0) {
151
+ onDrag(e, moveBy, distanceMoved);
152
+ }
153
+ },
154
+ [onDrag]
155
+ );
156
+ const onMouseUp = (0, import_react2.useCallback)(
157
+ (e) => {
158
+ window.removeEventListener("mouseup", onMouseUp);
159
+ window.removeEventListener("mousemove", onMouseMove);
160
+ const { current: position } = positionRef;
161
+ const distanceMoved = position.now - position.start;
162
+ onDragEnd(e, distanceMoved);
163
+ },
164
+ [onDragEnd, onMouseMove]
165
+ );
166
+ const handleMouseDown = (0, import_react2.useCallback)(
167
+ (e) => {
168
+ const { current: position } = positionRef;
169
+ onDragStart(e);
170
+ position.now = position.start = Math.round(e.clientX);
171
+ window.addEventListener("mouseup", onMouseUp);
172
+ window.addEventListener("mousemove", onMouseMove);
173
+ if (e.stopPropagation) {
174
+ e.stopPropagation();
175
+ }
176
+ if (e.preventDefault) {
177
+ e.preventDefault();
178
+ }
179
+ },
180
+ [onDragStart, onMouseMove, onMouseUp]
181
+ );
182
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)("div", { className: baseClass, onMouseDown: handleMouseDown });
183
+ };
184
+
185
+ // src/column-resizing/useTableColumnResize.tsx
186
+ var import_react3 = require("react");
187
+ var useTableColumnResize = ({
188
+ column,
189
+ onResize,
190
+ rootRef
191
+ }) => {
192
+ const widthRef = (0, import_react3.useRef)({ start: 0, now: 0 });
193
+ const [isResizing, setResizing] = (0, import_react3.useState)(false);
194
+ const { name } = column;
195
+ const handleResizeStart = (0, import_react3.useCallback)(() => {
196
+ if (onResize && rootRef.current) {
197
+ const { current: width } = widthRef;
198
+ const { width: measuredWidth } = rootRef.current.getBoundingClientRect();
199
+ width.start = width.now = Math.round(measuredWidth);
200
+ setResizing(true);
201
+ onResize == null ? void 0 : onResize("begin", name);
202
+ }
203
+ }, [name, onResize, rootRef]);
204
+ const handleResize = (0, import_react3.useCallback)(
205
+ (_evt, moveBy, totalDistanceMoved) => {
206
+ if (rootRef.current) {
207
+ if (onResize) {
208
+ const { current: width } = widthRef;
209
+ const newWidth = width.start + totalDistanceMoved;
210
+ if (newWidth !== width.now && newWidth > 0) {
211
+ onResize("resize", name, newWidth);
212
+ width.now = newWidth;
213
+ }
214
+ }
215
+ }
216
+ },
217
+ [name, onResize, rootRef]
218
+ );
219
+ const handleResizeEnd = (0, import_react3.useCallback)(() => {
220
+ if (onResize) {
221
+ const { current: width } = widthRef;
222
+ onResize("end", name, width.now);
223
+ setTimeout(() => {
224
+ setResizing(false);
225
+ }, 80);
226
+ }
227
+ }, [name, onResize]);
228
+ return {
229
+ isResizing,
230
+ onDrag: handleResize,
231
+ onDragStart: handleResizeStart,
232
+ onDragEnd: handleResizeEnd
233
+ };
234
+ };
235
+
236
+ // src/useCell.ts
237
+ var import_vuu_utils = require("@vuu-ui/vuu-utils");
238
+ var import_clsx2 = __toESM(require("clsx"));
239
+ var import_react4 = require("react");
240
+ var useCell = (column, classBase10, isHeader) => (
241
+ // TODO measure perf without the memo, might not be worth the cost
242
+ (0, import_react4.useMemo)(() => {
243
+ const className = (0, import_clsx2.default)(classBase10, {
244
+ vuuPinFloating: column.pin === "floating",
245
+ vuuPinLeft: column.pin === "left",
246
+ vuuPinRight: column.pin === "right",
247
+ vuuEndPin: isHeader && column.endPin,
248
+ // [`${classBase}-resizing`]: column.resizing,
249
+ [`${classBase10}-editable`]: column.editable,
250
+ [`${classBase10}-right`]: column.align === "right"
251
+ });
252
+ const style = (0, import_vuu_utils.getColumnStyle)(column);
253
+ return {
254
+ className,
255
+ style
256
+ };
257
+ }, [column, classBase10, isHeader])
258
+ );
259
+
260
+ // src/header-cell/GroupHeaderCellNext.tsx
261
+ var import_jsx_runtime5 = require("react/jsx-runtime");
262
+ var import_react6 = require("react");
263
+ var classBase2 = "vuuTableGroupHeaderCell";
264
+ var switchIfChanged = (columns, newColumns) => {
265
+ if (columns === newColumns) {
266
+ return columns;
267
+ } else {
268
+ return newColumns;
269
+ }
270
+ };
271
+ var GroupHeaderCellNext = ({
272
+ column: groupColumn,
273
+ className: classNameProp,
274
+ onMoveColumn,
275
+ onRemoveColumn,
276
+ onResize,
277
+ ...htmlAttributes
278
+ }) => {
279
+ const rootRef = (0, import_react5.useRef)(null);
280
+ const { isResizing, ...resizeProps } = useTableColumnResize({
281
+ column: groupColumn,
282
+ onResize,
283
+ rootRef
284
+ });
285
+ const [columns, setColumns] = (0, import_react5.useState)(groupColumn.columns);
286
+ const { className, style } = useCell(groupColumn, classBase2, true);
287
+ const columnPillProps = columns.length > 1 ? {
288
+ removable: true,
289
+ onRemove: onRemoveColumn
290
+ } : void 0;
291
+ const handleMoveItem = (0, import_react5.useCallback)(
292
+ (fromIndex, toIndex) => {
293
+ setColumns((cols) => {
294
+ const newCols = cols.slice();
295
+ const [tab] = newCols.splice(fromIndex, 1);
296
+ if (toIndex === -1) {
297
+ const result = newCols.concat(tab);
298
+ onMoveColumn == null ? void 0 : onMoveColumn(result);
299
+ return result;
300
+ } else {
301
+ newCols.splice(toIndex, 0, tab);
302
+ onMoveColumn == null ? void 0 : onMoveColumn(newCols);
303
+ return newCols;
304
+ }
305
+ });
306
+ },
307
+ [onMoveColumn]
308
+ );
309
+ (0, import_vuu_utils2.useLayoutEffectSkipFirst)(() => {
310
+ setColumns((cols) => switchIfChanged(cols, groupColumn.columns));
311
+ }, [groupColumn.columns]);
312
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(
313
+ "div",
314
+ {
315
+ ...htmlAttributes,
316
+ className: (0, import_clsx3.default)(className, classNameProp, {
317
+ [`${classBase2}-pending`]: groupColumn.groupConfirmed === false
318
+ }),
319
+ ref: rootRef,
320
+ role: "columnheader",
321
+ style,
322
+ children: [
323
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
324
+ import_vuu_ui_controls.OverflowContainer,
325
+ {
326
+ allowDragDrop: true,
327
+ className: `${classBase2}-inner`,
328
+ height: 24,
329
+ onMoveItem: handleMoveItem,
330
+ overflowPosition: "start",
331
+ children: columns.map((column) => {
332
+ return /* @__PURE__ */ (0, import_react6.createElement)(
333
+ GroupColumnPill,
334
+ {
335
+ ...columnPillProps,
336
+ column,
337
+ key: column.name
338
+ }
339
+ );
340
+ })
341
+ }
342
+ ),
343
+ /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
344
+ ColumnHeaderPill,
345
+ {
346
+ column: groupColumn,
347
+ removable: true,
348
+ onRemove: onRemoveColumn
349
+ }
350
+ ),
351
+ groupColumn.resizeable !== false ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(ColumnResizer, { ...resizeProps }) : null
352
+ ]
353
+ }
354
+ );
355
+ };
356
+
357
+ // src/header-cell/HeaderCell.tsx
358
+ var import_clsx5 = __toESM(require("clsx"));
359
+ var import_react8 = require("react");
360
+
361
+ // src/column-menu/ColumnMenu.tsx
362
+ var import_vuu_popups = require("@vuu-ui/vuu-popups");
363
+ var import_clsx4 = __toESM(require("clsx"));
364
+ var import_react7 = require("react");
365
+ var import_jsx_runtime6 = require("react/jsx-runtime");
366
+ var getPosition = (element) => {
367
+ if (element) {
368
+ const { bottom, left } = element.getBoundingClientRect();
369
+ return { x: left, y: bottom + 6 };
370
+ }
371
+ };
372
+ var ColumnMenu = ({
373
+ className,
374
+ column,
375
+ ...props
376
+ }) => {
377
+ const rootRef = (0, import_react7.useRef)(null);
378
+ const [menuOpen, setMenuOpen] = (0, import_react7.useState)(false);
379
+ const [showContextMenu] = (0, import_vuu_popups.useContextMenu)();
380
+ const handleMenuClose = (0, import_react7.useCallback)(() => {
381
+ setMenuOpen(false);
382
+ }, []);
383
+ const showColumnMenu = (0, import_react7.useCallback)(
384
+ (e) => {
385
+ setMenuOpen(true);
386
+ showContextMenu(e, "column-menu", {
387
+ column,
388
+ ContextMenuProps: {
389
+ onClose: handleMenuClose,
390
+ position: getPosition(rootRef.current)
391
+ }
392
+ });
393
+ },
394
+ [column, handleMenuClose, showContextMenu]
395
+ );
396
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(
397
+ "span",
398
+ {
399
+ ...props,
400
+ className: (0, import_clsx4.default)("vuuTable-columnMenu", className, {
401
+ "vuuTable-columnMenu-open": menuOpen
402
+ }),
403
+ "data-icon": "more-vert",
404
+ onClick: showColumnMenu,
405
+ ref: rootRef
406
+ }
407
+ );
408
+ };
409
+
410
+ // src/header-cell/HeaderCell.tsx
411
+ var import_jsx_runtime7 = require("react/jsx-runtime");
412
+ var classBase3 = "vuuTableHeaderCell";
413
+ var HeaderCell = ({
414
+ className: classNameProp,
415
+ column,
416
+ onClick,
417
+ onResize,
418
+ ...htmlAttributes
419
+ }) => {
420
+ var _a;
421
+ const { HeaderCellContentRenderer, HeaderCellLabelRenderer } = column;
422
+ const rootRef = (0, import_react8.useRef)(null);
423
+ const { isResizing, ...resizeProps } = useTableColumnResize({
424
+ column,
425
+ onResize,
426
+ rootRef
427
+ });
428
+ const handleClick = (0, import_react8.useCallback)(
429
+ (evt) => {
430
+ !isResizing && (onClick == null ? void 0 : onClick(evt));
431
+ },
432
+ [isResizing, onClick]
433
+ );
434
+ const { className, style } = useCell(column, classBase3, true);
435
+ const columnMenu = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnMenu, { column });
436
+ const columnLabel = HeaderCellLabelRenderer ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellLabelRenderer, { className: `${classBase3}-label`, column }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: `${classBase3}-label`, children: (_a = column.label) != null ? _a : column.name });
437
+ const columnContent = HeaderCellContentRenderer ? [/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(HeaderCellContentRenderer, { column }, "content")] : [];
438
+ const sortIndicator = /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(SortIndicator, { column });
439
+ const headerItems = column.align === "right" ? [sortIndicator, columnLabel].concat(columnContent).concat(columnMenu) : [columnMenu, columnLabel, sortIndicator].concat(columnContent);
440
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
441
+ "div",
442
+ {
443
+ ...htmlAttributes,
444
+ className: (0, import_clsx5.default)(className, classNameProp, {
445
+ [`${classBase3}-resizing`]: isResizing
446
+ }),
447
+ onClick: handleClick,
448
+ ref: rootRef,
449
+ role: "columnheader",
450
+ style,
451
+ children: [
452
+ ...headerItems,
453
+ column.resizeable !== false ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(ColumnResizer, { ...resizeProps }) : null
454
+ ]
455
+ }
456
+ );
457
+ };
458
+
459
+ // src/Table.tsx
460
+ var import_vuu_popups3 = require("@vuu-ui/vuu-popups");
461
+ var import_vuu_ui_controls5 = require("@vuu-ui/vuu-ui-controls");
462
+ var import_vuu_utils24 = require("@vuu-ui/vuu-utils");
463
+ var import_core2 = require("@salt-ds/core");
464
+ var import_clsx9 = __toESM(require("clsx"));
465
+ var import_react27 = require("react");
466
+
467
+ // src/Row.tsx
468
+ var import_vuu_utils5 = require("@vuu-ui/vuu-utils");
469
+ var import_clsx7 = __toESM(require("clsx"));
470
+ var import_react11 = require("react");
471
+
472
+ // src/table-cell/TableCell.tsx
473
+ var import_vuu_utils3 = require("@vuu-ui/vuu-utils");
474
+ var import_react9 = require("react");
475
+ var import_jsx_runtime8 = require("react/jsx-runtime");
476
+ var classBase4 = "vuuTableCell";
477
+ var TableCell = ({
478
+ column,
479
+ columnMap,
480
+ onClick,
481
+ onDataEdited,
482
+ row
483
+ }) => {
484
+ const { className, style } = useCell(column, classBase4);
485
+ const { CellRenderer, index, name, valueFormatter } = column;
486
+ const dataIdx = columnMap[name];
487
+ const handleDataItemEdited = (0, import_react9.useCallback)(
488
+ (value) => {
489
+ if (onDataEdited) {
490
+ let typedValue = value;
491
+ if ((0, import_vuu_utils3.isNumericColumn)(column) && typeof value === "string") {
492
+ typedValue = column.serverDataType === "double" ? parseFloat(value) : parseInt(value);
493
+ }
494
+ return onDataEdited == null ? void 0 : onDataEdited(row, name, typedValue);
495
+ } else {
496
+ throw Error(
497
+ "TableCell onDataEdited prop not supplied for an editable cell"
498
+ );
499
+ }
500
+ },
501
+ [column, name, onDataEdited, row]
502
+ );
503
+ const handleClick = (0, import_react9.useCallback)(
504
+ (evt) => {
505
+ onClick == null ? void 0 : onClick(evt, column);
506
+ },
507
+ [column, onClick]
508
+ );
509
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
510
+ "div",
511
+ {
512
+ "aria-colindex": index,
513
+ className,
514
+ onClick: onClick ? handleClick : void 0,
515
+ role: "cell",
516
+ style,
517
+ children: CellRenderer ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
518
+ CellRenderer,
519
+ {
520
+ column,
521
+ columnMap,
522
+ onCommit: handleDataItemEdited,
523
+ row
524
+ }
525
+ ) : valueFormatter(row[dataIdx])
526
+ }
527
+ );
528
+ };
529
+
530
+ // src/table-cell/TableGroupCell.tsx
531
+ var import_vuu_utils4 = require("@vuu-ui/vuu-utils");
532
+ var import_react10 = require("react");
533
+ var import_clsx6 = __toESM(require("clsx"));
534
+ var import_jsx_runtime9 = require("react/jsx-runtime");
535
+ var { IS_LEAF } = import_vuu_utils4.metadataKeys;
536
+ var classBase5 = "vuuTableGroupCell";
537
+ var TableGroupCell = ({
538
+ column,
539
+ columnMap,
540
+ onClick,
541
+ row
542
+ }) => {
543
+ const { columns } = column;
544
+ const [value, offset] = (0, import_vuu_utils4.getGroupValueAndOffset)(columns, row, columnMap);
545
+ const { className, style } = useCell(column, classBase5);
546
+ const handleClick = (0, import_react10.useCallback)(
547
+ (evt) => {
548
+ onClick == null ? void 0 : onClick(evt, column);
549
+ },
550
+ [column, onClick]
551
+ );
552
+ const isLeaf = row[IS_LEAF];
553
+ const spacers = Array(offset).fill(0).map((n, i) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${classBase5}-spacer` }, i));
554
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
555
+ "div",
556
+ {
557
+ className: (0, import_clsx6.default)(className, "vuuTableCell"),
558
+ role: "cell",
559
+ style,
560
+ onClick: isLeaf ? void 0 : handleClick,
561
+ children: [
562
+ spacers,
563
+ isLeaf ? null : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: `${classBase5}-toggle`, "data-icon": "triangle-right" }),
564
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { children: value })
565
+ ]
566
+ }
567
+ );
568
+ };
569
+
570
+ // src/Row.tsx
571
+ var import_jsx_runtime10 = require("react/jsx-runtime");
572
+ var { IDX, IS_EXPANDED, SELECTED } = import_vuu_utils5.metadataKeys;
573
+ var classBase6 = "vuuTableRow";
574
+ var RowProxy = (0, import_react11.forwardRef)(
575
+ function RowProxy2({ height }, forwardedRef) {
576
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
577
+ "div",
578
+ {
579
+ "aria-hidden": true,
580
+ className: (0, import_clsx7.default)(classBase6, `${classBase6}-proxy`),
581
+ ref: forwardedRef,
582
+ style: { height }
583
+ }
584
+ );
585
+ }
586
+ );
587
+ var Row = (0, import_react11.memo)(
588
+ ({
589
+ className: classNameProp,
590
+ classNameGenerator,
591
+ columnMap,
592
+ columns,
593
+ highlighted,
594
+ row,
595
+ offset,
596
+ onClick,
597
+ onDataEdited,
598
+ onToggleGroup,
599
+ virtualColSpan = 0,
600
+ zebraStripes = false,
601
+ ...htmlAttributes
602
+ }) => {
603
+ const {
604
+ [IDX]: rowIndex,
605
+ [IS_EXPANDED]: isExpanded,
606
+ [SELECTED]: selectionStatus
607
+ } = row;
608
+ const handleRowClick = (0, import_react11.useCallback)(
609
+ (evt) => {
610
+ const rangeSelect = evt.shiftKey;
611
+ const keepExistingSelection = evt.ctrlKey || evt.metaKey;
612
+ onClick == null ? void 0 : onClick(row, rangeSelect, keepExistingSelection);
613
+ },
614
+ [onClick, row]
615
+ );
616
+ const { True, First, Last } = import_vuu_utils5.RowSelected;
617
+ const className = (0, import_clsx7.default)(
618
+ classBase6,
619
+ classNameProp,
620
+ classNameGenerator == null ? void 0 : classNameGenerator(row, columnMap),
621
+ {
622
+ [`${classBase6}-even`]: zebraStripes && rowIndex % 2 === 0,
623
+ [`${classBase6}-expanded`]: isExpanded,
624
+ [`${classBase6}-highlighted`]: highlighted,
625
+ [`${classBase6}-selected`]: selectionStatus & True,
626
+ [`${classBase6}-selectedStart`]: selectionStatus & First,
627
+ [`${classBase6}-selectedEnd`]: selectionStatus & Last
628
+ }
629
+ );
630
+ const style = { transform: `translate3d(0px, ${offset}px, 0px)` };
631
+ const handleGroupCellClick = (0, import_react11.useCallback)(
632
+ (evt, column) => {
633
+ if ((0, import_vuu_utils5.isGroupColumn)(column) || (0, import_vuu_utils5.isJsonGroup)(column, row, columnMap)) {
634
+ evt.stopPropagation();
635
+ onToggleGroup == null ? void 0 : onToggleGroup(row, column);
636
+ }
637
+ },
638
+ [columnMap, onToggleGroup, row]
639
+ );
640
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(
641
+ "div",
642
+ {
643
+ ...htmlAttributes,
644
+ role: "row",
645
+ className,
646
+ onClick: handleRowClick,
647
+ style,
648
+ children: [
649
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: `${classBase6}-selectionDecorator vuuStickyLeft` }),
650
+ virtualColSpan > 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "vuuTableCell", style: { width: virtualColSpan } }) : null,
651
+ columns.filter(import_vuu_utils5.isNotHidden).map((column) => {
652
+ const isGroup = (0, import_vuu_utils5.isGroupColumn)(column);
653
+ const isJsonCell = (0, import_vuu_utils5.isJsonColumn)(column);
654
+ const Cell = isGroup ? TableGroupCell : TableCell;
655
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
656
+ Cell,
657
+ {
658
+ column,
659
+ columnMap,
660
+ onClick: isGroup || isJsonCell ? handleGroupCellClick : void 0,
661
+ onDataEdited,
662
+ row
663
+ },
664
+ column.name
665
+ );
666
+ }),
667
+ /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("span", { className: `${classBase6}-selectionDecorator vuuStickyRight` })
668
+ ]
669
+ }
670
+ );
671
+ }
672
+ );
673
+ Row.displayName = "Row";
674
+
675
+ // src/table-header/TableHeader.tsx
676
+ var import_vuu_utils7 = require("@vuu-ui/vuu-utils");
677
+ var import_clsx8 = __toESM(require("clsx"));
678
+ var import_react13 = require("react");
679
+
680
+ // src/table-header/useTableHeader.ts
681
+ var import_vuu_ui_controls2 = require("@vuu-ui/vuu-ui-controls");
682
+ var import_vuu_utils6 = require("@vuu-ui/vuu-utils");
683
+ var import_react12 = require("react");
684
+ var useTableHeader = ({
685
+ columns,
686
+ onMoveColumn,
687
+ onSortColumn,
688
+ tableConfig
689
+ }) => {
690
+ const containerRef = (0, import_react12.useRef)(null);
691
+ const scrollingContainerRef = (0, import_react12.useRef)(null);
692
+ const setContainerRef = (0, import_react12.useCallback)((el) => {
693
+ containerRef.current = el;
694
+ if (el) {
695
+ scrollingContainerRef.current = el.closest(".vuuTable-contentContainer");
696
+ } else {
697
+ scrollingContainerRef.current = null;
698
+ }
699
+ }, []);
700
+ const handleDropColumnHeader = (0, import_react12.useCallback)(
701
+ ({ fromIndex: moveFrom, toIndex: moveTo }) => {
702
+ const column = columns[moveFrom];
703
+ const orderedColumns = (0, import_vuu_utils6.moveColumnTo)(columns, column, moveTo);
704
+ const ofColumn = ({ name }) => (col) => col.name === name;
705
+ const targetIndex = orderedColumns.findIndex(ofColumn(column));
706
+ const nextColumn = orderedColumns[targetIndex + 1];
707
+ const insertPos = nextColumn ? tableConfig.columns.findIndex(ofColumn(nextColumn)) : -1;
708
+ if (moveTo > moveFrom && insertPos !== -1) {
709
+ onMoveColumn((0, import_vuu_utils6.moveColumnTo)(tableConfig.columns, column, insertPos - 1));
710
+ } else {
711
+ onMoveColumn((0, import_vuu_utils6.moveColumnTo)(tableConfig.columns, column, insertPos));
712
+ }
713
+ },
714
+ [columns, onMoveColumn, tableConfig.columns]
715
+ );
716
+ const handleColumnHeaderClick = (0, import_react12.useCallback)(
717
+ (evt) => {
718
+ var _a;
719
+ const targetElement = evt.target;
720
+ const headerCell = targetElement.closest(
721
+ ".vuuTableHeaderCell"
722
+ );
723
+ const colIdx = parseInt((_a = headerCell == null ? void 0 : headerCell.dataset.index) != null ? _a : "-1");
724
+ const column = (0, import_vuu_utils6.visibleColumnAtIndex)(columns, colIdx);
725
+ const isAdditive = evt.shiftKey;
726
+ column && onSortColumn(column, isAdditive);
727
+ },
728
+ [columns, onSortColumn]
729
+ );
730
+ const {
731
+ onMouseDown: columnHeaderDragMouseDown,
732
+ draggable: draggableColumn,
733
+ ...dragDropHook
734
+ } = (0, import_vuu_ui_controls2.useDragDrop)({
735
+ allowDragDrop: true,
736
+ containerRef,
737
+ draggableClassName: `vuuTable`,
738
+ itemQuery: ".vuuTableHeaderCell",
739
+ onDrop: handleDropColumnHeader,
740
+ orientation: "horizontal",
741
+ scrollingContainerRef
742
+ });
743
+ return {
744
+ draggableColumn,
745
+ draggedColumnIndex: dragDropHook.draggedItemIndex,
746
+ onClick: handleColumnHeaderClick,
747
+ onMouseDown: columnHeaderDragMouseDown,
748
+ setContainerRef
749
+ };
750
+ };
751
+
752
+ // src/table-header/TableHeader.tsx
753
+ var import_jsx_runtime11 = require("react/jsx-runtime");
754
+ var TableHeader = (0, import_react13.memo)(
755
+ ({
756
+ classBase: classBase10 = "vuuTable",
757
+ columns,
758
+ headings,
759
+ onMoveColumn,
760
+ onMoveGroupColumn,
761
+ onRemoveGroupColumn,
762
+ onResizeColumn,
763
+ onSortColumn,
764
+ tableConfig,
765
+ tableId,
766
+ virtualColSpan = 0
767
+ }) => {
768
+ const {
769
+ draggableColumn,
770
+ draggedColumnIndex,
771
+ onClick,
772
+ onMouseDown,
773
+ setContainerRef
774
+ } = useTableHeader({
775
+ columns,
776
+ onMoveColumn,
777
+ onSortColumn,
778
+ tableConfig
779
+ });
780
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: `${classBase10}-col-headings`, ref: setContainerRef, children: [
781
+ headings.map((colHeaders, i) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "vuuTable-heading", children: colHeaders.map(({ label, width }, j) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "vuuTable-headingCell", style: { width }, children: label }, j)) }, i)),
782
+ /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: `${classBase10}-col-headers`, role: "row", children: [
783
+ virtualColSpan > 0 ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
784
+ "div",
785
+ {
786
+ role: "cell",
787
+ className: "vuuTableCell",
788
+ style: { width: virtualColSpan }
789
+ }
790
+ ) : null,
791
+ columns.filter(import_vuu_utils7.isNotHidden).map(
792
+ (col, i) => (0, import_vuu_utils7.isGroupColumn)(col) ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
793
+ GroupHeaderCellNext,
794
+ {
795
+ "aria-colindex": col.index,
796
+ column: col,
797
+ "data-index": i,
798
+ onMoveColumn: onMoveGroupColumn,
799
+ onRemoveColumn: onRemoveGroupColumn,
800
+ onResize: onResizeColumn
801
+ },
802
+ col.name
803
+ ) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
804
+ HeaderCell,
805
+ {
806
+ "aria-colindex": col.index,
807
+ className: (0, import_clsx8.default)({
808
+ "vuuDraggable-dragAway": i === draggedColumnIndex
809
+ }),
810
+ column: col,
811
+ "data-index": i,
812
+ id: `${tableId}-col-${i}`,
813
+ onClick,
814
+ onMouseDown,
815
+ onResize: onResizeColumn
816
+ },
817
+ col.name
818
+ )
819
+ ),
820
+ draggableColumn
821
+ ] })
822
+ ] });
823
+ }
824
+ );
825
+ TableHeader.displayName = "TableHeader";
826
+
827
+ // src/useTable.ts
828
+ var import_vuu_ui_controls4 = require("@vuu-ui/vuu-ui-controls");
829
+ var import_vuu_utils22 = require("@vuu-ui/vuu-utils");
830
+ var import_react25 = require("react");
831
+
832
+ // src/context-menu/buildContextMenuDescriptors.ts
833
+ var import_vuu_utils8 = require("@vuu-ui/vuu-utils");
834
+ var buildContextMenuDescriptors = (dataSource) => (location, options) => {
835
+ const descriptors = [];
836
+ if (dataSource === void 0) {
837
+ return descriptors;
838
+ }
839
+ if (location === "header" || location === "column-menu") {
840
+ descriptors.push(
841
+ ...buildSortMenuItems(options, dataSource)
842
+ );
843
+ descriptors.push(
844
+ ...buildGroupMenuItems(options, dataSource)
845
+ );
846
+ descriptors.push(
847
+ ...buildAggregationMenuItems(options, dataSource)
848
+ );
849
+ descriptors.push(...buildColumnDisplayMenuItems(options));
850
+ descriptors.push({
851
+ action: "column-settings",
852
+ icon: "cog",
853
+ label: `Column Settings`,
854
+ options
855
+ });
856
+ descriptors.push({
857
+ action: "table-settings",
858
+ icon: "cog",
859
+ label: `DataGrid Settings`,
860
+ options
861
+ });
862
+ }
863
+ return descriptors;
864
+ };
865
+ function buildSortMenuItems(options, { sort: { sortDefs } }) {
866
+ const { column } = options;
867
+ const menuItems = [];
868
+ if (column === void 0) {
869
+ return menuItems;
870
+ }
871
+ const hasSort = sortDefs.length > 0;
872
+ if (column.sorted === "A") {
873
+ menuItems.push({
874
+ label: "Reverse Sort (DSC)",
875
+ action: "sort-dsc",
876
+ options
877
+ });
878
+ } else if (column.sorted === "D") {
879
+ menuItems.push({
880
+ label: "Reverse Sort (ASC)",
881
+ action: "sort-asc",
882
+ options
883
+ });
884
+ } else if (typeof column.sorted === "number") {
885
+ if (column.sorted > 0) {
886
+ menuItems.push({
887
+ label: "Reverse Sort (DSC)",
888
+ action: "sort-add-dsc",
889
+ options
890
+ });
891
+ } else {
892
+ menuItems.push({
893
+ label: "Reverse Sort (ASC)",
894
+ action: "sort-add-asc",
895
+ options
896
+ });
897
+ }
898
+ if (hasSort && Math.abs(column.sorted) < sortDefs.length) {
899
+ menuItems.push({
900
+ label: "Remove from sort",
901
+ action: "sort-remove",
902
+ options
903
+ });
904
+ }
905
+ menuItems.push({
906
+ label: "New Sort",
907
+ children: [
908
+ { label: "Ascending", action: "sort-asc", options },
909
+ { label: "Descending", action: "sort-dsc", options }
910
+ ]
911
+ });
912
+ } else if (hasSort) {
913
+ menuItems.push({
914
+ label: "Add to sort",
915
+ children: [
916
+ { label: "Ascending", action: "sort-add-asc", options },
917
+ { label: "Descending", action: "sort-add-dsc", options }
918
+ ]
919
+ });
920
+ menuItems.push({
921
+ label: "New Sort",
922
+ children: [
923
+ { label: "Ascending", action: "sort-asc", options },
924
+ { label: "Descending", action: "sort-dsc", options }
925
+ ]
926
+ });
927
+ } else {
928
+ menuItems.push({
929
+ label: "Sort",
930
+ children: [
931
+ { label: "Ascending", action: "sort-asc", options },
932
+ { label: "Descending", action: "sort-dsc", options }
933
+ ]
934
+ });
935
+ }
936
+ return menuItems;
937
+ }
938
+ function buildAggregationMenuItems(options, dataSource) {
939
+ const { column } = options;
940
+ if (column === void 0 || dataSource.groupBy.length === 0) {
941
+ return [];
942
+ }
943
+ const { name, label = name } = column;
944
+ return [
945
+ {
946
+ label: `Aggregate ${label}`,
947
+ children: [
948
+ { label: "Count", action: "agg-count", options },
949
+ { label: "Distinct", action: "agg-distinct", options }
950
+ ].concat(
951
+ (0, import_vuu_utils8.isNumericColumn)(column) ? [
952
+ { label: "Sum", action: "agg-sum", options },
953
+ { label: "Avg", action: "agg-avg", options },
954
+ { label: "High", action: "agg-high", options },
955
+ { label: "Low", action: "agg-low", options }
956
+ ] : []
957
+ )
958
+ }
959
+ ];
960
+ }
961
+ var pinColumn = (options, pinLocation) => ({
962
+ label: `Pin ${pinLocation}`,
963
+ action: `column-pin-${pinLocation}`,
964
+ options
965
+ });
966
+ var pinLeft = (options) => pinColumn(options, "left");
967
+ var pinFloating = (options) => pinColumn(options, "floating");
968
+ var pinRight = (options) => pinColumn(options, "right");
969
+ function buildColumnDisplayMenuItems(options) {
970
+ const { column } = options;
971
+ if (column === void 0) {
972
+ return [];
973
+ }
974
+ const { pin } = column;
975
+ const menuItems = [
976
+ {
977
+ label: `Hide column`,
978
+ action: "column-hide",
979
+ options
980
+ },
981
+ {
982
+ label: `Remove column`,
983
+ action: "column-remove",
984
+ options
985
+ }
986
+ ];
987
+ if (pin === void 0) {
988
+ menuItems.push({
989
+ label: `Pin column`,
990
+ children: [pinLeft(options), pinFloating(options), pinRight(options)]
991
+ });
992
+ } else if (pin === "left") {
993
+ menuItems.push(
994
+ { label: "Unpin column", action: "column-unpin", options },
995
+ {
996
+ label: `Pin column`,
997
+ children: [pinFloating(options), pinRight(options)]
998
+ }
999
+ );
1000
+ } else if (pin === "right") {
1001
+ menuItems.push(
1002
+ { label: "Unpin column", action: "column-unpin", options },
1003
+ {
1004
+ label: `Pin column`,
1005
+ children: [pinLeft(options), pinFloating(options)]
1006
+ }
1007
+ );
1008
+ } else if (pin === "floating") {
1009
+ menuItems.push(
1010
+ { label: "Unpin column", action: "column-unpin", options },
1011
+ {
1012
+ label: `Pin column`,
1013
+ children: [pinLeft(options), pinRight(options)]
1014
+ }
1015
+ );
1016
+ }
1017
+ return menuItems;
1018
+ }
1019
+ function buildGroupMenuItems(options, { groupBy }) {
1020
+ const { column } = options;
1021
+ const menuItems = [];
1022
+ if (column === void 0) {
1023
+ return menuItems;
1024
+ }
1025
+ const { name, label = name } = column;
1026
+ if (groupBy.length === 0) {
1027
+ menuItems.push({
1028
+ label: `Group by ${label}`,
1029
+ action: "group",
1030
+ options
1031
+ });
1032
+ } else {
1033
+ menuItems.push({
1034
+ label: `Add ${label} to group by`,
1035
+ action: "group-add",
1036
+ options
1037
+ });
1038
+ }
1039
+ return menuItems;
1040
+ }
1041
+
1042
+ // src/context-menu/useHandleTableContextMenu.ts
1043
+ var import_vuu_utils9 = require("@vuu-ui/vuu-utils");
1044
+ var import_vuu_utils10 = require("@vuu-ui/vuu-utils");
1045
+ var removeFilterColumn = (dataSourceFilter, column) => {
1046
+ if (dataSourceFilter.filterStruct && column) {
1047
+ const [filterStruct, filter] = (0, import_vuu_utils9.removeColumnFromFilter)(
1048
+ column,
1049
+ dataSourceFilter.filterStruct
1050
+ );
1051
+ return {
1052
+ filter,
1053
+ filterStruct
1054
+ };
1055
+ } else {
1056
+ return dataSourceFilter;
1057
+ }
1058
+ };
1059
+ var { Average, Count, Distinct, High, Low, Sum } = import_vuu_utils10.AggregationType;
1060
+ var useHandleTableContextMenu = ({
1061
+ dataSource,
1062
+ onPersistentColumnOperation
1063
+ }) => {
1064
+ const handleContextMenuAction = (action) => {
1065
+ const gridOptions = action.options;
1066
+ if (gridOptions.column && dataSource) {
1067
+ const { column } = gridOptions;
1068
+ switch (action.menuId) {
1069
+ case "sort-asc":
1070
+ return dataSource.sort = (0, import_vuu_utils10.setSortColumn)(dataSource.sort, column, "A"), true;
1071
+ case "sort-dsc":
1072
+ return dataSource.sort = (0, import_vuu_utils10.setSortColumn)(dataSource.sort, column, "D"), true;
1073
+ case "sort-add-asc":
1074
+ return dataSource.sort = (0, import_vuu_utils10.addSortColumn)(dataSource.sort, column, "A"), true;
1075
+ case "sort-add-dsc":
1076
+ return dataSource.sort = (0, import_vuu_utils10.addSortColumn)(dataSource.sort, column, "D"), true;
1077
+ case "group":
1078
+ return dataSource.groupBy = (0, import_vuu_utils10.addGroupColumn)(dataSource.groupBy, column), true;
1079
+ case "group-add":
1080
+ return dataSource.groupBy = (0, import_vuu_utils10.addGroupColumn)(dataSource.groupBy, column), true;
1081
+ case "column-hide":
1082
+ return onPersistentColumnOperation({ type: "hideColumns", columns: [column] }), true;
1083
+ case "column-remove":
1084
+ return dataSource.columns = dataSource.columns.filter((name) => name !== column.name), true;
1085
+ case "filter-remove-column":
1086
+ return dataSource.filter = removeFilterColumn(dataSource.filter, column), true;
1087
+ case "remove-filters":
1088
+ return dataSource.filter = { filter: "" }, true;
1089
+ case "agg-avg":
1090
+ return dataSource.aggregations = (0, import_vuu_utils10.setAggregations)(dataSource.aggregations, column, Average), true;
1091
+ case "agg-high":
1092
+ return dataSource.aggregations = (0, import_vuu_utils10.setAggregations)(dataSource.aggregations, column, High), true;
1093
+ case "agg-low":
1094
+ return dataSource.aggregations = (0, import_vuu_utils10.setAggregations)(dataSource.aggregations, column, Low), true;
1095
+ case "agg-count":
1096
+ return dataSource.aggregations = (0, import_vuu_utils10.setAggregations)(dataSource.aggregations, column, Count), true;
1097
+ case "agg-distinct":
1098
+ return dataSource.aggregations = (0, import_vuu_utils10.setAggregations)(dataSource.aggregations, column, Distinct), true;
1099
+ case "agg-sum":
1100
+ return dataSource.aggregations = (0, import_vuu_utils10.setAggregations)(dataSource.aggregations, column, Sum), true;
1101
+ case "column-pin-floating":
1102
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "floating" }), true;
1103
+ case "column-pin-left":
1104
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "left" }), true;
1105
+ case "column-pin-right":
1106
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: "right" }), true;
1107
+ case "column-unpin":
1108
+ return onPersistentColumnOperation({ type: "pinColumn", column, pin: void 0 }), true;
1109
+ case "column-settings":
1110
+ return onPersistentColumnOperation({ type: "columnSettings", column }), true;
1111
+ case "table-settings":
1112
+ return onPersistentColumnOperation({ type: "tableSettings" }), true;
1113
+ default:
1114
+ }
1115
+ }
1116
+ return false;
1117
+ };
1118
+ return handleContextMenuAction;
1119
+ };
1120
+
1121
+ // src/table-config.ts
1122
+ var updateTableConfig = (config, action) => {
1123
+ switch (action.type) {
1124
+ case "col-size":
1125
+ return {
1126
+ ...config,
1127
+ columns: config.columns.map(
1128
+ (col) => col.name === action.column.name ? { ...col, width: action.width } : col
1129
+ )
1130
+ };
1131
+ case "column-prop":
1132
+ return {
1133
+ ...config,
1134
+ columns: config.columns.map(
1135
+ (col) => col.name === action.column.name ? { ...col, [action.property]: action.value } : col
1136
+ )
1137
+ };
1138
+ default:
1139
+ return config;
1140
+ }
1141
+ };
1142
+
1143
+ // src/useCellEditing.ts
1144
+ var import_vuu_utils11 = require("@vuu-ui/vuu-utils");
1145
+ var import_react14 = require("react");
1146
+
1147
+ // src/table-dom-utils.ts
1148
+ var headerCellQuery = (colIdx) => `.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${colIdx})`;
1149
+ var dataCellQuery = (rowIdx, colIdx) => `.vuuTable-body > [aria-rowindex='${rowIdx + 1}'] > [role='cell']:nth-child(${colIdx + 1})`;
1150
+ var getTableCell = (containerRef, [rowIdx, colIdx]) => {
1151
+ var _a;
1152
+ const cssQuery = rowIdx === -1 ? headerCellQuery(colIdx) : dataCellQuery(rowIdx, colIdx);
1153
+ const cell = (_a = containerRef.current) == null ? void 0 : _a.querySelector(
1154
+ cssQuery
1155
+ );
1156
+ if (cellIsEditable(cell)) {
1157
+ const focusableContent = cell.querySelector("button");
1158
+ return focusableContent || cell;
1159
+ } else {
1160
+ return cell;
1161
+ }
1162
+ };
1163
+ var cellIsEditable = (cell) => cell == null ? void 0 : cell.classList.contains("vuuTableCell-editable");
1164
+ var cellIsTextInput = (cell) => cell.querySelector(".vuuTableInputCell") !== null;
1165
+ function getRowIndex(rowEl) {
1166
+ if (rowEl) {
1167
+ const idx = rowEl.ariaRowIndex;
1168
+ if (idx !== null) {
1169
+ return parseInt(idx, 10) - 1;
1170
+ }
1171
+ }
1172
+ return -1;
1173
+ }
1174
+ var closestRow = (el) => el.closest('[role="row"]');
1175
+ var closestRowIndex = (el) => getRowIndex(closestRow(el));
1176
+ var NO_SCROLL_NECESSARY = [void 0, void 0];
1177
+ var howFarIsRowOutsideViewport = (rowEl, totalHeaderHeight, contentContainer = rowEl.closest(".vuuTable-contentContainer")) => {
1178
+ if (contentContainer) {
1179
+ const viewport = contentContainer == null ? void 0 : contentContainer.getBoundingClientRect();
1180
+ const upperBoundary = viewport.top + totalHeaderHeight;
1181
+ const row = rowEl.getBoundingClientRect();
1182
+ if (row) {
1183
+ if (row.bottom > viewport.bottom) {
1184
+ return ["down", row.bottom - viewport.bottom];
1185
+ } else if (row.top < upperBoundary) {
1186
+ return ["up", row.top - upperBoundary];
1187
+ } else {
1188
+ return NO_SCROLL_NECESSARY;
1189
+ }
1190
+ } else {
1191
+ throw Error("Whats going on, row not found");
1192
+ }
1193
+ } else {
1194
+ throw Error("Whats going on, scrollbar container not found");
1195
+ }
1196
+ };
1197
+
1198
+ // src/useCellEditing.ts
1199
+ var useCellEditing = ({ navigate }) => {
1200
+ const commitHandler = (0, import_react14.useCallback)(() => {
1201
+ navigate();
1202
+ }, [navigate]);
1203
+ const editInput = (0, import_react14.useCallback)(
1204
+ (evt) => {
1205
+ const cellEl = evt.target;
1206
+ const input = cellEl.matches("input") ? cellEl : cellEl.querySelector("input");
1207
+ if (input) {
1208
+ input.focus();
1209
+ input.select();
1210
+ }
1211
+ },
1212
+ []
1213
+ );
1214
+ const focusInput = (0, import_react14.useCallback)(
1215
+ (evt) => {
1216
+ const cellEl = evt.target;
1217
+ const input = cellEl.querySelector("input");
1218
+ if (input) {
1219
+ input.focus();
1220
+ input.select();
1221
+ }
1222
+ },
1223
+ []
1224
+ );
1225
+ const handleKeyDown = (0, import_react14.useCallback)(
1226
+ (e) => {
1227
+ const el = e.target;
1228
+ if (cellIsTextInput(el)) {
1229
+ if ((0, import_vuu_utils11.isCharacterKey)(e.key)) {
1230
+ editInput(e);
1231
+ } else if (e.key === "Enter") {
1232
+ focusInput(e);
1233
+ }
1234
+ }
1235
+ },
1236
+ [editInput, focusInput]
1237
+ );
1238
+ const handleDoubleClick = (0, import_react14.useCallback)(
1239
+ (e) => {
1240
+ const el = e.target;
1241
+ if (el.matches("input") || el.querySelector("input")) {
1242
+ editInput(e);
1243
+ e.stopPropagation();
1244
+ }
1245
+ },
1246
+ [editInput]
1247
+ );
1248
+ const handleBlur = (0, import_react14.useCallback)(
1249
+ (e) => {
1250
+ const el = e.target;
1251
+ el.removeEventListener("vuu-commit", commitHandler, true);
1252
+ },
1253
+ [commitHandler]
1254
+ );
1255
+ const handleFocus = (0, import_react14.useCallback)(
1256
+ (e) => {
1257
+ const el = e.target;
1258
+ el.addEventListener("vuu-commit", commitHandler, true);
1259
+ },
1260
+ [commitHandler]
1261
+ );
1262
+ return {
1263
+ onBlur: handleBlur,
1264
+ onDoubleClick: handleDoubleClick,
1265
+ onFocus: handleFocus,
1266
+ onKeyDown: handleKeyDown
1267
+ };
1268
+ };
1269
+
1270
+ // src/useDataSource.ts
1271
+ var import_vuu_utils13 = require("@vuu-ui/vuu-utils");
1272
+ var import_react15 = require("react");
1273
+
1274
+ // src/moving-window.ts
1275
+ var import_vuu_utils12 = require("@vuu-ui/vuu-utils");
1276
+ var { SELECTED: SELECTED2 } = import_vuu_utils12.metadataKeys;
1277
+ var MovingWindow = class {
1278
+ constructor({ from, to }) {
1279
+ this.rowCount = 0;
1280
+ this.setRowCount = (rowCount) => {
1281
+ if (rowCount < this.data.length) {
1282
+ this.data.length = rowCount;
1283
+ }
1284
+ this.rowCount = rowCount;
1285
+ };
1286
+ this.range = new import_vuu_utils12.WindowRange(from, to);
1287
+ this.data = new Array(Math.max(0, to - from));
1288
+ this.rowCount = 0;
1289
+ }
1290
+ add(data) {
1291
+ const [index] = data;
1292
+ if (this.isWithinRange(index)) {
1293
+ const internalIndex = index - this.range.from;
1294
+ this.data[internalIndex] = data;
1295
+ if (data[SELECTED2]) {
1296
+ const previousRow = this.data[internalIndex - 1];
1297
+ if ((0, import_vuu_utils12.isRowSelectedLast)(previousRow)) {
1298
+ this.data[internalIndex - 1] = previousRow.slice();
1299
+ this.data[internalIndex - 1][SELECTED2] -= 4;
1300
+ }
1301
+ }
1302
+ }
1303
+ }
1304
+ getAtIndex(index) {
1305
+ return this.range.isWithin(index) && this.data[index - this.range.from] != null ? this.data[index - this.range.from] : void 0;
1306
+ }
1307
+ isWithinRange(index) {
1308
+ return this.range.isWithin(index);
1309
+ }
1310
+ setRange({ from, to }) {
1311
+ if (from !== this.range.from || to !== this.range.to) {
1312
+ const [overlapFrom, overlapTo] = this.range.overlap(from, to);
1313
+ const newData = new Array(Math.max(0, to - from));
1314
+ for (let i = overlapFrom; i < overlapTo; i++) {
1315
+ const data = this.getAtIndex(i);
1316
+ if (data) {
1317
+ const index = i - from;
1318
+ newData[index] = data;
1319
+ }
1320
+ }
1321
+ this.data = newData;
1322
+ this.range.from = from;
1323
+ this.range.to = to;
1324
+ }
1325
+ }
1326
+ getSelectedRows() {
1327
+ return this.data.filter((row) => row[SELECTED2] !== 0);
1328
+ }
1329
+ };
1330
+
1331
+ // src/useDataSource.ts
1332
+ var isVuuFeatureInvocation = (action) => action.type === "vuu-link-created" || action.type === "vuu-link-removed";
1333
+ var useDataSource = ({
1334
+ dataSource,
1335
+ onFeatureInvocation,
1336
+ onSizeChange,
1337
+ onSubscribed,
1338
+ range = import_vuu_utils13.NULL_RANGE,
1339
+ renderBufferSize = 0
1340
+ }) => {
1341
+ const [, forceUpdate] = (0, import_react15.useState)(null);
1342
+ const data = (0, import_react15.useRef)([]);
1343
+ const isMounted = (0, import_react15.useRef)(true);
1344
+ const hasUpdated = (0, import_react15.useRef)(false);
1345
+ const rangeRef = (0, import_react15.useRef)(range);
1346
+ const dataWindow = (0, import_react15.useMemo)(
1347
+ () => new MovingWindow((0, import_vuu_utils13.getFullRange)(range, renderBufferSize)),
1348
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1349
+ []
1350
+ );
1351
+ const setData = (0, import_react15.useCallback)(
1352
+ (updates) => {
1353
+ for (const row of updates) {
1354
+ dataWindow.add(row);
1355
+ }
1356
+ data.current = dataWindow.data;
1357
+ if (isMounted.current) {
1358
+ forceUpdate({});
1359
+ } else {
1360
+ }
1361
+ },
1362
+ [dataWindow]
1363
+ );
1364
+ const datasourceMessageHandler = (0, import_react15.useCallback)(
1365
+ (message) => {
1366
+ if (message.type === "subscribed") {
1367
+ onSubscribed == null ? void 0 : onSubscribed(message);
1368
+ } else if (message.type === "viewport-update") {
1369
+ if (typeof message.size === "number") {
1370
+ onSizeChange == null ? void 0 : onSizeChange(message.size);
1371
+ dataWindow.setRowCount(message.size);
1372
+ }
1373
+ if (message.rows) {
1374
+ setData(message.rows);
1375
+ } else if (typeof message.size === "number") {
1376
+ data.current = dataWindow.data;
1377
+ hasUpdated.current = true;
1378
+ }
1379
+ } else if (isVuuFeatureInvocation(message)) {
1380
+ onFeatureInvocation == null ? void 0 : onFeatureInvocation(message);
1381
+ } else {
1382
+ console.log(`useDataSource unexpected message ${message.type}`);
1383
+ }
1384
+ },
1385
+ [dataWindow, onFeatureInvocation, onSizeChange, onSubscribed, setData]
1386
+ );
1387
+ const getSelectedRows = (0, import_react15.useCallback)(() => {
1388
+ return dataWindow.getSelectedRows();
1389
+ }, [dataWindow]);
1390
+ (0, import_react15.useEffect)(() => {
1391
+ var _a;
1392
+ isMounted.current = true;
1393
+ (_a = dataSource.resume) == null ? void 0 : _a.call(dataSource);
1394
+ return () => {
1395
+ var _a2;
1396
+ isMounted.current = false;
1397
+ (_a2 = dataSource.suspend) == null ? void 0 : _a2.call(dataSource);
1398
+ };
1399
+ }, [dataSource]);
1400
+ (0, import_react15.useEffect)(() => {
1401
+ var _a;
1402
+ if (dataSource.status === "disabled") {
1403
+ (_a = dataSource.enable) == null ? void 0 : _a.call(dataSource, datasourceMessageHandler);
1404
+ } else {
1405
+ dataSource == null ? void 0 : dataSource.subscribe(
1406
+ { range: (0, import_vuu_utils13.getFullRange)(range, renderBufferSize) },
1407
+ datasourceMessageHandler
1408
+ );
1409
+ }
1410
+ }, [dataSource, datasourceMessageHandler, range, renderBufferSize]);
1411
+ const setRange = (0, import_react15.useCallback)(
1412
+ (range2) => {
1413
+ if (!(0, import_vuu_utils13.rangesAreSame)(range2, rangeRef.current)) {
1414
+ const fullRange = (0, import_vuu_utils13.getFullRange)(range2, renderBufferSize);
1415
+ dataWindow.setRange(fullRange);
1416
+ dataSource.range = rangeRef.current = fullRange;
1417
+ dataSource.emit("range", range2);
1418
+ }
1419
+ },
1420
+ [dataSource, dataWindow, renderBufferSize]
1421
+ );
1422
+ return {
1423
+ data: data.current,
1424
+ dataRef: data,
1425
+ getSelectedRows,
1426
+ range: rangeRef.current,
1427
+ setRange
1428
+ };
1429
+ };
1430
+
1431
+ // src/useInitialValue.ts
1432
+ var import_react16 = require("react");
1433
+ var useInitialValue = (value) => {
1434
+ const ref = (0, import_react16.useRef)(value);
1435
+ return (0, import_react16.useMemo)(() => ref.current, []);
1436
+ };
1437
+
1438
+ // src/useKeyboardNavigation.ts
1439
+ var import_vuu_utils14 = require("@vuu-ui/vuu-utils");
1440
+ var import_core = require("@salt-ds/core");
1441
+ var import_react17 = require("react");
1442
+ var rowNavigationKeys = /* @__PURE__ */ new Set([
1443
+ "Home",
1444
+ "End",
1445
+ "PageUp",
1446
+ "PageDown",
1447
+ "ArrowDown",
1448
+ "ArrowUp"
1449
+ ]);
1450
+ var cellNavigationKeys = new Set(rowNavigationKeys);
1451
+ cellNavigationKeys.add("ArrowLeft");
1452
+ cellNavigationKeys.add("ArrowRight");
1453
+ var isNavigationKey = (key, navigationStyle) => {
1454
+ switch (navigationStyle) {
1455
+ case "cell":
1456
+ return cellNavigationKeys.has(key);
1457
+ case "row":
1458
+ return rowNavigationKeys.has(key);
1459
+ default:
1460
+ return false;
1461
+ }
1462
+ };
1463
+ var PageKeys = ["Home", "End", "PageUp", "PageDown"];
1464
+ var isPagingKey = (key) => PageKeys.includes(key);
1465
+ var NULL_CELL_POS = [-1, -1];
1466
+ function nextCellPos(key, [rowIdx, colIdx], columnCount, rowCount) {
1467
+ if (key === "ArrowUp") {
1468
+ if (rowIdx > -1) {
1469
+ return [rowIdx - 1, colIdx];
1470
+ } else {
1471
+ return [rowIdx, colIdx];
1472
+ }
1473
+ } else if (key === "ArrowDown") {
1474
+ if (rowIdx === -1) {
1475
+ return [0, colIdx];
1476
+ } else if (rowIdx === rowCount - 1) {
1477
+ return [rowIdx, colIdx];
1478
+ } else {
1479
+ return [rowIdx + 1, colIdx];
1480
+ }
1481
+ } else if (key === "ArrowRight") {
1482
+ if (colIdx < columnCount) {
1483
+ return [rowIdx, colIdx + 1];
1484
+ } else {
1485
+ return [rowIdx, colIdx];
1486
+ }
1487
+ } else if (key === "ArrowLeft") {
1488
+ if (colIdx > 1) {
1489
+ return [rowIdx, colIdx - 1];
1490
+ } else {
1491
+ return [rowIdx, colIdx];
1492
+ }
1493
+ }
1494
+ return [rowIdx, colIdx];
1495
+ }
1496
+ var useKeyboardNavigation = ({
1497
+ columnCount = 0,
1498
+ containerRef,
1499
+ disableFocus = false,
1500
+ defaultHighlightedIndex,
1501
+ disableHighlightOnFocus,
1502
+ highlightedIndex: highlightedIndexProp,
1503
+ navigationStyle,
1504
+ requestScroll,
1505
+ onHighlight,
1506
+ rowCount = 0,
1507
+ viewportRowCount
1508
+ }) => {
1509
+ var _a;
1510
+ const focusedCellPos = (0, import_react17.useRef)([-1, -1]);
1511
+ const focusableCell = (0, import_react17.useRef)();
1512
+ const activeCellPos = (0, import_react17.useRef)([-1, 0]);
1513
+ const highlightedIndexRef = (0, import_react17.useRef)();
1514
+ const [highlightedIndex, setHighlightedIdx] = (0, import_core.useControlled)({
1515
+ controlled: highlightedIndexProp,
1516
+ default: defaultHighlightedIndex,
1517
+ name: "UseKeyboardNavigation"
1518
+ });
1519
+ highlightedIndexRef.current = highlightedIndex;
1520
+ const setHighlightedIndex = (0, import_react17.useCallback)(
1521
+ (idx, fromKeyboard = false) => {
1522
+ onHighlight == null ? void 0 : onHighlight(idx);
1523
+ setHighlightedIdx(idx);
1524
+ if (fromKeyboard) {
1525
+ }
1526
+ },
1527
+ [onHighlight, setHighlightedIdx]
1528
+ );
1529
+ const getFocusedCell = (element) => element == null ? void 0 : element.closest(
1530
+ "[role='columnHeader'],[role='cell']"
1531
+ );
1532
+ const getTableCellPos = (tableCell) => {
1533
+ var _a2;
1534
+ if (tableCell.role === "columnHeader") {
1535
+ const colIdx = parseInt((_a2 = tableCell.dataset.idx) != null ? _a2 : "-1", 10);
1536
+ return [-1, colIdx];
1537
+ } else {
1538
+ const focusedRow = tableCell.closest("[role='row']");
1539
+ if (focusedRow) {
1540
+ const rowIdx = (0, import_vuu_utils14.getIndexFromRowElement)(focusedRow);
1541
+ const colIdx = Array.from(focusedRow.childNodes).indexOf(tableCell);
1542
+ return [rowIdx, colIdx];
1543
+ }
1544
+ }
1545
+ return NULL_CELL_POS;
1546
+ };
1547
+ const focusCell = (0, import_react17.useCallback)(
1548
+ (cellPos) => {
1549
+ var _a2;
1550
+ if (containerRef.current) {
1551
+ const activeCell = getTableCell(containerRef, cellPos);
1552
+ if (activeCell) {
1553
+ if (activeCell !== focusableCell.current) {
1554
+ (_a2 = focusableCell.current) == null ? void 0 : _a2.removeAttribute("tabindex");
1555
+ focusableCell.current = activeCell;
1556
+ activeCell.setAttribute("tabindex", "0");
1557
+ }
1558
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-row", rowIndex: cellPos[0] });
1559
+ activeCell.focus({ preventScroll: true });
1560
+ }
1561
+ }
1562
+ },
1563
+ // TODO we recreate this function whenever viewportRange changes, which will
1564
+ // be often whilst scrolling - store range in a a ref ?
1565
+ [containerRef, requestScroll]
1566
+ );
1567
+ const setActiveCell = (0, import_react17.useCallback)(
1568
+ (rowIdx, colIdx, fromKeyboard = false) => {
1569
+ const pos = [rowIdx, colIdx];
1570
+ activeCellPos.current = pos;
1571
+ if (navigationStyle === "row") {
1572
+ setHighlightedIdx(rowIdx);
1573
+ } else {
1574
+ focusCell(pos);
1575
+ }
1576
+ if (fromKeyboard) {
1577
+ focusedCellPos.current = pos;
1578
+ }
1579
+ },
1580
+ [focusCell, navigationStyle, setHighlightedIdx]
1581
+ );
1582
+ const nextPageItemIdx = (0, import_react17.useCallback)(
1583
+ (key, [rowIdx, colIdx]) => new Promise((resolve) => {
1584
+ let newRowIdx = rowIdx;
1585
+ switch (key) {
1586
+ case "PageDown": {
1587
+ newRowIdx = Math.min(rowCount - 1, rowIdx + viewportRowCount);
1588
+ if (newRowIdx !== rowIdx) {
1589
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "down" });
1590
+ }
1591
+ break;
1592
+ }
1593
+ case "PageUp": {
1594
+ newRowIdx = Math.max(0, rowIdx - viewportRowCount);
1595
+ if (newRowIdx !== rowIdx) {
1596
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-page", direction: "up" });
1597
+ }
1598
+ break;
1599
+ }
1600
+ case "Home": {
1601
+ newRowIdx = 0;
1602
+ if (newRowIdx !== rowIdx) {
1603
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "home" });
1604
+ }
1605
+ break;
1606
+ }
1607
+ case "End": {
1608
+ newRowIdx = rowCount - 1;
1609
+ if (newRowIdx !== rowIdx) {
1610
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-end", direction: "end" });
1611
+ }
1612
+ break;
1613
+ }
1614
+ }
1615
+ setTimeout(() => {
1616
+ resolve([newRowIdx, colIdx]);
1617
+ }, 35);
1618
+ }),
1619
+ [requestScroll, rowCount, viewportRowCount]
1620
+ );
1621
+ const handleFocus = (0, import_react17.useCallback)(() => {
1622
+ var _a2;
1623
+ if (disableHighlightOnFocus !== true) {
1624
+ if ((_a2 = containerRef.current) == null ? void 0 : _a2.contains(document.activeElement)) {
1625
+ const focusedCell = getFocusedCell(document.activeElement);
1626
+ if (focusedCell) {
1627
+ focusedCellPos.current = getTableCellPos(focusedCell);
1628
+ if (navigationStyle === "row") {
1629
+ setHighlightedIdx(focusedCellPos.current[0]);
1630
+ }
1631
+ }
1632
+ }
1633
+ }
1634
+ }, [
1635
+ disableHighlightOnFocus,
1636
+ containerRef,
1637
+ navigationStyle,
1638
+ setHighlightedIdx
1639
+ ]);
1640
+ const navigateChildItems = (0, import_react17.useCallback)(
1641
+ async (key) => {
1642
+ const [nextRowIdx, nextColIdx] = isPagingKey(key) ? await nextPageItemIdx(key, activeCellPos.current) : nextCellPos(key, activeCellPos.current, columnCount, rowCount);
1643
+ const [rowIdx, colIdx] = activeCellPos.current;
1644
+ if (nextRowIdx !== rowIdx || nextColIdx !== colIdx) {
1645
+ setActiveCell(nextRowIdx, nextColIdx, true);
1646
+ }
1647
+ },
1648
+ [columnCount, nextPageItemIdx, rowCount, setActiveCell]
1649
+ );
1650
+ const scrollRowIntoViewIfNecessary = (0, import_react17.useCallback)(
1651
+ (rowIndex) => {
1652
+ requestScroll == null ? void 0 : requestScroll({ type: "scroll-row", rowIndex });
1653
+ },
1654
+ [requestScroll]
1655
+ );
1656
+ const moveHighlightedRow = (0, import_react17.useCallback)(
1657
+ async (key) => {
1658
+ const { current: highlighted } = highlightedIndexRef;
1659
+ const [nextRowIdx] = isPagingKey(key) ? await nextPageItemIdx(key, [highlighted != null ? highlighted : -1, 0]) : nextCellPos(key, [highlighted != null ? highlighted : -1, 0], columnCount, rowCount);
1660
+ if (nextRowIdx !== highlighted) {
1661
+ setHighlightedIndex(nextRowIdx);
1662
+ scrollRowIntoViewIfNecessary(nextRowIdx);
1663
+ }
1664
+ },
1665
+ [
1666
+ columnCount,
1667
+ nextPageItemIdx,
1668
+ rowCount,
1669
+ scrollRowIntoViewIfNecessary,
1670
+ setHighlightedIndex
1671
+ ]
1672
+ );
1673
+ (0, import_react17.useEffect)(() => {
1674
+ if (highlightedIndexProp !== void 0 && highlightedIndexProp !== -1) {
1675
+ scrollRowIntoViewIfNecessary(highlightedIndexProp);
1676
+ }
1677
+ }, [highlightedIndexProp, scrollRowIntoViewIfNecessary]);
1678
+ const handleKeyDown = (0, import_react17.useCallback)(
1679
+ (e) => {
1680
+ if (rowCount > 0 && isNavigationKey(e.key, navigationStyle)) {
1681
+ e.preventDefault();
1682
+ e.stopPropagation();
1683
+ if (navigationStyle === "row") {
1684
+ moveHighlightedRow(e.key);
1685
+ } else {
1686
+ void navigateChildItems(e.key);
1687
+ }
1688
+ }
1689
+ },
1690
+ [rowCount, navigationStyle, moveHighlightedRow, navigateChildItems]
1691
+ );
1692
+ const handleClick = (0, import_react17.useCallback)(
1693
+ // Might not be a cell e.g the Settings button
1694
+ (evt) => {
1695
+ const target = evt.target;
1696
+ const focusedCell = getFocusedCell(target);
1697
+ if (focusedCell) {
1698
+ const [rowIdx, colIdx] = getTableCellPos(focusedCell);
1699
+ setActiveCell(rowIdx, colIdx);
1700
+ }
1701
+ },
1702
+ [setActiveCell]
1703
+ );
1704
+ const handleMouseLeave = (0, import_react17.useCallback)(() => {
1705
+ setHighlightedIndex(-1);
1706
+ }, [setHighlightedIndex]);
1707
+ const handleMouseMove = (0, import_react17.useCallback)(
1708
+ (evt) => {
1709
+ const idx = closestRowIndex(evt.target);
1710
+ if (idx !== -1 && idx !== highlightedIndexRef.current) {
1711
+ setHighlightedIndex(idx);
1712
+ }
1713
+ },
1714
+ [setHighlightedIndex]
1715
+ );
1716
+ const navigate = (0, import_react17.useCallback)(() => {
1717
+ navigateChildItems("ArrowDown");
1718
+ }, [navigateChildItems]);
1719
+ const fullyRendered = ((_a = containerRef.current) == null ? void 0 : _a.firstChild) != null;
1720
+ (0, import_react17.useEffect)(() => {
1721
+ if (fullyRendered && focusableCell.current === void 0 && !disableFocus) {
1722
+ const { current: container } = containerRef;
1723
+ const cell = (container == null ? void 0 : container.querySelector(headerCellQuery(0))) || (container == null ? void 0 : container.querySelector(dataCellQuery(0, 0)));
1724
+ if (cell) {
1725
+ cell.setAttribute("tabindex", "0");
1726
+ focusableCell.current = cell;
1727
+ }
1728
+ }
1729
+ }, [containerRef, disableFocus, fullyRendered]);
1730
+ return {
1731
+ highlightedIndexRef,
1732
+ navigate,
1733
+ onClick: handleClick,
1734
+ onFocus: handleFocus,
1735
+ onKeyDown: handleKeyDown,
1736
+ onMouseLeave: navigationStyle === "row" ? handleMouseLeave : void 0,
1737
+ onMouseMove: navigationStyle === "row" ? handleMouseMove : void 0
1738
+ };
1739
+ };
1740
+
1741
+ // src/useSelection.ts
1742
+ var import_vuu_utils15 = require("@vuu-ui/vuu-utils");
1743
+ var import_react18 = require("react");
1744
+ var { IDX: IDX2 } = import_vuu_utils15.metadataKeys;
1745
+ var NO_SELECTION = [];
1746
+ var defaultSelectionKeys = ["Enter", " "];
1747
+ var useSelection = ({
1748
+ highlightedIndexRef,
1749
+ selectionKeys = defaultSelectionKeys,
1750
+ selectionModel,
1751
+ onSelect,
1752
+ onSelectionChange
1753
+ }) => {
1754
+ selectionModel === "extended" || selectionModel === "checkbox";
1755
+ const lastActiveRef = (0, import_react18.useRef)(-1);
1756
+ const selectedRef = (0, import_react18.useRef)(NO_SELECTION);
1757
+ const isSelectionEvent = (0, import_react18.useCallback)(
1758
+ (evt) => selectionKeys.includes(evt.key),
1759
+ [selectionKeys]
1760
+ );
1761
+ const handleRowClick = (0, import_react18.useCallback)(
1762
+ (row, rangeSelect, keepExistingSelection) => {
1763
+ const { [IDX2]: idx } = row;
1764
+ const { current: active } = lastActiveRef;
1765
+ const { current: selected } = selectedRef;
1766
+ const selectOperation = (0, import_vuu_utils15.isRowSelected)(row) ? import_vuu_utils15.deselectItem : import_vuu_utils15.selectItem;
1767
+ const newSelected = selectOperation(
1768
+ selectionModel,
1769
+ selected,
1770
+ idx,
1771
+ rangeSelect,
1772
+ keepExistingSelection,
1773
+ active
1774
+ );
1775
+ selectedRef.current = newSelected;
1776
+ lastActiveRef.current = idx;
1777
+ onSelect == null ? void 0 : onSelect(row);
1778
+ onSelectionChange == null ? void 0 : onSelectionChange(newSelected);
1779
+ },
1780
+ [onSelect, onSelectionChange, selectionModel]
1781
+ );
1782
+ const handleKeyDown = (0, import_react18.useCallback)(
1783
+ (e) => {
1784
+ if (isSelectionEvent(e)) {
1785
+ const { current: rowIndex } = highlightedIndexRef;
1786
+ if (rowIndex !== void 0 && rowIndex !== -1) {
1787
+ const rowEl = e.target.querySelector(
1788
+ `[aria-rowindex="${rowIndex}"]`
1789
+ );
1790
+ if (rowEl) {
1791
+ (0, import_vuu_utils15.dispatchMouseEvent)(rowEl, "click");
1792
+ }
1793
+ }
1794
+ }
1795
+ },
1796
+ [highlightedIndexRef, isSelectionEvent]
1797
+ );
1798
+ return {
1799
+ onKeyDown: handleKeyDown,
1800
+ onRowClick: handleRowClick
1801
+ };
1802
+ };
1803
+
1804
+ // src/useTableContextMenu.ts
1805
+ var import_vuu_popups2 = require("@vuu-ui/vuu-popups");
1806
+ var import_vuu_utils16 = require("@vuu-ui/vuu-utils");
1807
+ var import_react19 = require("react");
1808
+ var NO_ROWS = [];
1809
+ var useTableContextMenu = ({
1810
+ columns,
1811
+ data,
1812
+ dataSource,
1813
+ getSelectedRows
1814
+ }) => {
1815
+ const [showContextMenu] = (0, import_vuu_popups2.useContextMenu)();
1816
+ const onContextMenu = (0, import_react19.useCallback)(
1817
+ (evt) => {
1818
+ const target = evt.target;
1819
+ const cellEl = target == null ? void 0 : target.closest("div[role='cell']");
1820
+ const rowEl = target == null ? void 0 : target.closest("div[role='row']");
1821
+ if (cellEl && rowEl) {
1822
+ const { selectedRowsCount } = dataSource;
1823
+ const columnMap = (0, import_vuu_utils16.buildColumnMap)(columns);
1824
+ const rowIndex = (0, import_vuu_utils16.getIndexFromRowElement)(rowEl);
1825
+ const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
1826
+ const row = data.find(([idx]) => idx === rowIndex);
1827
+ const columnName = columns[cellIndex];
1828
+ showContextMenu(evt, "grid", {
1829
+ columnMap,
1830
+ columnName,
1831
+ row,
1832
+ selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
1833
+ viewport: dataSource.viewport
1834
+ });
1835
+ }
1836
+ },
1837
+ [columns, data, dataSource, getSelectedRows, showContextMenu]
1838
+ );
1839
+ return onContextMenu;
1840
+ };
1841
+
1842
+ // src/useTableModel.ts
1843
+ var import_vuu_utils17 = require("@vuu-ui/vuu-utils");
1844
+ var import_vuu_ui_controls3 = require("@vuu-ui/vuu-ui-controls");
1845
+ var import_react20 = require("react");
1846
+ var { info } = (0, import_vuu_utils17.logger)("useTableModel");
1847
+ var DEFAULT_COLUMN_WIDTH = 100;
1848
+ var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
1849
+ var getDataType = (column, tableSchema) => {
1850
+ const schemaColumn = tableSchema == null ? void 0 : tableSchema.columns.find(
1851
+ ({ name }) => name === column.name
1852
+ );
1853
+ if (schemaColumn) {
1854
+ return schemaColumn.serverDataType;
1855
+ } else {
1856
+ return column.serverDataType;
1857
+ }
1858
+ };
1859
+ var numericTypes = ["int", "long", "double"];
1860
+ var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
1861
+ var isShowColumnSettings = (action) => action.type === "columnSettings";
1862
+ var isShowTableSettings = (action) => action.type === "tableSettings";
1863
+ var columnReducer = (state, action) => {
1864
+ info == null ? void 0 : info(`TableModelReducer ${action.type}`);
1865
+ switch (action.type) {
1866
+ case "init":
1867
+ return init(action);
1868
+ case "moveColumn":
1869
+ return moveColumn(state, action);
1870
+ case "resizeColumn":
1871
+ return resizeColumn(state, action);
1872
+ case "setTableSchema":
1873
+ return setTableSchema(state, action);
1874
+ case "hideColumns":
1875
+ return hideColumns(state, action);
1876
+ case "showColumns":
1877
+ return showColumns(state, action);
1878
+ case "pinColumn":
1879
+ return pinColumn2(state, action);
1880
+ case "updateColumnProp":
1881
+ return updateColumnProp(state, action);
1882
+ case "tableConfig":
1883
+ return updateTableConfig2(state, action);
1884
+ default:
1885
+ console.log(`unhandled action ${action.type}`);
1886
+ return state;
1887
+ }
1888
+ };
1889
+ var useTableModel = (tableConfigProp, dataSource) => {
1890
+ const [state, dispatchTableModelAction] = (0, import_react20.useReducer)(columnReducer, { tableConfig: tableConfigProp, dataSource }, init);
1891
+ const { columns, headings, tableConfig, ...tableAttributes } = state;
1892
+ return {
1893
+ columns,
1894
+ dispatchTableModelAction,
1895
+ headings,
1896
+ tableAttributes,
1897
+ tableConfig
1898
+ };
1899
+ };
1900
+ function init({ dataSource, tableConfig }) {
1901
+ const { columns, ...tableAttributes } = tableConfig;
1902
+ const { config: dataSourceConfig, tableSchema } = dataSource;
1903
+ const runtimeColumns = columns.filter((0, import_vuu_utils17.subscribedOnly)(dataSourceConfig == null ? void 0 : dataSourceConfig.columns)).map(
1904
+ columnDescriptorToRuntimeColumDescriptor(tableAttributes, tableSchema)
1905
+ );
1906
+ const maybePinnedColumns = runtimeColumns.some(import_vuu_utils17.isPinned) ? (0, import_vuu_utils17.sortPinnedColumns)(runtimeColumns) : runtimeColumns;
1907
+ let state = {
1908
+ columns: maybePinnedColumns,
1909
+ headings: (0, import_vuu_utils17.getTableHeadings)(maybePinnedColumns),
1910
+ tableConfig,
1911
+ ...tableAttributes
1912
+ };
1913
+ if (dataSourceConfig) {
1914
+ const { columns: _, ...rest } = dataSourceConfig;
1915
+ state = updateTableConfig2(state, {
1916
+ type: "tableConfig",
1917
+ ...rest
1918
+ });
1919
+ }
1920
+ return state;
1921
+ }
1922
+ var getLabel = (label, columnFormatHeader) => {
1923
+ if (columnFormatHeader === "uppercase") {
1924
+ return label.toUpperCase();
1925
+ } else if (columnFormatHeader === "capitalize") {
1926
+ return label[0].toUpperCase() + label.slice(1).toLowerCase();
1927
+ }
1928
+ return label;
1929
+ };
1930
+ var columnDescriptorToRuntimeColumDescriptor = (tableAttributes, tableSchema) => (column, index) => {
1931
+ const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = tableAttributes;
1932
+ const serverDataType = getDataType(column, tableSchema);
1933
+ const {
1934
+ align = getDefaultAlignment(serverDataType),
1935
+ name,
1936
+ label = (0, import_vuu_utils17.getColumnLabel)(column),
1937
+ width = columnDefaultWidth,
1938
+ ...rest
1939
+ } = column;
1940
+ const runtimeColumnWithDefaults = {
1941
+ ...rest,
1942
+ align,
1943
+ CellRenderer: (0, import_vuu_utils17.getCellRenderer)(column),
1944
+ HeaderCellContentRenderer: (0, import_vuu_utils17.getColumnHeaderContentRenderer)(column),
1945
+ HeaderCellLabelRenderer: (0, import_vuu_utils17.getColumnHeaderLabelRenderer)(column),
1946
+ clientSideEditValidationCheck: (0, import_vuu_utils17.hasValidationRules)(column.type) ? (0, import_vuu_ui_controls3.buildValidationChecker)(column.type.renderer.rules) : void 0,
1947
+ index: index + 1,
1948
+ label: getLabel(label, columnFormatHeader),
1949
+ name,
1950
+ originalIdx: index,
1951
+ serverDataType,
1952
+ valueFormatter: (0, import_vuu_utils17.getValueFormatter)(column, serverDataType),
1953
+ width
1954
+ };
1955
+ if ((0, import_vuu_utils17.isGroupColumn)(runtimeColumnWithDefaults)) {
1956
+ runtimeColumnWithDefaults.columns = runtimeColumnWithDefaults.columns.map(
1957
+ (col) => columnDescriptorToRuntimeColumDescriptor(tableAttributes)(col, index)
1958
+ );
1959
+ }
1960
+ return runtimeColumnWithDefaults;
1961
+ };
1962
+ function moveColumn(state, { column, moveBy }) {
1963
+ const { columns } = state;
1964
+ if (typeof moveBy === "number") {
1965
+ const idx = columns.indexOf(column);
1966
+ const newColumns = columns.slice();
1967
+ const [movedColumns] = newColumns.splice(idx, 1);
1968
+ newColumns.splice(idx + moveBy, 0, movedColumns);
1969
+ return {
1970
+ ...state,
1971
+ columns: newColumns
1972
+ };
1973
+ }
1974
+ return state;
1975
+ }
1976
+ function hideColumns(state, { columns }) {
1977
+ if (columns.some((col) => col.hidden !== true)) {
1978
+ return columns.reduce((s, c) => {
1979
+ if (c.hidden !== true) {
1980
+ return updateColumnProp(s, {
1981
+ type: "updateColumnProp",
1982
+ column: c,
1983
+ hidden: true
1984
+ });
1985
+ } else {
1986
+ return s;
1987
+ }
1988
+ }, state);
1989
+ } else {
1990
+ return state;
1991
+ }
1992
+ }
1993
+ function showColumns(state, { columns }) {
1994
+ if (columns.some((col) => col.hidden)) {
1995
+ return columns.reduce((s, c) => {
1996
+ if (c.hidden) {
1997
+ return updateColumnProp(s, {
1998
+ type: "updateColumnProp",
1999
+ column: c,
2000
+ hidden: false
2001
+ });
2002
+ } else {
2003
+ return s;
2004
+ }
2005
+ }, state);
2006
+ } else {
2007
+ return state;
2008
+ }
2009
+ }
2010
+ function resizeColumn(state, { column, phase, width }) {
2011
+ const type = "updateColumnProp";
2012
+ const resizing = phase !== "end";
2013
+ switch (phase) {
2014
+ case "begin":
2015
+ return updateColumnProp(state, { type, column, resizing });
2016
+ case "end":
2017
+ return updateColumnProp(state, { type, column, resizing, width });
2018
+ case "resize":
2019
+ return updateColumnProp(state, { type, column, width });
2020
+ default:
2021
+ throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
2022
+ }
2023
+ }
2024
+ function setTableSchema(state, { tableSchema }) {
2025
+ const { columns } = state;
2026
+ if (columns.some(columnWithoutDataType)) {
2027
+ const cols = columns.map((column) => {
2028
+ var _a;
2029
+ const serverDataType = getDataType(column, tableSchema);
2030
+ return {
2031
+ ...column,
2032
+ align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
2033
+ serverDataType
2034
+ };
2035
+ });
2036
+ return {
2037
+ ...state,
2038
+ columns: cols
2039
+ };
2040
+ } else {
2041
+ return state;
2042
+ }
2043
+ }
2044
+ function pinColumn2(state, action) {
2045
+ let { columns } = state;
2046
+ const { column, pin } = action;
2047
+ const targetColumn = columns.find((col) => col.name === column.name);
2048
+ if (targetColumn) {
2049
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, pin });
2050
+ columns = (0, import_vuu_utils17.sortPinnedColumns)(columns);
2051
+ return {
2052
+ ...state,
2053
+ columns
2054
+ };
2055
+ } else {
2056
+ return state;
2057
+ }
2058
+ }
2059
+ function updateColumnProp(state, action) {
2060
+ let { columns, tableConfig } = state;
2061
+ const { align, column, hidden, label, resizing, width } = action;
2062
+ const targetColumn = columns.find((col) => col.name === column.name);
2063
+ if (targetColumn) {
2064
+ if (align === "left" || align === "right") {
2065
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, align });
2066
+ }
2067
+ if (typeof label === "string") {
2068
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, label });
2069
+ }
2070
+ if (typeof resizing === "boolean") {
2071
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, resizing });
2072
+ }
2073
+ if (typeof hidden === "boolean") {
2074
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, hidden });
2075
+ }
2076
+ if (typeof width === "number") {
2077
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, width });
2078
+ const targetConfigColumn = tableConfig.columns.find(
2079
+ (col) => col.name === column.name
2080
+ );
2081
+ if (targetConfigColumn) {
2082
+ tableConfig = {
2083
+ ...tableConfig,
2084
+ columns: (0, import_vuu_utils17.replaceColumn)(tableConfig.columns, {
2085
+ ...targetConfigColumn,
2086
+ width
2087
+ })
2088
+ };
2089
+ }
2090
+ }
2091
+ }
2092
+ return {
2093
+ ...state,
2094
+ columns,
2095
+ tableConfig
2096
+ };
2097
+ }
2098
+ function updateTableConfig2(state, { confirmed, filter, groupBy, sort }) {
2099
+ const hasGroupBy = groupBy !== void 0;
2100
+ const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
2101
+ const hasSort = sort && sort.sortDefs.length > 0;
2102
+ let result = state;
2103
+ if (hasGroupBy) {
2104
+ result = {
2105
+ ...state,
2106
+ columns: (0, import_vuu_utils17.applyGroupByToColumns)(result.columns, groupBy, confirmed)
2107
+ };
2108
+ }
2109
+ if (hasSort) {
2110
+ result = {
2111
+ ...state,
2112
+ columns: (0, import_vuu_utils17.applySortToColumns)(result.columns, sort)
2113
+ };
2114
+ }
2115
+ if (hasFilter) {
2116
+ result = {
2117
+ ...state,
2118
+ columns: (0, import_vuu_utils17.applyFilterToColumns)(result.columns, filter)
2119
+ };
2120
+ } else if (result.columns.some(import_vuu_utils17.isFilteredColumn)) {
2121
+ result = {
2122
+ ...state,
2123
+ columns: (0, import_vuu_utils17.stripFilterFromColumns)(result.columns)
2124
+ };
2125
+ }
2126
+ return result;
2127
+ }
2128
+
2129
+ // src/useTableScroll.ts
2130
+ var import_vuu_utils18 = require("@vuu-ui/vuu-utils");
2131
+ var import_react21 = require("react");
2132
+ var SCROLL_MOVE_CHECK_THRESHOLD = 100;
2133
+ var HORIZONTAL_SCROLL_BUFFER = 200;
2134
+ var getMaxScroll = (container) => {
2135
+ const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
2136
+ return [scrollWidth - clientWidth, scrollHeight - clientHeight];
2137
+ };
2138
+ var getScrollDirection = (prevScrollPositions, scrollPos) => {
2139
+ if (prevScrollPositions === void 0) {
2140
+ return void 0;
2141
+ } else {
2142
+ const { scrollTop: prevTop } = prevScrollPositions;
2143
+ return scrollPos > prevTop ? "fwd" : "bwd";
2144
+ }
2145
+ };
2146
+ var getPctScroll = (container, currentScrollPos) => {
2147
+ const {
2148
+ clientHeight,
2149
+ clientWidth,
2150
+ scrollHeight,
2151
+ scrollLeft,
2152
+ scrollTop,
2153
+ scrollWidth
2154
+ } = container;
2155
+ const maxScrollLeft = scrollWidth - clientWidth;
2156
+ const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
2157
+ const maxScrollTop = scrollHeight - clientHeight;
2158
+ let pctScrollTop = scrollTop / (scrollHeight - clientHeight);
2159
+ const scrollDirection = getScrollDirection(currentScrollPos, scrollTop);
2160
+ if (scrollDirection === "fwd" && pctScrollTop > 0.99) {
2161
+ pctScrollTop = 1;
2162
+ } else if (scrollDirection === "bwd" && pctScrollTop < 0.02) {
2163
+ pctScrollTop = 0;
2164
+ }
2165
+ return [
2166
+ scrollLeft,
2167
+ pctScrollLeft,
2168
+ maxScrollLeft,
2169
+ scrollTop,
2170
+ pctScrollTop,
2171
+ maxScrollTop
2172
+ ];
2173
+ };
2174
+ var noScrolling = {
2175
+ scrollToIndex: () => void 0,
2176
+ scrollToKey: () => void 0
2177
+ };
2178
+ var useCallbackRef = ({
2179
+ onAttach,
2180
+ onDetach
2181
+ }) => {
2182
+ const ref = (0, import_react21.useRef)(null);
2183
+ const callbackRef = (0, import_react21.useCallback)(
2184
+ (el) => {
2185
+ if (el) {
2186
+ ref.current = el;
2187
+ onAttach == null ? void 0 : onAttach(el);
2188
+ } else if (ref.current) {
2189
+ const { current: originalRef } = ref;
2190
+ ref.current = el;
2191
+ onDetach == null ? void 0 : onDetach(originalRef);
2192
+ }
2193
+ },
2194
+ [onAttach, onDetach]
2195
+ );
2196
+ return callbackRef;
2197
+ };
2198
+ var useTableScroll = ({
2199
+ columns,
2200
+ getRowAtPosition,
2201
+ onHorizontalScroll,
2202
+ onVerticalScroll,
2203
+ onVerticalScrollInSitu,
2204
+ rowHeight,
2205
+ scrollingApiRef,
2206
+ setRange,
2207
+ viewportMeasurements
2208
+ }) => {
2209
+ const firstRowRef = (0, import_react21.useRef)(0);
2210
+ const rowHeightRef = (0, import_react21.useRef)(rowHeight);
2211
+ const contentContainerScrolledRef = (0, import_react21.useRef)(false);
2212
+ const contentContainerPosRef = (0, import_react21.useRef)({
2213
+ scrollTop: 0,
2214
+ scrollLeft: 0
2215
+ });
2216
+ const scrollbarContainerScrolledRef = (0, import_react21.useRef)(false);
2217
+ const scrollbarContainerPosRef = (0, import_react21.useRef)({
2218
+ scrollTop: 0,
2219
+ scrollLeft: 0
2220
+ });
2221
+ const scrollbarContainerRef = (0, import_react21.useRef)(null);
2222
+ const contentContainerRef = (0, import_react21.useRef)(null);
2223
+ const lastHorizontalScrollCheckPoint = (0, import_react21.useRef)(0);
2224
+ const {
2225
+ appliedPageSize,
2226
+ isVirtualScroll,
2227
+ rowCount: viewportRowCount,
2228
+ totalHeaderHeight,
2229
+ viewportWidth
2230
+ } = viewportMeasurements;
2231
+ const columnsWithinViewportRef = (0, import_react21.useRef)([]);
2232
+ const [, forceRefresh] = (0, import_react21.useState)({});
2233
+ const preSpanRef = (0, import_react21.useRef)(0);
2234
+ (0, import_react21.useMemo)(() => {
2235
+ const [visibleColumns, offset] = (0, import_vuu_utils18.getColumnsInViewport)(
2236
+ columns,
2237
+ contentContainerPosRef.current.scrollLeft,
2238
+ contentContainerPosRef.current.scrollLeft + viewportWidth + HORIZONTAL_SCROLL_BUFFER
2239
+ );
2240
+ preSpanRef.current = offset;
2241
+ columnsWithinViewportRef.current = visibleColumns;
2242
+ }, [viewportWidth, columns]);
2243
+ const handleHorizontalScroll = (0, import_react21.useCallback)(
2244
+ (scrollLeft) => {
2245
+ contentContainerPosRef.current.scrollLeft = scrollLeft;
2246
+ onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
2247
+ if (Math.abs(scrollLeft - lastHorizontalScrollCheckPoint.current) > SCROLL_MOVE_CHECK_THRESHOLD) {
2248
+ lastHorizontalScrollCheckPoint.current = scrollLeft;
2249
+ const [visibleColumns, pre] = (0, import_vuu_utils18.getColumnsInViewport)(
2250
+ columns,
2251
+ scrollLeft,
2252
+ scrollLeft + viewportWidth + HORIZONTAL_SCROLL_BUFFER
2253
+ );
2254
+ if ((0, import_vuu_utils18.itemsChanged)(columnsWithinViewportRef.current, visibleColumns)) {
2255
+ preSpanRef.current = pre;
2256
+ columnsWithinViewportRef.current = visibleColumns;
2257
+ forceRefresh({});
2258
+ }
2259
+ }
2260
+ },
2261
+ [columns, onHorizontalScroll, viewportWidth]
2262
+ );
2263
+ const handleVerticalScroll = (0, import_react21.useCallback)(
2264
+ (scrollTop, pctScrollTop) => {
2265
+ contentContainerPosRef.current.scrollTop = scrollTop;
2266
+ onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop, pctScrollTop);
2267
+ const firstRow = getRowAtPosition(scrollTop);
2268
+ if (firstRow !== firstRowRef.current) {
2269
+ firstRowRef.current = firstRow;
2270
+ setRange({ from: firstRow, to: firstRow + viewportRowCount });
2271
+ }
2272
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(0);
2273
+ },
2274
+ [
2275
+ getRowAtPosition,
2276
+ onVerticalScroll,
2277
+ onVerticalScrollInSitu,
2278
+ setRange,
2279
+ viewportRowCount
2280
+ ]
2281
+ );
2282
+ const handleScrollbarContainerScroll = (0, import_react21.useCallback)(() => {
2283
+ const { current: contentContainer } = contentContainerRef;
2284
+ const { current: scrollbarContainer } = scrollbarContainerRef;
2285
+ const { current: contentContainerScrolled } = contentContainerScrolledRef;
2286
+ const { current: scrollPos } = scrollbarContainerPosRef;
2287
+ if (contentContainerScrolled) {
2288
+ contentContainerScrolledRef.current = false;
2289
+ } else if (contentContainer && scrollbarContainer) {
2290
+ scrollbarContainerScrolledRef.current = true;
2291
+ const [scrollLeft, pctScrollLeft, , scrollTop, pctScrollTop] = getPctScroll(scrollbarContainer, scrollPos);
2292
+ scrollPos.scrollLeft = scrollLeft;
2293
+ scrollPos.scrollTop = scrollTop;
2294
+ const [maxScrollLeft, maxScrollTop] = getMaxScroll(scrollbarContainer);
2295
+ const contentScrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
2296
+ const contentScrollTop = pctScrollTop * maxScrollTop;
2297
+ contentContainer.scrollTo({
2298
+ left: contentScrollLeft,
2299
+ top: contentScrollTop,
2300
+ behavior: "auto"
2301
+ });
2302
+ }
2303
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(0);
2304
+ }, [onVerticalScrollInSitu]);
2305
+ const handleContentContainerScroll = (0, import_react21.useCallback)(() => {
2306
+ const { current: scrollbarContainerScrolled } = scrollbarContainerScrolledRef;
2307
+ const { current: contentContainer } = contentContainerRef;
2308
+ const { current: scrollbarContainer } = scrollbarContainerRef;
2309
+ const { current: scrollPos } = contentContainerPosRef;
2310
+ if (contentContainer && scrollbarContainer) {
2311
+ const [
2312
+ scrollLeft,
2313
+ pctScrollLeft,
2314
+ maxScrollLeft,
2315
+ scrollTop,
2316
+ pctScrollTop,
2317
+ maxScrollTop
2318
+ ] = getPctScroll(contentContainer);
2319
+ contentContainerScrolledRef.current = true;
2320
+ if (scrollbarContainerScrolled) {
2321
+ scrollbarContainerScrolledRef.current = false;
2322
+ } else {
2323
+ scrollbarContainer.scrollLeft = Math.round(
2324
+ pctScrollLeft * maxScrollLeft
2325
+ );
2326
+ scrollbarContainer.scrollTop = pctScrollTop * maxScrollTop;
2327
+ }
2328
+ if (scrollPos.scrollTop !== scrollTop) {
2329
+ handleVerticalScroll(scrollTop, pctScrollTop);
2330
+ }
2331
+ if (scrollPos.scrollLeft !== scrollLeft) {
2332
+ handleHorizontalScroll(scrollLeft);
2333
+ }
2334
+ }
2335
+ }, [handleVerticalScroll, handleHorizontalScroll]);
2336
+ const handleAttachScrollbarContainer = (0, import_react21.useCallback)(
2337
+ (el) => {
2338
+ scrollbarContainerRef.current = el;
2339
+ el.addEventListener("scroll", handleScrollbarContainerScroll, {
2340
+ passive: true
2341
+ });
2342
+ },
2343
+ [handleScrollbarContainerScroll]
2344
+ );
2345
+ const handleDetachScrollbarContainer = (0, import_react21.useCallback)(
2346
+ (el) => {
2347
+ scrollbarContainerRef.current = null;
2348
+ el.removeEventListener("scroll", handleScrollbarContainerScroll);
2349
+ },
2350
+ [handleScrollbarContainerScroll]
2351
+ );
2352
+ const handleAttachContentContainer = (0, import_react21.useCallback)(
2353
+ (el) => {
2354
+ contentContainerRef.current = el;
2355
+ el.addEventListener("scroll", handleContentContainerScroll, {
2356
+ passive: true
2357
+ });
2358
+ },
2359
+ [handleContentContainerScroll]
2360
+ );
2361
+ const handleDetachContentContainer = (0, import_react21.useCallback)(
2362
+ (el) => {
2363
+ contentContainerRef.current = null;
2364
+ el.removeEventListener("scroll", handleContentContainerScroll);
2365
+ },
2366
+ [handleContentContainerScroll]
2367
+ );
2368
+ const contentContainerCallbackRef = useCallbackRef({
2369
+ onAttach: handleAttachContentContainer,
2370
+ onDetach: handleDetachContentContainer
2371
+ });
2372
+ const scrollbarContainerCallbackRef = useCallbackRef({
2373
+ onAttach: handleAttachScrollbarContainer,
2374
+ onDetach: handleDetachScrollbarContainer
2375
+ });
2376
+ const requestScroll = (0, import_react21.useCallback)(
2377
+ (scrollRequest) => {
2378
+ const { current: contentContainer } = contentContainerRef;
2379
+ if (contentContainer) {
2380
+ const [maxScrollLeft, maxScrollTop] = getMaxScroll(contentContainer);
2381
+ const { scrollLeft, scrollTop } = contentContainer;
2382
+ contentContainerScrolledRef.current = false;
2383
+ if (scrollRequest.type === "scroll-row") {
2384
+ const activeRow = (0, import_vuu_utils18.getRowElementAtIndex)(
2385
+ contentContainer,
2386
+ scrollRequest.rowIndex
2387
+ );
2388
+ if (activeRow !== null) {
2389
+ const [direction, distance] = howFarIsRowOutsideViewport(
2390
+ activeRow,
2391
+ totalHeaderHeight
2392
+ );
2393
+ if (direction && distance) {
2394
+ if (isVirtualScroll) {
2395
+ const offset = direction === "down" ? 1 : -1;
2396
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(offset);
2397
+ const firstRow = firstRowRef.current + offset;
2398
+ firstRowRef.current = firstRow;
2399
+ setRange({
2400
+ from: firstRow,
2401
+ to: firstRow + viewportRowCount
2402
+ });
2403
+ } else {
2404
+ let newScrollLeft = scrollLeft;
2405
+ let newScrollTop = scrollTop;
2406
+ if (direction === "up" || direction === "down") {
2407
+ newScrollTop = Math.min(
2408
+ Math.max(0, scrollTop + distance),
2409
+ maxScrollTop
2410
+ );
2411
+ } else {
2412
+ newScrollLeft = Math.min(
2413
+ Math.max(0, scrollLeft + distance),
2414
+ maxScrollLeft
2415
+ );
2416
+ }
2417
+ contentContainer.scrollTo({
2418
+ top: newScrollTop,
2419
+ left: newScrollLeft,
2420
+ behavior: "smooth"
2421
+ });
2422
+ }
2423
+ }
2424
+ }
2425
+ } else if (scrollRequest.type === "scroll-page") {
2426
+ const { direction } = scrollRequest;
2427
+ if (isVirtualScroll) {
2428
+ const offset = direction === "down" ? viewportRowCount : -viewportRowCount;
2429
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(offset);
2430
+ const firstRow = firstRowRef.current + offset;
2431
+ firstRowRef.current = firstRow;
2432
+ setRange({ from: firstRow, to: firstRow + viewportRowCount });
2433
+ } else {
2434
+ const scrollBy = direction === "down" ? appliedPageSize : -appliedPageSize;
2435
+ const newScrollTop = Math.min(
2436
+ Math.max(0, scrollTop + scrollBy),
2437
+ maxScrollTop
2438
+ );
2439
+ contentContainer.scrollTo({
2440
+ top: newScrollTop,
2441
+ left: scrollLeft,
2442
+ behavior: "auto"
2443
+ });
2444
+ }
2445
+ } else if (scrollRequest.type === "scroll-end") {
2446
+ const { direction } = scrollRequest;
2447
+ const scrollTo = direction === "end" ? maxScrollTop : 0;
2448
+ contentContainer.scrollTo({
2449
+ top: scrollTo,
2450
+ left: contentContainer.scrollLeft,
2451
+ behavior: "auto"
2452
+ });
2453
+ }
2454
+ }
2455
+ },
2456
+ [
2457
+ appliedPageSize,
2458
+ isVirtualScroll,
2459
+ onVerticalScrollInSitu,
2460
+ setRange,
2461
+ totalHeaderHeight,
2462
+ viewportRowCount
2463
+ ]
2464
+ );
2465
+ const scrollHandles = (0, import_react21.useMemo)(
2466
+ // TODO not complete yet
2467
+ () => ({
2468
+ scrollToIndex: (rowIndex) => {
2469
+ if (scrollbarContainerRef.current) {
2470
+ const scrollPos = (rowIndex - 30) * 20;
2471
+ scrollbarContainerRef.current.scrollTop = scrollPos;
2472
+ }
2473
+ },
2474
+ scrollToKey: (rowKey) => {
2475
+ console.log(`scrollToKey ${rowKey}`);
2476
+ }
2477
+ }),
2478
+ []
2479
+ );
2480
+ (0, import_react21.useImperativeHandle)(
2481
+ scrollingApiRef,
2482
+ () => {
2483
+ if (scrollbarContainerRef.current) {
2484
+ return scrollHandles;
2485
+ } else {
2486
+ return noScrolling;
2487
+ }
2488
+ },
2489
+ [scrollHandles]
2490
+ );
2491
+ (0, import_react21.useEffect)(() => {
2492
+ if (rowHeight !== rowHeightRef.current) {
2493
+ rowHeightRef.current = rowHeight;
2494
+ if (contentContainerPosRef.current.scrollTop > 0) {
2495
+ if (contentContainerRef.current) {
2496
+ contentContainerRef.current.scrollTop = 0;
2497
+ }
2498
+ }
2499
+ } else {
2500
+ const { current: from } = firstRowRef;
2501
+ const rowRange = { from, to: from + viewportRowCount };
2502
+ setRange(rowRange);
2503
+ }
2504
+ }, [rowHeight, setRange, viewportRowCount]);
2505
+ return {
2506
+ columnsWithinViewport: columnsWithinViewportRef.current,
2507
+ /** Ref to be assigned to ScrollbarContainer */
2508
+ scrollbarContainerRef: scrollbarContainerCallbackRef,
2509
+ /** Ref to be assigned to ContentContainer */
2510
+ contentContainerRef: contentContainerCallbackRef,
2511
+ /** Scroll the table */
2512
+ requestScroll,
2513
+ /** number of leading columns not rendered because of virtualization */
2514
+ virtualColSpan: preSpanRef.current
2515
+ };
2516
+ };
2517
+
2518
+ // src/useTableViewport.ts
2519
+ var import_vuu_utils19 = require("@vuu-ui/vuu-utils");
2520
+ var import_react22 = require("react");
2521
+ var MAX_PIXEL_HEIGHT = 1e7;
2522
+ var UNMEASURED_VIEWPORT = {
2523
+ appliedPageSize: 0,
2524
+ contentHeight: 0,
2525
+ contentWidth: 0,
2526
+ getRowAtPosition: () => -1,
2527
+ getRowOffset: () => -1,
2528
+ horizontalScrollbarHeight: 0,
2529
+ isVirtualScroll: false,
2530
+ pinnedWidthLeft: 0,
2531
+ pinnedWidthRight: 0,
2532
+ rowCount: 0,
2533
+ setInSituRowOffset: () => void 0,
2534
+ setScrollTop: () => void 0,
2535
+ totalHeaderHeight: 0,
2536
+ verticalScrollbarWidth: 0,
2537
+ viewportBodyHeight: 0,
2538
+ viewportWidth: 0
2539
+ };
2540
+ var useTableViewport = ({
2541
+ columns,
2542
+ headerHeight,
2543
+ headings,
2544
+ rowCount,
2545
+ rowHeight,
2546
+ selectionEndSize = 4,
2547
+ size
2548
+ }) => {
2549
+ const inSituRowOffsetRef = (0, import_react22.useRef)(0);
2550
+ const pctScrollTopRef = (0, import_react22.useRef)(0);
2551
+ const pixelContentHeight = Math.min(rowHeight * rowCount, MAX_PIXEL_HEIGHT);
2552
+ const virtualContentHeight = rowCount * rowHeight;
2553
+ const virtualisedExtent = virtualContentHeight - pixelContentHeight;
2554
+ const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = (0, import_react22.useMemo)(
2555
+ () => (0, import_vuu_utils19.measurePinnedColumns)(columns, selectionEndSize),
2556
+ [columns, selectionEndSize]
2557
+ );
2558
+ const totalHeaderHeightRef = (0, import_react22.useRef)(headerHeight);
2559
+ (0, import_react22.useMemo)(() => {
2560
+ totalHeaderHeightRef.current = headerHeight * (1 + headings.length);
2561
+ }, [headerHeight, headings.length]);
2562
+ const [getRowOffset, getRowAtPosition, isVirtualScroll] = (0, import_react22.useMemo)(() => {
2563
+ if (virtualisedExtent) {
2564
+ const [_getRowOffset, getRowAtPosition2, _isVirtual] = (0, import_vuu_utils19.virtualRowPositioning)(rowHeight, virtualisedExtent, pctScrollTopRef);
2565
+ const getOffset = (row) => {
2566
+ return _getRowOffset(row, inSituRowOffsetRef.current);
2567
+ };
2568
+ return [getOffset, getRowAtPosition2, _isVirtual];
2569
+ } else {
2570
+ return (0, import_vuu_utils19.actualRowPositioning)(rowHeight);
2571
+ }
2572
+ }, [virtualisedExtent, rowHeight]);
2573
+ const setScrollTop = (0, import_react22.useCallback)((_, scrollPct) => {
2574
+ pctScrollTopRef.current = scrollPct;
2575
+ }, []);
2576
+ const setInSituRowOffset = (0, import_react22.useCallback)((rowIndexOffset) => {
2577
+ if (rowIndexOffset === 0) {
2578
+ inSituRowOffsetRef.current = 0;
2579
+ } else {
2580
+ inSituRowOffsetRef.current = Math.max(
2581
+ 0,
2582
+ inSituRowOffsetRef.current + rowIndexOffset
2583
+ );
2584
+ }
2585
+ }, []);
2586
+ return (0, import_react22.useMemo)(() => {
2587
+ if (size) {
2588
+ const { current: totalHeaderHeight } = totalHeaderHeightRef;
2589
+ const scrollbarSize = 15;
2590
+ const contentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
2591
+ const horizontalScrollbarHeight = contentWidth > size.width ? scrollbarSize : 0;
2592
+ const visibleRows = (size.height - headerHeight) / rowHeight;
2593
+ const count = Number.isInteger(visibleRows) ? visibleRows : Math.ceil(visibleRows);
2594
+ const viewportBodyHeight = size.height - totalHeaderHeight;
2595
+ const verticalScrollbarWidth = pixelContentHeight > viewportBodyHeight ? scrollbarSize : 0;
2596
+ const appliedPageSize = count * rowHeight * (pixelContentHeight / virtualContentHeight);
2597
+ const viewportWidth = size.width;
2598
+ return {
2599
+ appliedPageSize,
2600
+ contentHeight: pixelContentHeight,
2601
+ contentWidth,
2602
+ getRowAtPosition,
2603
+ getRowOffset,
2604
+ isVirtualScroll,
2605
+ horizontalScrollbarHeight,
2606
+ pinnedWidthLeft,
2607
+ pinnedWidthRight,
2608
+ rowCount: count,
2609
+ setInSituRowOffset,
2610
+ setScrollTop,
2611
+ totalHeaderHeight,
2612
+ verticalScrollbarWidth,
2613
+ viewportBodyHeight,
2614
+ viewportWidth
2615
+ };
2616
+ } else {
2617
+ return UNMEASURED_VIEWPORT;
2618
+ }
2619
+ }, [
2620
+ getRowAtPosition,
2621
+ getRowOffset,
2622
+ headerHeight,
2623
+ isVirtualScroll,
2624
+ pinnedWidthLeft,
2625
+ unpinnedWidth,
2626
+ pinnedWidthRight,
2627
+ pixelContentHeight,
2628
+ rowHeight,
2629
+ setInSituRowOffset,
2630
+ setScrollTop,
2631
+ size,
2632
+ virtualContentHeight
2633
+ ]);
2634
+ };
2635
+
2636
+ // src/useTableAndColumnSettings.ts
2637
+ var import_vuu_layout = require("@vuu-ui/vuu-layout");
2638
+ var import_vuu_utils20 = require("@vuu-ui/vuu-utils");
2639
+ var import_react23 = require("react");
2640
+ var useTableAndColumnSettings = ({
2641
+ availableColumns: availableColumnsProps,
2642
+ onAvailableColumnsChange,
2643
+ onConfigChange,
2644
+ onCreateCalculatedColumn,
2645
+ onDataSourceConfigChange,
2646
+ tableConfig
2647
+ }) => {
2648
+ const dispatchLayoutAction = (0, import_vuu_layout.useLayoutProviderDispatch)();
2649
+ const showTableSettingsRef = (0, import_react23.useRef)();
2650
+ const [availableColumns, setAvailableColumns] = (0, import_react23.useState)(
2651
+ availableColumnsProps
2652
+ );
2653
+ const showContextPanel = (0, import_react23.useCallback)(
2654
+ (componentType, title, props) => {
2655
+ dispatchLayoutAction({
2656
+ type: "set-props",
2657
+ path: "#context-panel",
2658
+ props: {
2659
+ expanded: true,
2660
+ content: {
2661
+ type: componentType,
2662
+ props
2663
+ },
2664
+ title
2665
+ }
2666
+ });
2667
+ },
2668
+ [dispatchLayoutAction]
2669
+ );
2670
+ const handleCancelCreateColumn = (0, import_react23.useCallback)(() => {
2671
+ requestAnimationFrame(() => {
2672
+ var _a;
2673
+ (_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
2674
+ });
2675
+ }, []);
2676
+ const handleCreateCalculatedColumn = (0, import_react23.useCallback)(
2677
+ (column) => {
2678
+ const newAvailableColumns = availableColumns.concat({
2679
+ name: column.name,
2680
+ serverDataType: (0, import_vuu_utils20.getCalculatedColumnType)(column)
2681
+ });
2682
+ setAvailableColumns(newAvailableColumns);
2683
+ onAvailableColumnsChange == null ? void 0 : onAvailableColumnsChange(newAvailableColumns);
2684
+ requestAnimationFrame(() => {
2685
+ var _a;
2686
+ (_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
2687
+ });
2688
+ onCreateCalculatedColumn(column);
2689
+ },
2690
+ [availableColumns, onAvailableColumnsChange, onCreateCalculatedColumn]
2691
+ );
2692
+ const showColumnSettingsPanel = (0, import_react23.useCallback)(
2693
+ (action) => {
2694
+ showContextPanel("ColumnSettings", "Column Settings", {
2695
+ column: action.column,
2696
+ onCancelCreateColumn: handleCancelCreateColumn,
2697
+ onConfigChange,
2698
+ onCreateCalculatedColumn: handleCreateCalculatedColumn,
2699
+ tableConfig,
2700
+ vuuTable: action.vuuTable
2701
+ });
2702
+ },
2703
+ [
2704
+ handleCancelCreateColumn,
2705
+ handleCreateCalculatedColumn,
2706
+ onConfigChange,
2707
+ showContextPanel,
2708
+ tableConfig
2709
+ ]
2710
+ );
2711
+ const handleAddCalculatedColumn = (0, import_react23.useCallback)(() => {
2712
+ showColumnSettingsPanel({
2713
+ column: {
2714
+ name: "::",
2715
+ serverDataType: "string"
2716
+ },
2717
+ type: "columnSettings",
2718
+ vuuTable: { module: "SIMUL", table: "instruments" }
2719
+ });
2720
+ }, [showColumnSettingsPanel]);
2721
+ const handleNavigateToColumn = (0, import_react23.useCallback)(
2722
+ (columnName) => {
2723
+ const column = tableConfig.columns.find((c) => c.name === columnName);
2724
+ if (column) {
2725
+ showColumnSettingsPanel({
2726
+ type: "columnSettings",
2727
+ column,
2728
+ //TODO where do we get this from
2729
+ vuuTable: { module: "SIMUL", table: "instruments" }
2730
+ });
2731
+ }
2732
+ },
2733
+ [showColumnSettingsPanel, tableConfig.columns]
2734
+ );
2735
+ showTableSettingsRef.current = (0, import_react23.useCallback)(() => {
2736
+ showContextPanel("TableSettings", "DataGrid Settings", {
2737
+ availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType }) => ({
2738
+ name,
2739
+ serverDataType
2740
+ })),
2741
+ onAddCalculatedColumn: handleAddCalculatedColumn,
2742
+ onConfigChange,
2743
+ onDataSourceConfigChange,
2744
+ onNavigateToColumn: handleNavigateToColumn,
2745
+ tableConfig
2746
+ });
2747
+ }, [
2748
+ availableColumns,
2749
+ handleAddCalculatedColumn,
2750
+ handleNavigateToColumn,
2751
+ onConfigChange,
2752
+ onDataSourceConfigChange,
2753
+ showContextPanel,
2754
+ tableConfig
2755
+ ]);
2756
+ return {
2757
+ showColumnSettingsPanel,
2758
+ showTableSettingsPanel: showTableSettingsRef.current
2759
+ };
2760
+ };
2761
+
2762
+ // src/useRowClassNameGenerators.ts
2763
+ var import_vuu_utils21 = require("@vuu-ui/vuu-utils");
2764
+ var import_react24 = require("react");
2765
+ var createClassNameGenerator = (ids) => {
2766
+ const functions = [];
2767
+ ids == null ? void 0 : ids.forEach((id) => {
2768
+ const fn = (0, import_vuu_utils21.getRowClassNameGenerator)(id);
2769
+ if (fn) {
2770
+ functions.push(fn.fn);
2771
+ }
2772
+ });
2773
+ return (row, columnMap) => {
2774
+ const classNames = [];
2775
+ functions == null ? void 0 : functions.forEach((fn) => {
2776
+ const className = fn(row, columnMap);
2777
+ if (className) {
2778
+ classNames.push(className);
2779
+ }
2780
+ });
2781
+ return classNames.join(" ");
2782
+ };
2783
+ };
2784
+ var useRowClassNameGenerators = ({
2785
+ rowClassNameGenerators
2786
+ }) => {
2787
+ return (0, import_react24.useMemo)(() => {
2788
+ return createClassNameGenerator(rowClassNameGenerators);
2789
+ }, [rowClassNameGenerators]);
2790
+ };
2791
+
2792
+ // src/useTable.ts
2793
+ var stripInternalProperties = (tableConfig) => {
2794
+ return tableConfig;
2795
+ };
2796
+ var { KEY, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = import_vuu_utils22.metadataKeys;
2797
+ var NULL_DRAG_DROP = {
2798
+ draggable: void 0,
2799
+ onMouseDown: void 0
2800
+ };
2801
+ var useNullDragDrop = () => NULL_DRAG_DROP;
2802
+ var addColumn = (tableConfig, column) => ({
2803
+ ...tableConfig,
2804
+ columns: tableConfig.columns.concat(column)
2805
+ });
2806
+ var useTable = ({
2807
+ allowDragDrop = false,
2808
+ availableColumns,
2809
+ config,
2810
+ containerRef,
2811
+ dataSource,
2812
+ disableFocus,
2813
+ headerHeight = 25,
2814
+ highlightedIndex: highlightedIndexProp,
2815
+ id,
2816
+ navigationStyle = "cell",
2817
+ onAvailableColumnsChange,
2818
+ onConfigChange,
2819
+ onDragStart,
2820
+ onDrop,
2821
+ onFeatureInvocation,
2822
+ onHighlight,
2823
+ onRowClick: onRowClickProp,
2824
+ onSelect,
2825
+ onSelectionChange,
2826
+ renderBufferSize = 0,
2827
+ rowHeight = 20,
2828
+ scrollingApiRef,
2829
+ selectionModel,
2830
+ size
2831
+ }) => {
2832
+ const [rowCount, setRowCount] = (0, import_react25.useState)(dataSource.size);
2833
+ if (dataSource === void 0) {
2834
+ throw Error("no data source provided to Vuu Table");
2835
+ }
2836
+ const rowClassNameGenerator = useRowClassNameGenerators(config);
2837
+ const useRowDragDrop = allowDragDrop ? import_vuu_ui_controls4.useDragDrop : useNullDragDrop;
2838
+ const menuBuilder = (0, import_react25.useMemo)(
2839
+ () => buildContextMenuDescriptors(dataSource),
2840
+ [dataSource]
2841
+ );
2842
+ const onDataRowcountChange = (0, import_react25.useCallback)((size2) => {
2843
+ setRowCount(size2);
2844
+ }, []);
2845
+ const {
2846
+ columns,
2847
+ dispatchTableModelAction,
2848
+ headings,
2849
+ tableAttributes,
2850
+ tableConfig
2851
+ } = useTableModel(config, dataSource);
2852
+ (0, import_vuu_utils22.useLayoutEffectSkipFirst)(() => {
2853
+ dispatchTableModelAction({
2854
+ type: "init",
2855
+ tableConfig: config,
2856
+ dataSource
2857
+ });
2858
+ }, [config, dataSource, dispatchTableModelAction]);
2859
+ const applyTableConfigChange = (0, import_react25.useCallback)(
2860
+ (config2) => {
2861
+ dispatchTableModelAction({
2862
+ type: "init",
2863
+ tableConfig: config2,
2864
+ dataSource
2865
+ });
2866
+ onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(config2));
2867
+ },
2868
+ [dataSource, dispatchTableModelAction, onConfigChange]
2869
+ );
2870
+ const columnMap = (0, import_react25.useMemo)(
2871
+ () => (0, import_vuu_utils22.buildColumnMap)(dataSource.columns),
2872
+ [dataSource.columns]
2873
+ );
2874
+ const onSubscribed = (0, import_react25.useCallback)(
2875
+ ({ tableSchema }) => {
2876
+ if (tableSchema) {
2877
+ dispatchTableModelAction({
2878
+ type: "setTableSchema",
2879
+ tableSchema
2880
+ });
2881
+ } else {
2882
+ console.log("subscription message with no schema");
2883
+ }
2884
+ },
2885
+ [dispatchTableModelAction]
2886
+ );
2887
+ const {
2888
+ getRowAtPosition,
2889
+ getRowOffset,
2890
+ setInSituRowOffset: viewportHookSetInSituRowOffset,
2891
+ setScrollTop: viewportHookSetScrollTop,
2892
+ ...viewportMeasurements
2893
+ } = useTableViewport({
2894
+ columns,
2895
+ headerHeight,
2896
+ headings,
2897
+ rowCount,
2898
+ rowHeight,
2899
+ size
2900
+ });
2901
+ const initialRange = useInitialValue({
2902
+ from: 0,
2903
+ to: viewportMeasurements.rowCount
2904
+ });
2905
+ const { data, dataRef, getSelectedRows, range, setRange } = useDataSource({
2906
+ dataSource,
2907
+ // We need to factor this out of Table
2908
+ onFeatureInvocation,
2909
+ renderBufferSize,
2910
+ onSizeChange: onDataRowcountChange,
2911
+ onSubscribed,
2912
+ range: initialRange
2913
+ });
2914
+ const { requestScroll, ...scrollProps } = useTableScroll({
2915
+ columns,
2916
+ getRowAtPosition,
2917
+ rowHeight,
2918
+ scrollingApiRef,
2919
+ setRange,
2920
+ onVerticalScroll: viewportHookSetScrollTop,
2921
+ onVerticalScrollInSitu: viewportHookSetInSituRowOffset,
2922
+ viewportMeasurements
2923
+ });
2924
+ const handleConfigEditedInSettingsPanel = (0, import_react25.useCallback)(
2925
+ (tableConfig2) => {
2926
+ dispatchTableModelAction({
2927
+ type: "init",
2928
+ tableConfig: tableConfig2,
2929
+ dataSource
2930
+ });
2931
+ onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(tableConfig2));
2932
+ },
2933
+ [dataSource, dispatchTableModelAction, onConfigChange]
2934
+ );
2935
+ const handleDataSourceConfigChanged = (0, import_react25.useCallback)(
2936
+ (dataSourceConfig) => {
2937
+ dataSource.config = {
2938
+ ...dataSource.config,
2939
+ ...dataSourceConfig
2940
+ };
2941
+ },
2942
+ [dataSource]
2943
+ );
2944
+ (0, import_react25.useEffect)(() => {
2945
+ dataSource.on("config", (config2, confirmed, changes) => {
2946
+ const scrollSensitiveChanges = (changes == null ? void 0 : changes.filterChanged) || (changes == null ? void 0 : changes.groupByChanged);
2947
+ if (scrollSensitiveChanges && dataSource.range.from > 0) {
2948
+ requestScroll({
2949
+ type: "scroll-end",
2950
+ direction: "home"
2951
+ });
2952
+ }
2953
+ dispatchTableModelAction({
2954
+ type: "tableConfig",
2955
+ ...config2,
2956
+ confirmed
2957
+ });
2958
+ });
2959
+ }, [dataSource, dispatchTableModelAction, requestScroll]);
2960
+ const handleCreateCalculatedColumn = (0, import_react25.useCallback)(
2961
+ (column) => {
2962
+ dataSource.columns = dataSource.columns.concat(column.name);
2963
+ applyTableConfigChange(addColumn(tableConfig, column));
2964
+ },
2965
+ [dataSource, tableConfig, applyTableConfigChange]
2966
+ );
2967
+ const hideColumns2 = (0, import_react25.useCallback)(
2968
+ (action) => {
2969
+ const { columns: columns2 } = action;
2970
+ const hiddenColumns = columns2.map((c) => c.name);
2971
+ const newTableConfig = {
2972
+ ...tableConfig,
2973
+ columns: tableConfig.columns.map(
2974
+ (col) => hiddenColumns.includes(col.name) ? { ...col, hidden: true } : col
2975
+ )
2976
+ };
2977
+ applyTableConfigChange(newTableConfig);
2978
+ },
2979
+ [tableConfig, applyTableConfigChange]
2980
+ );
2981
+ const pinColumn3 = (0, import_react25.useCallback)(
2982
+ (action) => {
2983
+ applyTableConfigChange({
2984
+ ...tableConfig,
2985
+ columns: (0, import_vuu_utils22.updateColumn)(tableConfig.columns, {
2986
+ ...action.column,
2987
+ pin: action.pin
2988
+ })
2989
+ });
2990
+ },
2991
+ [tableConfig, applyTableConfigChange]
2992
+ );
2993
+ const { showColumnSettingsPanel, showTableSettingsPanel } = useTableAndColumnSettings({
2994
+ availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType = "string" }) => ({
2995
+ name,
2996
+ serverDataType
2997
+ })),
2998
+ onAvailableColumnsChange,
2999
+ onConfigChange: handleConfigEditedInSettingsPanel,
3000
+ onCreateCalculatedColumn: handleCreateCalculatedColumn,
3001
+ onDataSourceConfigChange: handleDataSourceConfigChanged,
3002
+ tableConfig
3003
+ });
3004
+ const onPersistentColumnOperation = (0, import_react25.useCallback)(
3005
+ (action) => {
3006
+ if (isShowColumnSettings(action)) {
3007
+ showColumnSettingsPanel(action);
3008
+ } else if (isShowTableSettings(action)) {
3009
+ showTableSettingsPanel();
3010
+ } else {
3011
+ switch (action.type) {
3012
+ case "hideColumns":
3013
+ return hideColumns2(action);
3014
+ case "pinColumn":
3015
+ return pinColumn3(action);
3016
+ default:
3017
+ dispatchTableModelAction(action);
3018
+ }
3019
+ }
3020
+ },
3021
+ [
3022
+ dispatchTableModelAction,
3023
+ hideColumns2,
3024
+ pinColumn3,
3025
+ showColumnSettingsPanel,
3026
+ showTableSettingsPanel
3027
+ ]
3028
+ );
3029
+ const handleContextMenuAction = useHandleTableContextMenu({
3030
+ dataSource,
3031
+ onPersistentColumnOperation
3032
+ });
3033
+ const handleSort = (0, import_react25.useCallback)(
3034
+ (column, extendSort = false, sortType) => {
3035
+ if (dataSource) {
3036
+ dataSource.sort = (0, import_vuu_utils22.applySort)(
3037
+ dataSource.sort,
3038
+ column,
3039
+ extendSort,
3040
+ sortType
3041
+ );
3042
+ }
3043
+ },
3044
+ [dataSource]
3045
+ );
3046
+ const resizeCells = (0, import_react25.useRef)();
3047
+ const onResizeColumn = (0, import_react25.useCallback)(
3048
+ (phase, columnName, width) => {
3049
+ var _a, _b, _c;
3050
+ const column = columns.find((column2) => column2.name === columnName);
3051
+ if (column) {
3052
+ if (phase === "resize") {
3053
+ (_a = resizeCells.current) == null ? void 0 : _a.forEach((cell) => {
3054
+ cell.style.width = `${width}px`;
3055
+ });
3056
+ } else if (phase === "end") {
3057
+ resizeCells.current = void 0;
3058
+ if ((0, import_vuu_utils22.isValidNumber)(width)) {
3059
+ dispatchTableModelAction({
3060
+ type: "resizeColumn",
3061
+ phase,
3062
+ column,
3063
+ width
3064
+ });
3065
+ onConfigChange == null ? void 0 : onConfigChange(
3066
+ stripInternalProperties(
3067
+ updateTableConfig(tableConfig, {
3068
+ type: "col-size",
3069
+ column,
3070
+ width
3071
+ })
3072
+ )
3073
+ );
3074
+ }
3075
+ } else {
3076
+ const byColIndex = `[aria-colindex='${column.index}']`;
3077
+ resizeCells.current = Array.from(
3078
+ (_c = (_b = containerRef.current) == null ? void 0 : _b.querySelectorAll(
3079
+ `.vuuTableCell${byColIndex},.vuuTableHeaderCell${byColIndex}`
3080
+ )) != null ? _c : []
3081
+ );
3082
+ dispatchTableModelAction({
3083
+ type: "resizeColumn",
3084
+ phase,
3085
+ column,
3086
+ width
3087
+ });
3088
+ }
3089
+ } else {
3090
+ throw Error(
3091
+ `useDataTable.handleColumnResize, column ${columnName} not found`
3092
+ );
3093
+ }
3094
+ },
3095
+ [
3096
+ columns,
3097
+ dispatchTableModelAction,
3098
+ onConfigChange,
3099
+ tableConfig,
3100
+ containerRef
3101
+ ]
3102
+ );
3103
+ const onToggleGroup = (0, import_react25.useCallback)(
3104
+ (row, column) => {
3105
+ var _a, _b;
3106
+ const isJson = (0, import_vuu_utils22.isJsonGroup)(column, row, columnMap);
3107
+ const key = row[KEY];
3108
+ if (row[IS_EXPANDED2]) {
3109
+ dataSource.closeTreeNode(key, true);
3110
+ if (isJson) {
3111
+ const idx = columns.indexOf(column);
3112
+ const rows = (_a = dataSource.getRowsAtDepth) == null ? void 0 : _a.call(dataSource, idx + 1);
3113
+ if (rows && !rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
3114
+ dispatchTableModelAction({
3115
+ type: "hideColumns",
3116
+ columns: columns.slice(idx + 2)
3117
+ });
3118
+ }
3119
+ }
3120
+ } else {
3121
+ dataSource.openTreeNode(key);
3122
+ if (isJson) {
3123
+ const childRows = (_b = dataSource.getChildRows) == null ? void 0 : _b.call(dataSource, key);
3124
+ const idx = columns.indexOf(column) + 1;
3125
+ const columnsToShow = [columns[idx]];
3126
+ if (childRows && childRows.some((row2) => row2[IS_LEAF2])) {
3127
+ columnsToShow.push(columns[idx + 1]);
3128
+ }
3129
+ if (columnsToShow.some((col) => col.hidden)) {
3130
+ dispatchTableModelAction({
3131
+ type: "showColumns",
3132
+ columns: columnsToShow
3133
+ });
3134
+ }
3135
+ }
3136
+ }
3137
+ },
3138
+ [columnMap, columns, dataSource, dispatchTableModelAction]
3139
+ );
3140
+ const {
3141
+ highlightedIndexRef,
3142
+ navigate,
3143
+ onFocus: navigationFocus,
3144
+ onKeyDown: navigationKeyDown,
3145
+ ...containerProps
3146
+ } = useKeyboardNavigation({
3147
+ columnCount: columns.filter((c) => c.hidden !== true).length,
3148
+ containerRef,
3149
+ disableFocus,
3150
+ highlightedIndex: highlightedIndexProp,
3151
+ navigationStyle,
3152
+ requestScroll,
3153
+ rowCount: dataSource == null ? void 0 : dataSource.size,
3154
+ onHighlight,
3155
+ viewportRange: range,
3156
+ viewportRowCount: viewportMeasurements.rowCount
3157
+ });
3158
+ const {
3159
+ onBlur: editingBlur,
3160
+ onDoubleClick: editingDoubleClick,
3161
+ onKeyDown: editingKeyDown,
3162
+ onFocus: editingFocus
3163
+ } = useCellEditing({
3164
+ navigate
3165
+ });
3166
+ const handleFocus = (0, import_react25.useCallback)(
3167
+ (e) => {
3168
+ navigationFocus();
3169
+ if (!e.defaultPrevented) {
3170
+ editingFocus(e);
3171
+ }
3172
+ },
3173
+ [editingFocus, navigationFocus]
3174
+ );
3175
+ const onContextMenu = useTableContextMenu({
3176
+ columns,
3177
+ data,
3178
+ dataSource,
3179
+ getSelectedRows
3180
+ });
3181
+ const onMoveGroupColumn = (0, import_react25.useCallback)(
3182
+ (columns2) => {
3183
+ dataSource.groupBy = columns2.map((col) => col.name);
3184
+ },
3185
+ [dataSource]
3186
+ );
3187
+ const onRemoveGroupColumn = (0, import_react25.useCallback)(
3188
+ (column) => {
3189
+ if ((0, import_vuu_utils22.isGroupColumn)(column)) {
3190
+ dataSource.groupBy = [];
3191
+ } else {
3192
+ if (dataSource && dataSource.groupBy.includes(column.name)) {
3193
+ dataSource.groupBy = dataSource.groupBy.filter(
3194
+ (columnName) => columnName !== column.name
3195
+ );
3196
+ }
3197
+ }
3198
+ },
3199
+ [dataSource]
3200
+ );
3201
+ const handleSelectionChange = (0, import_react25.useCallback)(
3202
+ (selected) => {
3203
+ dataSource.select(selected);
3204
+ onSelectionChange == null ? void 0 : onSelectionChange(selected);
3205
+ },
3206
+ [dataSource, onSelectionChange]
3207
+ );
3208
+ const {
3209
+ onKeyDown: selectionHookKeyDown,
3210
+ onRowClick: selectionHookOnRowClick
3211
+ } = useSelection({
3212
+ highlightedIndexRef,
3213
+ onSelect,
3214
+ onSelectionChange: handleSelectionChange,
3215
+ selectionModel
3216
+ });
3217
+ const handleKeyDown = (0, import_react25.useCallback)(
3218
+ (e) => {
3219
+ navigationKeyDown(e);
3220
+ if (!e.defaultPrevented) {
3221
+ editingKeyDown(e);
3222
+ }
3223
+ if (!e.defaultPrevented) {
3224
+ selectionHookKeyDown(e);
3225
+ }
3226
+ },
3227
+ [navigationKeyDown, editingKeyDown, selectionHookKeyDown]
3228
+ );
3229
+ const handleRowClick = (0, import_react25.useCallback)(
3230
+ (row, rangeSelect, keepExistingSelection) => {
3231
+ selectionHookOnRowClick(row, rangeSelect, keepExistingSelection);
3232
+ onRowClickProp == null ? void 0 : onRowClickProp(row);
3233
+ },
3234
+ [onRowClickProp, selectionHookOnRowClick]
3235
+ );
3236
+ const onMoveColumn = (0, import_react25.useCallback)(
3237
+ (columns2) => {
3238
+ const newTableConfig = {
3239
+ ...tableConfig,
3240
+ columns: columns2
3241
+ };
3242
+ dispatchTableModelAction({
3243
+ type: "init",
3244
+ tableConfig: newTableConfig,
3245
+ dataSource
3246
+ });
3247
+ onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(newTableConfig));
3248
+ },
3249
+ [dataSource, dispatchTableModelAction, onConfigChange, tableConfig]
3250
+ );
3251
+ const handleDropRow = (0, import_react25.useCallback)(
3252
+ (dragDropState) => {
3253
+ onDrop == null ? void 0 : onDrop(dragDropState);
3254
+ },
3255
+ [onDrop]
3256
+ );
3257
+ const handleDataEdited = (0, import_react25.useCallback)(
3258
+ async (row, columnName, value) => dataSource.applyEdit(row, columnName, value),
3259
+ [dataSource]
3260
+ );
3261
+ const handleDragStartRow = (0, import_react25.useCallback)(
3262
+ (dragDropState) => {
3263
+ const { initialDragElement } = dragDropState;
3264
+ const rowIndex = (0, import_vuu_utils22.getIndexFromRowElement)(initialDragElement);
3265
+ const row = dataRef.current.find((row2) => row2[0] === rowIndex);
3266
+ if (row) {
3267
+ dragDropState.setPayload(row);
3268
+ } else {
3269
+ }
3270
+ onDragStart == null ? void 0 : onDragStart(dragDropState);
3271
+ },
3272
+ [dataRef, onDragStart]
3273
+ );
3274
+ const { onMouseDown: rowDragMouseDown, draggable: draggableRow } = useRowDragDrop({
3275
+ allowDragDrop,
3276
+ containerRef,
3277
+ draggableClassName: `vuuTable`,
3278
+ id,
3279
+ onDragStart: handleDragStartRow,
3280
+ onDrop: handleDropRow,
3281
+ orientation: "vertical",
3282
+ itemQuery: ".vuuTableRow"
3283
+ });
3284
+ return {
3285
+ ...containerProps,
3286
+ "aria-rowcount": dataSource.size,
3287
+ rowClassNameGenerator,
3288
+ draggableRow,
3289
+ onBlur: editingBlur,
3290
+ onDoubleClick: editingDoubleClick,
3291
+ onFocus: handleFocus,
3292
+ onKeyDown: handleKeyDown,
3293
+ onMouseDown: rowDragMouseDown,
3294
+ columnMap,
3295
+ columns,
3296
+ data,
3297
+ getRowOffset,
3298
+ handleContextMenuAction,
3299
+ headings,
3300
+ highlightedIndex: highlightedIndexRef.current,
3301
+ menuBuilder,
3302
+ onContextMenu,
3303
+ onDataEdited: handleDataEdited,
3304
+ onMoveColumn,
3305
+ onMoveGroupColumn,
3306
+ onRemoveGroupColumn,
3307
+ onRowClick: handleRowClick,
3308
+ onSortColumn: handleSort,
3309
+ onResizeColumn,
3310
+ onToggleGroup,
3311
+ scrollProps,
3312
+ // TODO don't think we need these ...
3313
+ tableAttributes,
3314
+ tableConfig,
3315
+ viewportMeasurements
3316
+ };
3317
+ };
3318
+
3319
+ // src/useRowHeight.ts
3320
+ var import_vuu_utils23 = require("@vuu-ui/vuu-utils");
3321
+ var import_react26 = require("react");
3322
+ var useRowHeight = ({
3323
+ rowHeight: rowHeightProp = 0
3324
+ }) => {
3325
+ const [rowHeight, setRowHeight] = (0, import_react26.useState)(rowHeightProp);
3326
+ const heightRef = (0, import_react26.useRef)(rowHeight);
3327
+ const resizeObserver = (0, import_react26.useMemo)(() => {
3328
+ return new ResizeObserver((entries) => {
3329
+ for (const entry of entries) {
3330
+ const { height: measuredHeight } = entry.contentRect;
3331
+ const newHeight = Math.round(measuredHeight);
3332
+ if ((0, import_vuu_utils23.isValidNumber)(newHeight) && heightRef.current !== newHeight) {
3333
+ heightRef.current = newHeight;
3334
+ setRowHeight(newHeight);
3335
+ }
3336
+ }
3337
+ });
3338
+ }, []);
3339
+ const rowRef = (0, import_react26.useCallback)(
3340
+ (el) => {
3341
+ if (el) {
3342
+ if (rowHeightProp === 0) {
3343
+ const { height } = el.getBoundingClientRect();
3344
+ console.log(`measured rowHeight = ${height}`);
3345
+ resizeObserver.observe(el);
3346
+ setRowHeight(height);
3347
+ }
3348
+ } else {
3349
+ resizeObserver.disconnect();
3350
+ }
3351
+ },
3352
+ [resizeObserver, rowHeightProp]
3353
+ );
3354
+ return { rowHeight, rowRef };
3355
+ };
3356
+
3357
+ // src/Table.tsx
3358
+ var import_jsx_runtime12 = require("react/jsx-runtime");
3359
+ var classBase7 = "vuuTable";
3360
+ var { IDX: IDX3, RENDER_IDX } = import_vuu_utils24.metadataKeys;
3361
+ var TableCore = ({
3362
+ Row: Row2 = Row,
3363
+ allowDragDrop,
3364
+ availableColumns,
3365
+ config,
3366
+ containerRef,
3367
+ dataSource,
3368
+ disableFocus = false,
3369
+ highlightedIndex: highlightedIndexProp,
3370
+ id: idProp,
3371
+ navigationStyle = "cell",
3372
+ onAvailableColumnsChange,
3373
+ onConfigChange,
3374
+ onDragStart,
3375
+ onDrop,
3376
+ onFeatureInvocation,
3377
+ onHighlight,
3378
+ onRowClick: onRowClickProp,
3379
+ onSelect,
3380
+ onSelectionChange,
3381
+ renderBufferSize = 5,
3382
+ rowHeight,
3383
+ scrollingApiRef,
3384
+ selectionModel = "extended",
3385
+ showColumnHeaders = true,
3386
+ headerHeight = showColumnHeaders ? rowHeight * 1.25 : 0,
3387
+ size
3388
+ }) => {
3389
+ const id = (0, import_vuu_utils24.useId)(idProp);
3390
+ const {
3391
+ columnMap,
3392
+ columns,
3393
+ data,
3394
+ draggableRow,
3395
+ getRowOffset,
3396
+ handleContextMenuAction,
3397
+ headings,
3398
+ highlightedIndex,
3399
+ menuBuilder,
3400
+ onDataEdited,
3401
+ onMoveColumn,
3402
+ onMoveGroupColumn,
3403
+ onRemoveGroupColumn,
3404
+ onResizeColumn,
3405
+ onRowClick,
3406
+ onSortColumn,
3407
+ onToggleGroup,
3408
+ rowClassNameGenerator,
3409
+ scrollProps,
3410
+ tableAttributes,
3411
+ tableConfig,
3412
+ viewportMeasurements,
3413
+ ...tableProps
3414
+ } = useTable({
3415
+ allowDragDrop,
3416
+ availableColumns,
3417
+ config,
3418
+ containerRef,
3419
+ dataSource,
3420
+ disableFocus,
3421
+ headerHeight,
3422
+ highlightedIndex: highlightedIndexProp,
3423
+ id,
3424
+ navigationStyle,
3425
+ onAvailableColumnsChange,
3426
+ onConfigChange,
3427
+ onDragStart,
3428
+ onDrop,
3429
+ onFeatureInvocation,
3430
+ onHighlight,
3431
+ onRowClick: onRowClickProp,
3432
+ onSelect,
3433
+ onSelectionChange,
3434
+ renderBufferSize,
3435
+ rowHeight,
3436
+ scrollingApiRef,
3437
+ selectionModel,
3438
+ size
3439
+ });
3440
+ const contentContainerClassName = (0, import_clsx9.default)(`${classBase7}-contentContainer`, {
3441
+ [`${classBase7}-colLines`]: tableAttributes.columnSeparators,
3442
+ [`${classBase7}-rowLines`]: tableAttributes.rowSeparators,
3443
+ [`${classBase7}-zebra`]: tableAttributes.zebraStripes
3444
+ });
3445
+ const cssVariables = {
3446
+ "--content-height": `${viewportMeasurements.contentHeight}px`,
3447
+ "--content-width": `${viewportMeasurements.contentWidth}px`,
3448
+ "--horizontal-scrollbar-height": `${viewportMeasurements.horizontalScrollbarHeight}px`,
3449
+ "--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
3450
+ "--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
3451
+ "--header-height": `${headerHeight}px`,
3452
+ "--row-height-prop": `${rowHeight}px`,
3453
+ "--total-header-height": `${viewportMeasurements.totalHeaderHeight}px`,
3454
+ "--vertical-scrollbar-width": `${viewportMeasurements.verticalScrollbarWidth}px`,
3455
+ "--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
3456
+ };
3457
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3458
+ import_vuu_popups3.ContextMenuProvider,
3459
+ {
3460
+ menuActionHandler: handleContextMenuAction,
3461
+ menuBuilder,
3462
+ children: [
3463
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3464
+ "div",
3465
+ {
3466
+ className: `${classBase7}-scrollbarContainer`,
3467
+ ref: scrollProps.scrollbarContainerRef,
3468
+ style: cssVariables,
3469
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${classBase7}-scrollbarContent` })
3470
+ }
3471
+ ),
3472
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3473
+ "div",
3474
+ {
3475
+ className: contentContainerClassName,
3476
+ ref: scrollProps.contentContainerRef,
3477
+ style: cssVariables,
3478
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3479
+ "div",
3480
+ {
3481
+ ...tableProps,
3482
+ className: `${classBase7}-table`,
3483
+ role: "table",
3484
+ tabIndex: disableFocus ? void 0 : -1,
3485
+ children: [
3486
+ showColumnHeaders ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3487
+ TableHeader,
3488
+ {
3489
+ columns: scrollProps.columnsWithinViewport,
3490
+ headings,
3491
+ onMoveColumn,
3492
+ onMoveGroupColumn,
3493
+ onRemoveGroupColumn,
3494
+ onResizeColumn,
3495
+ onSortColumn,
3496
+ tableConfig,
3497
+ tableId: id,
3498
+ virtualColSpan: scrollProps.virtualColSpan
3499
+ }
3500
+ ) : null,
3501
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${classBase7}-body`, children: data.map((data2) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3502
+ Row2,
3503
+ {
3504
+ "aria-rowindex": data2[0] + 1,
3505
+ classNameGenerator: rowClassNameGenerator,
3506
+ columnMap,
3507
+ columns: scrollProps.columnsWithinViewport,
3508
+ highlighted: highlightedIndex === data2[IDX3],
3509
+ onClick: onRowClick,
3510
+ onDataEdited,
3511
+ row: data2,
3512
+ offset: getRowOffset(data2),
3513
+ onToggleGroup,
3514
+ virtualColSpan: scrollProps.virtualColSpan,
3515
+ zebraStripes: tableAttributes.zebraStripes
3516
+ },
3517
+ data2[RENDER_IDX]
3518
+ )) })
3519
+ ]
3520
+ }
3521
+ )
3522
+ }
3523
+ ),
3524
+ draggableRow
3525
+ ]
3526
+ }
3527
+ );
3528
+ };
3529
+ var Table = (0, import_react27.forwardRef)(function TableNext({
3530
+ Row: Row2,
3531
+ allowDragDrop,
3532
+ availableColumns,
3533
+ className: classNameProp,
3534
+ config,
3535
+ dataSource,
3536
+ disableFocus,
3537
+ highlightedIndex,
3538
+ id,
3539
+ navigationStyle,
3540
+ onAvailableColumnsChange,
3541
+ onConfigChange,
3542
+ onDragStart,
3543
+ onDrop,
3544
+ onFeatureInvocation,
3545
+ onHighlight,
3546
+ onRowClick,
3547
+ onSelect,
3548
+ onSelectionChange,
3549
+ renderBufferSize,
3550
+ rowHeight: rowHeightProp,
3551
+ scrollingApiRef,
3552
+ selectionModel,
3553
+ showColumnHeaders,
3554
+ headerHeight,
3555
+ style: styleProp,
3556
+ ...htmlAttributes
3557
+ }, forwardedRef) {
3558
+ const containerRef = (0, import_react27.useRef)(null);
3559
+ const [size, setSize] = (0, import_react27.useState)();
3560
+ const { rowHeight, rowRef } = useRowHeight({ rowHeight: rowHeightProp });
3561
+ if (config === void 0) {
3562
+ throw Error(
3563
+ "vuu Table requires config prop. Minimum config is list of Column Descriptors"
3564
+ );
3565
+ }
3566
+ if (dataSource === void 0) {
3567
+ throw Error("vuu Table requires dataSource prop");
3568
+ }
3569
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3570
+ import_vuu_ui_controls5.MeasuredContainer,
3571
+ {
3572
+ ...htmlAttributes,
3573
+ className: (0, import_clsx9.default)(classBase7, classNameProp),
3574
+ id,
3575
+ onResize: setSize,
3576
+ ref: (0, import_core2.useForkRef)(containerRef, forwardedRef),
3577
+ children: [
3578
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(RowProxy, { ref: rowRef, height: rowHeightProp }),
3579
+ size && rowHeight ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3580
+ TableCore,
3581
+ {
3582
+ Row: Row2,
3583
+ allowDragDrop,
3584
+ availableColumns,
3585
+ config,
3586
+ containerRef,
3587
+ dataSource,
3588
+ disableFocus,
3589
+ headerHeight,
3590
+ highlightedIndex,
3591
+ id,
3592
+ navigationStyle,
3593
+ onAvailableColumnsChange,
3594
+ onConfigChange,
3595
+ onDragStart,
3596
+ onDrop,
3597
+ onFeatureInvocation,
3598
+ onHighlight,
3599
+ onRowClick,
3600
+ onSelect,
3601
+ onSelectionChange,
3602
+ renderBufferSize,
3603
+ rowHeight,
3604
+ scrollingApiRef,
3605
+ selectionModel,
3606
+ showColumnHeaders,
3607
+ size
3608
+ }
3609
+ ) : null
3610
+ ]
3611
+ }
3612
+ );
3613
+ });
3614
+
3615
+ // src/cell-renderers/checkbox-cell/CheckboxCell.tsx
3616
+ var import_react28 = require("react");
3617
+ var import_vuu_ui_controls6 = require("@vuu-ui/vuu-ui-controls");
3618
+ var import_core3 = require("@salt-ds/core");
3619
+ var import_vuu_utils25 = require("@vuu-ui/vuu-utils");
3620
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3621
+ var CheckboxCell = (0, import_react28.memo)(
3622
+ ({ column, columnMap, onCommit = import_vuu_ui_controls6.WarnCommit, row }) => {
3623
+ const dataIdx = columnMap[column.name];
3624
+ const isChecked = !!row[dataIdx];
3625
+ const handleCommit = (0, import_react28.useCallback)(
3626
+ (value) => async (evt) => {
3627
+ const res = await onCommit(value);
3628
+ if (res === true) {
3629
+ (0, import_vuu_utils25.dispatchCustomEvent)(evt.target, "vuu-commit");
3630
+ }
3631
+ return res;
3632
+ },
3633
+ [onCommit]
3634
+ );
3635
+ return column.editable ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_core3.Checkbox, { checked: isChecked, onClick: handleCommit(!isChecked) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_vuu_ui_controls6.CheckboxIcon, { checked: isChecked, disabled: true });
3636
+ },
3637
+ import_vuu_utils25.dataColumnAndKeyUnchanged
3638
+ );
3639
+ CheckboxCell.displayName = "CheckboxCell";
3640
+ (0, import_vuu_utils25.registerComponent)("checkbox-cell", CheckboxCell, "cell-renderer", {
3641
+ serverDataType: "boolean"
3642
+ });
3643
+
3644
+ // src/cell-renderers/input-cell/InputCell.tsx
3645
+ var import_vuu_utils26 = require("@vuu-ui/vuu-utils");
3646
+ var import_core4 = require("@salt-ds/core");
3647
+ var import_vuu_ui_controls7 = require("@vuu-ui/vuu-ui-controls");
3648
+ var import_clsx10 = __toESM(require("clsx"));
3649
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3650
+ var classBase8 = "vuuTableInputCell";
3651
+ var WarnCommit2 = () => {
3652
+ console.warn(
3653
+ "onCommit handler has not been provided to InputCell cell renderer"
3654
+ );
3655
+ return Promise.resolve(true);
3656
+ };
3657
+ var InputCell = ({
3658
+ column,
3659
+ columnMap,
3660
+ onCommit = WarnCommit2,
3661
+ row
3662
+ }) => {
3663
+ const dataIdx = columnMap[column.name];
3664
+ const dataValue = row[dataIdx];
3665
+ const { align = "left", clientSideEditValidationCheck } = column;
3666
+ const { warningMessage, ...editProps } = (0, import_vuu_ui_controls7.useEditableText)({
3667
+ initialValue: dataValue,
3668
+ onCommit,
3669
+ clientSideEditValidationCheck
3670
+ });
3671
+ const endAdornment = warningMessage && align === "left" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `${classBase8}-icon`, "data-icon": "error" }) : void 0;
3672
+ const startAdornment = warningMessage && align === "right" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `${classBase8}-icon`, "data-icon": "error" }) : void 0;
3673
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3674
+ import_core4.Input,
3675
+ {
3676
+ ...editProps,
3677
+ className: (0, import_clsx10.default)(classBase8, {
3678
+ [`${classBase8}-error`]: warningMessage !== void 0
3679
+ }),
3680
+ endAdornment,
3681
+ startAdornment
3682
+ }
3683
+ );
3684
+ };
3685
+ (0, import_vuu_utils26.registerComponent)("input-cell", InputCell, "cell-renderer", {
3686
+ userCanAssign: false
3687
+ });
3688
+
3689
+ // src/cell-renderers/toggle-cell/ToggleCell.tsx
3690
+ var import_vuu_ui_controls8 = require("@vuu-ui/vuu-ui-controls");
3691
+ var import_vuu_utils27 = require("@vuu-ui/vuu-utils");
3692
+ var import_clsx11 = __toESM(require("clsx"));
3693
+ var import_react29 = require("react");
3694
+ var import_vuu_ui_controls9 = require("@vuu-ui/vuu-ui-controls");
3695
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3696
+ var classBase9 = "vuuTableToggleCell";
3697
+ var getValueList = ({ name, type }) => {
3698
+ if ((0, import_vuu_utils27.isTypeDescriptor)(type) && (0, import_vuu_utils27.isValueListRenderer)(type.renderer)) {
3699
+ return type.renderer.values;
3700
+ } else {
3701
+ throw Error(
3702
+ `useLookupValues column ${name} has not been configured with a values list`
3703
+ );
3704
+ }
3705
+ };
3706
+ var ToggleCell = (0, import_react29.memo)(
3707
+ function ToggleCell2({
3708
+ column,
3709
+ columnMap,
3710
+ onCommit = import_vuu_ui_controls8.WarnCommit,
3711
+ row
3712
+ }) {
3713
+ const values = getValueList(column);
3714
+ const dataIdx = columnMap[column.name];
3715
+ const value = row[dataIdx];
3716
+ const handleCommit = (0, import_react29.useCallback)(
3717
+ (evt, value2) => {
3718
+ return onCommit(value2).then((response) => {
3719
+ if (response === true) {
3720
+ (0, import_vuu_utils27.dispatchCustomEvent)(evt.target, "vuu-commit");
3721
+ }
3722
+ return response;
3723
+ });
3724
+ },
3725
+ [onCommit]
3726
+ );
3727
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3728
+ import_vuu_ui_controls9.CycleStateButton,
3729
+ {
3730
+ className: (0, import_clsx11.default)(classBase9, `${classBase9}-${column.name}`),
3731
+ onCommit: handleCommit,
3732
+ value,
3733
+ values,
3734
+ variant: "cta",
3735
+ children: value
3736
+ }
3737
+ );
3738
+ },
3739
+ import_vuu_utils27.dataColumnAndKeyUnchanged
3740
+ );
3741
+ (0, import_vuu_utils27.registerComponent)("toggle-cell", ToggleCell, "cell-renderer", {
3742
+ userCanAssign: false
3743
+ });
3744
+
3745
+ // src/useControlledTableNavigation.ts
3746
+ var import_vuu_ui_controls10 = require("@vuu-ui/vuu-ui-controls");
3747
+ var import_vuu_utils28 = require("@vuu-ui/vuu-utils");
3748
+ var import_react30 = require("react");
3749
+ var useControlledTableNavigation = (initialValue, rowCount) => {
3750
+ const tableRef = (0, import_react30.useRef)(null);
3751
+ const [highlightedIndexRef, setHighlightedIndex] = (0, import_vuu_ui_controls10.useStateRef)(initialValue);
3752
+ const handleKeyDown = (0, import_react30.useCallback)(
3753
+ (e) => {
3754
+ var _a;
3755
+ if (e.key === "ArrowDown") {
3756
+ setHighlightedIndex((index = -1) => Math.min(rowCount - 1, index + 1));
3757
+ } else if (e.key === "ArrowUp") {
3758
+ setHighlightedIndex((index = -1) => Math.max(0, index - 1));
3759
+ } else if (e.key === "Enter" || e.key === " ") {
3760
+ const { current: rowIdx } = highlightedIndexRef;
3761
+ const rowEl = (_a = tableRef.current) == null ? void 0 : _a.querySelector(
3762
+ `[aria-rowindex="${rowIdx}"]`
3763
+ );
3764
+ if (rowEl) {
3765
+ (0, import_vuu_utils28.dispatchMouseEvent)(rowEl, "click");
3766
+ }
3767
+ }
3768
+ },
3769
+ [highlightedIndexRef, rowCount, setHighlightedIndex]
3770
+ );
3771
+ const handleHighlight = (0, import_react30.useCallback)(
3772
+ (idx) => {
3773
+ setHighlightedIndex(idx);
3774
+ },
3775
+ [setHighlightedIndex]
3776
+ );
3777
+ return {
3778
+ highlightedIndexRef,
3779
+ onHighlight: handleHighlight,
3780
+ onKeyDown: handleKeyDown,
3781
+ tableRef
3782
+ };
3783
+ };
2
3784
  //# sourceMappingURL=index.js.map