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