@vuu-ui/vuu-table 0.8.25 → 0.8.26-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,3761 @@
1
- "use strict";var mr=Object.create;var Je=Object.defineProperty;var dr=Object.getOwnPropertyDescriptor;var pr=Object.getOwnPropertyNames;var br=Object.getPrototypeOf,fr=Object.prototype.hasOwnProperty;var gr=(e,o)=>{for(var t in o)Je(e,t,{get:o[t],enumerable:!0})},nt=(e,o,t,r)=>{if(o&&typeof o=="object"||typeof o=="function")for(let n of pr(o))!fr.call(e,n)&&n!==t&&Je(e,n,{get:()=>o[n],enumerable:!(r=dr(o,n))||r.enumerable});return e};var me=(e,o,t)=>(t=e!=null?mr(br(e)):{},nt(o||!e||!e.__esModule?Je(t,"default",{value:e,enumerable:!0}):t,e)),Cr=e=>nt(Je({},"__esModule",{value:!0}),e);var Tl={};gr(Tl,{CheckboxCell:()=>Uo,GroupHeaderCell:()=>qe,GroupHeaderCellNext:()=>qe,HeaderCell:()=>ho,InputCell:()=>Ln,Table:()=>vl,TableCell:()=>To,TableGroupCell:()=>yo,ToggleCell:()=>Fn,isShowColumnSettings:()=>Go,isShowTableSettings:()=>Ko,noScrolling:()=>mn,updateTableConfig:()=>Lo,useControlledTableNavigation:()=>xl,useTableModel:()=>Oo,useTableScroll:()=>$o,useTableViewport:()=>Bo});module.exports=Cr(Tl);var bt=require("@vuu-ui/vuu-ui-controls"),ft=require("@vuu-ui/vuu-utils"),gt=me(require("clsx")),Fe=require("react");var lt=me(require("clsx")),it=require("react");var Ze=require("react/jsx-runtime"),rt="vuuColumnHeaderPill",Ae=({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 a=(0,it.useCallback)(i=>{i.preventDefault(),i.stopPropagation(),r==null||r(t)},[t,r]);return(0,Ze.jsxs)("div",{...l,className:(0,lt.default)(rt,o),children:[e,n?(0,Ze.jsx)("span",{className:`${rt}-removeButton`,role:"button","data-icon":"cross",onClick:a}):null]})};var Ie=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,Ie.jsxs)(Ae,{...o,column:e,children:[(0,Ie.jsx)("span",{className:"vuuGroupColumnPill-label",children:t}),n!==void 0?(0,Ie.jsx)("span",{"data-icon":n}):null,typeof r=="number"?(0,Ie.jsx)("span",{className:"vuuSortPosition",children:Math.abs(r)}):null]})};var _e=require("react/jsx-runtime"),st=({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,_e.jsxs)(Ae,{column:e,children:[(0,_e.jsx)("span",{"data-icon":o}),typeof e.sorted=="number"?(0,_e.jsx)("span",{className:"vuuSortPosition",children:Math.abs(e.sorted)}):null]})};var ze=require("react");var ct=require("react/jsx-runtime"),ut=()=>{},vr="vuuColumnResizerNext",Ye=({onDrag:e,onDragEnd:o=ut,onDragStart:t=ut})=>{let r=(0,ze.useRef)({start:0,now:0}),n=(0,ze.useCallback)(i=>{i.stopPropagation&&i.stopPropagation(),i.preventDefault&&i.preventDefault();let{current:s}=r,u=Math.round(i.clientX),d=u-s.now,m=s.now-s.start;r.current.now=u,d!==0&&e(i,d,m)},[e]),l=(0,ze.useCallback)(i=>{window.removeEventListener("mouseup",l),window.removeEventListener("mousemove",n);let{current:s}=r,u=s.now-s.start;o(i,u)},[o,n]),a=(0,ze.useCallback)(i=>{let{current:s}=r;t(i),s.now=s.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,ct.jsx)("div",{className:vr,onMouseDown:a})};var we=require("react"),je=({column:e,onResize:o,rootRef:t})=>{let r=(0,we.useRef)({start:0,now:0}),[n,l]=(0,we.useState)(!1),{name:a}=e,i=(0,we.useCallback)(()=>{if(o&&t.current){let{current:d}=r,{width:m}=t.current.getBoundingClientRect();d.start=d.now=Math.round(m),l(!0),o==null||o("begin",a)}},[a,o,t]),s=(0,we.useCallback)((d,m,b)=>{if(t.current&&o){let{current:C}=r,h=C.start+b;h!==C.now&&h>0&&(o("resize",a,h),C.now=h)}},[a,o,t]),u=(0,we.useCallback)(()=>{if(o){let{current:d}=r;o("end",a,d.now),setTimeout(()=>{l(!1)},80)}},[a,o]);return{isResizing:n,onDrag:s,onDragStart:i,onDragEnd:u}};var mt=require("@vuu-ui/vuu-utils"),dt=me(require("clsx")),pt=require("react"),xe=(e,o,t)=>(0,pt.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,mt.getColumnStyle)(e);return{className:r,style:n}},[e,o,t]);var Ne=require("react/jsx-runtime"),Ct=require("react"),vo="vuuTableGroupHeaderCell",hr=(e,o)=>e===o?e:o,qe=({column:e,className:o,onMoveColumn:t,onRemoveColumn:r,onResize:n,...l})=>{let a=(0,Fe.useRef)(null),{isResizing:i,...s}=je({column:e,onResize:n,rootRef:a}),[u,d]=(0,Fe.useState)(e.columns),{className:m,style:b}=xe(e,vo,!0),C=u.length>1?{removable:!0,onRemove:r}:void 0,h=(0,Fe.useCallback)((x,c)=>{d(v=>{let T=v.slice(),[S]=T.splice(x,1);if(c===-1){let D=T.concat(S);return t==null||t(D),D}else return T.splice(c,0,S),t==null||t(T),T})},[t]);return(0,ft.useLayoutEffectSkipFirst)(()=>{d(x=>hr(x,e.columns))},[e.columns]),(0,Ne.jsxs)("div",{...l,className:(0,gt.default)(m,o,{[`${vo}-pending`]:e.groupConfirmed===!1}),ref:a,role:"columnheader",style:b,children:[(0,Ne.jsx)(bt.OverflowContainer,{allowDragDrop:!0,className:`${vo}-inner`,onMoveItem:h,overflowPosition:"start",children:u.map(x=>(0,Ct.createElement)(at,{...C,column:x,key:x.name}))}),(0,Ne.jsx)(Ae,{column:e,removable:!0,onRemove:r}),e.resizeable!==!1?(0,Ne.jsx)(Ye,{...s}):null]})};var Tt=me(require("clsx")),oo=require("react");var vt=require("@vuu-ui/vuu-popups"),ht=me(require("clsx"));var xt=require("react/jsx-runtime"),wr="vuuColumnMenu",wt=({className:e,column:o})=>(0,xt.jsx)(vt.PopupMenu,{className:(0,ht.default)(wr,e),"data-embedded":!0,menuLocation:"column-menu",menuOptions:{column:o}});var ge=require("react/jsx-runtime"),eo="vuuTableHeaderCell",ho=({className:e,column:o,onClick:t,onResize:r,...n})=>{var T;let{HeaderCellContentRenderer:l,HeaderCellLabelRenderer:a}=o,i=(0,oo.useRef)(null),{isResizing:s,...u}=je({column:o,onResize:r,rootRef:i}),d=(0,oo.useCallback)(S=>{!s&&(t==null||t(S))},[s,t]),{className:m,style:b}=xe(o,eo,!0),C=(0,ge.jsx)(wt,{column:o}),h=a?(0,ge.jsx)(a,{className:`${eo}-label`,column:o}):(0,ge.jsx)("div",{className:`${eo}-label`,children:(T=o.label)!=null?T:o.name}),x=l?[(0,ge.jsx)(l,{column:o},"content")]:[],c=(0,ge.jsx)(st,{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,Tt.default)(m,e,{[`${eo}-resizing`]:s}),onClick:d,ref:i,role:"columnheader",style:b,children:[...v,o.resizeable!==!1?(0,ge.jsx)(Ye,{...u}):null]})};var yn=require("@vuu-ui/vuu-popups"),Dn=require("@vuu-ui/vuu-ui-controls"),so=require("@vuu-ui/vuu-utils"),Hn=require("@salt-ds/core"),Vo=me(require("clsx")),Ve=require("react");var le=require("@vuu-ui/vuu-utils"),Do=me(require("clsx")),Pe=require("react");var Rt=require("@vuu-ui/vuu-utils"),wo=require("react");var xo=require("react/jsx-runtime"),xr="vuuTableCell",To=({column:e,columnMap:o,onClick:t,onDataEdited:r,row:n})=>{let{className:l,style:a}=xe(e,xr),{CellRenderer:i,index:s,name:u,valueFormatter:d}=e,m=o[u],b=(0,wo.useCallback)(h=>{if(r){let x=h;return(0,Rt.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,wo.useCallback)(h=>{t==null||t(h,e)},[e,t]);return(0,xo.jsx)("div",{"aria-colindex":s,className:l,onClick:t?C:void 0,role:"cell",style:a,children:i?(0,xo.jsx)(i,{column:e,columnMap:o,onCommit:b,row:n}):d(n[m])})};var to=require("@vuu-ui/vuu-utils"),yt=require("react");var Dt=me(require("clsx"));var Ge=require("react/jsx-runtime"),{IS_LEAF:Tr}=to.metadataKeys,Ro="vuuTableGroupCell",yo=({column:e,columnMap:o,onClick:t,row:r})=>{let{columns:n}=e,[l,a]=(0,to.getGroupValueAndOffset)(n,r,o),{className:i,style:s}=xe(e,Ro),u=(0,yt.useCallback)(b=>{t==null||t(b,e)},[e,t]),d=r[Tr],m=Array(a).fill(0).map((b,C)=>(0,Ge.jsx)("span",{className:`${Ro}-spacer`},C));return(0,Ge.jsxs)("div",{className:(0,Dt.default)(i,"vuuTableCell"),role:"cell",style:s,onClick:d?void 0:u,children:[m,d?null:(0,Ge.jsx)("span",{className:`${Ro}-toggle`,"data-icon":"triangle-right"}),(0,Ge.jsx)("span",{children:l})]})};var Te=require("react/jsx-runtime"),{IDX:Rr,IS_EXPANDED:yr,SELECTED:Dr}=le.metadataKeys,de="vuuTableRow",Ht=(0,Pe.forwardRef)(function({height:o},t){return(0,Te.jsx)("div",{"aria-hidden":!0,className:(0,Do.default)(de,`${de}-proxy`),ref:t,style:{height:o}})}),Ho=(0,Pe.memo)(({className:e,classNameGenerator:o,columnMap:t,columns:r,highlighted:n,row:l,offset:a,onClick:i,onDataEdited:s,onToggleGroup:u,virtualColSpan:d=0,zebraStripes:m=!1,...b})=>{let{[Rr]:C,[yr]:h,[Dr]:x}=l,c=(0,Pe.useCallback)(P=>{let z=P.shiftKey,G=P.ctrlKey||P.metaKey;i==null||i(P,l,z,G)},[i,l]),{True:v,First:T,Last:S}=le.RowSelected,D=(0,Do.default)(de,e,o==null?void 0:o(l,t),{[`${de}-even`]:m&&C%2===0,[`${de}-expanded`]:h,[`${de}-highlighted`]:n,[`${de}-selected`]:x&v,[`${de}-selectedStart`]:x&T,[`${de}-selectedEnd`]:x&S}),A={transform:`translate3d(0px, ${a}px, 0px)`},F=(0,Pe.useCallback)((P,z)=>{((0,le.isGroupColumn)(z)||(0,le.isJsonGroup)(z,l,t))&&(P.stopPropagation(),u==null||u(l,z))},[t,u,l]);return(0,Te.jsxs)("div",{...b,role:"row",className:D,onClick:c,style:A,children:[(0,Te.jsx)("span",{className:`${de}-selectionDecorator vuuStickyLeft`}),d>0?(0,Te.jsx)("div",{className:"vuuTableCell",style:{width:d}}):null,r.filter(le.isNotHidden).map(P=>{let z=(0,le.isGroupColumn)(P),G=(0,le.isJsonColumn)(P);return(0,Te.jsx)(z?yo:To,{column:P,columnMap:t,onClick:z||G?F:void 0,onDataEdited:s,row:l},P.name)}),(0,Te.jsx)("span",{className:`${de}-selectionDecorator vuuStickyRight`})]})});Ho.displayName="Row";var no=require("@vuu-ui/vuu-utils"),Et=me(require("clsx")),St=require("react");var Mt=require("@vuu-ui/vuu-ui-controls"),Ke=require("@vuu-ui/vuu-utils"),Ee=require("react"),Pt=({columns:e,onMoveColumn:o,onSortColumn:t,tableConfig:r})=>{let n=(0,Ee.useRef)(null),l=(0,Ee.useRef)(null),a=(0,Ee.useCallback)(b=>{n.current=b,b?l.current=b.closest(".vuuTable-contentContainer"):l.current=null},[]),i=(0,Ee.useCallback)(({fromIndex:b,toIndex:C})=>{let h=e[b],x=(0,Ke.moveColumnTo)(e,h,C),c=({name:D})=>A=>A.name===D,v=x.findIndex(c(h)),T=x[v+1],S=T?r.columns.findIndex(c(T)):-1;C>b&&S!==-1?o((0,Ke.moveColumnTo)(r.columns,h,S-1)):o((0,Ke.moveColumnTo)(r.columns,h,S))},[e,o,r.columns]),s=(0,Ee.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,Ke.visibleColumnAtIndex)(e,x),v=b.shiftKey;c&&t(c,v)},[e,t]),{onMouseDown:u,draggable:d,...m}=(0,Mt.useDragDrop)({allowDragDrop:!0,containerRef:n,draggableClassName:"vuuTable",itemQuery:".vuuTableHeaderCell",onDrop:i,orientation:"horizontal",scrollingContainerRef:l});return{draggableColumn:d,draggedColumnIndex:m.draggedItemIndex,onClick:s,onMouseDown:u,setContainerRef:a}};var Ce=require("react/jsx-runtime"),Mo=(0,St.memo)(({classBase:e="vuuTable",columns:o,headings:t,onMoveColumn:r,onMoveGroupColumn:n,onRemoveGroupColumn:l,onResizeColumn:a,onSortColumn:i,tableConfig:s,tableId:u,virtualColSpan:d=0})=>{let{draggableColumn:m,draggedColumnIndex:b,onClick:C,onMouseDown:h,setContainerRef:x}=Pt({columns:o,onMoveColumn:r,onSortColumn:i,tableConfig:s});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:S},D)=>(0,Ce.jsx)("div",{className:"vuuTable-headingCell",style:{width:S},children:T},D))},v)),(0,Ce.jsxs)("div",{className:`${e}-col-headers`,role:"row",children:[d>0?(0,Ce.jsx)("div",{role:"cell",className:"vuuTableCell",style:{width:d}}):null,o.filter(no.isNotHidden).map((c,v)=>(0,no.isGroupColumn)(c)?(0,Ce.jsx)(qe,{"aria-colindex":c.index,column:c,"data-index":v,onMoveColumn:n,onRemoveColumn:l,onResize:a},c.name):(0,Ce.jsx)(ho,{"aria-colindex":c.index,className:(0,Et.default)({"vuuDraggable-dragAway":v===b}),column:c,"data-index":v,id:`${u}-col-${v}`,onClick:C,onMouseDown:h,onResize:a},c.name)),m]})]})});Mo.displayName="TableHeader";var wn=require("@vuu-ui/vuu-ui-controls"),B=require("@vuu-ui/vuu-utils"),M=require("react");var kt=require("@vuu-ui/vuu-utils"),Lt=e=>(o,t)=>{let r=[];return e===void 0||(o==="header"||o==="column-menu")&&(r.push(...Hr(t,e)),r.push(...Er(t,e)),r.push(...Mr(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 Hr(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 Mr(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,kt.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 ko=(e,o)=>({label:`Pin ${o}`,action:`column-pin-${o}`,options:e}),Po=e=>ko(e,"left"),Eo=e=>ko(e,"floating"),So=e=>ko(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:[Po(e),Eo(e),So(e)]}):t==="left"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Eo(e),So(e)]}):t==="right"?r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Po(e),Eo(e)]}):t==="floating"&&r.push({label:"Unpin column",action:"column-unpin",options:e},{label:"Pin column",children:[Po(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 At=require("@vuu-ui/vuu-utils"),_=require("@vuu-ui/vuu-utils"),Sr=(e,o)=>{if(e.filterStruct&&o){let[t,r]=(0,At.removeColumnFromFilter)(o,e.filterStruct);return{filter:r,filterStruct:t}}else return e},{Average:kr,Count:Lr,Distinct:Ar,High:Ir,Low:zr,Sum:Nr}=_.AggregationType,It=({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,_.setSortColumn)(e.sort,l,"A"),!0;case"sort-dsc":return e.sort=(0,_.setSortColumn)(e.sort,l,"D"),!0;case"sort-add-asc":return e.sort=(0,_.addSortColumn)(e.sort,l,"A"),!0;case"sort-add-dsc":return e.sort=(0,_.addSortColumn)(e.sort,l,"D"),!0;case"group":return e.groupBy=(0,_.addGroupColumn)(e.groupBy,l),!0;case"group-add":return e.groupBy=(0,_.addGroupColumn)(e.groupBy,l),!0;case"column-hide":return o({type:"hideColumns",columns:[l]}),!0;case"column-remove":return e.columns=e.columns.filter(a=>a!==l.name),!0;case"filter-remove-column":return e.filter=Sr(e.filter,l),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=(0,_.setAggregations)(e.aggregations,l,kr),!0;case"agg-high":return e.aggregations=(0,_.setAggregations)(e.aggregations,l,Ir),!0;case"agg-low":return e.aggregations=(0,_.setAggregations)(e.aggregations,l,zr),!0;case"agg-count":return e.aggregations=(0,_.setAggregations)(e.aggregations,l,Lr),!0;case"agg-distinct":return e.aggregations=(0,_.setAggregations)(e.aggregations,l,Ar),!0;case"agg-sum":return e.aggregations=(0,_.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 Lo=(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 Kt=require("@vuu-ui/vuu-utils"),Re=require("react");var Ao=e=>`.vuuTable-col-headers .vuuTableHeaderCell:nth-child(${e})`,Io=(e,o)=>`.vuuTable-body > [aria-rowindex='${e+1}'] > [role='cell']:nth-child(${o+1})`,zt=(e,[o,t])=>{var l;let r=o===-1?Ao(t):Io(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"),Nt=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"]'),Ft=e=>Gr(Kr(e)),Or=[void 0,void 0],Gt=(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 Ot=({navigate:e})=>{let o=(0,Re.useCallback)(()=>{e()},[e]),t=(0,Re.useCallback)(s=>{let u=s.target,d=u.matches("input")?u:u.querySelector("input");d&&(d.focus(),d.select())},[]),r=(0,Re.useCallback)(s=>{let d=s.target.querySelector("input");d&&(d.focus(),d.select())},[]),n=(0,Re.useCallback)(s=>{let u=s.target;Nt(u)&&((0,Kt.isCharacterKey)(s.key)?t(s):s.key==="Enter"&&r(s))},[t,r]),l=(0,Re.useCallback)(s=>{let u=s.target;(u.matches("input")||u.querySelector("input"))&&(t(s),s.stopPropagation())},[t]),a=(0,Re.useCallback)(s=>{s.target.removeEventListener("vuu-commit",o,!0)},[o]),i=(0,Re.useCallback)(s=>{s.target.addEventListener("vuu-commit",o,!0)},[o]);return{onBlur:a,onDoubleClick:l,onFocus:i,onKeyDown:n}};var ye=require("@vuu-ui/vuu-utils"),Q=require("react");var Oe=require("@vuu-ui/vuu-utils"),{SELECTED:zo}=Oe.metadataKeys,ro=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 Oe.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[zo]){let n=this.data[r-1];(0,Oe.isRowSelectedLast)(n)&&(this.data[r-1]=n.slice(),this.data[r-1][zo]-=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 a=r;a<n;a++){let i=this.getAtIndex(a);if(i){let s=a-o;l[s]=i}}this.data=l,this.range.from=o,this.range.to=t}}getSelectedRows(){return this.data.filter(o=>o[zo]!==0)}};var $r=e=>e.type==="vuu-link-created"||e.type==="vuu-link-removed",$t=({dataSource:e,onFeatureInvocation:o,onSizeChange:t,onSubscribed:r,range:n=ye.NULL_RANGE,renderBufferSize:l=0})=>{let[,a]=(0,Q.useState)(null),i=(0,Q.useRef)([]),s=(0,Q.useRef)(!0),u=(0,Q.useRef)(!1),d=(0,Q.useRef)(n),m=(0,Q.useMemo)(()=>new ro((0,ye.getFullRange)(n,l)),[]),b=(0,Q.useCallback)(c=>{for(let v of c)m.add(v);i.current=m.data,s.current&&a({})},[m]),C=(0,Q.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,Q.useCallback)(()=>m.getSelectedRows(),[m]);(0,Q.useEffect)(()=>{var c;return s.current=!0,(c=e.resume)==null||c.call(e),()=>{var v;s.current=!1,(v=e.suspend)==null||v.call(e)}},[e]),(0,Q.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,Q.useCallback)(c=>{if(!(0,ye.rangesAreSame)(c,d.current)){let v=(0,ye.getFullRange)(c,l);m.setRange(v),e.range=d.current=v,e.emit("range",c)}},[e,m,l]);return{data:i.current,dataRef:i,getSelectedRows:h,range:d.current,setRange:x}};var lo=require("react"),Bt=e=>{let o=(0,lo.useRef)(e);return(0,lo.useMemo)(()=>o.current,[])};var Ut=require("@vuu-ui/vuu-utils"),_t=require("@salt-ds/core"),$=require("react");var Xt=new Set(["Home","End","PageUp","PageDown","ArrowDown","ArrowUp"]),No=new Set(Xt);No.add("ArrowLeft");No.add("ArrowRight");var Br=(e,o)=>{switch(o){case"cell":return No.has(e);case"row":return Xt.has(e);default:return!1}},Vr=["Home","End","PageUp","PageDown"],Vt=e=>Vr.includes(e),Wr=[-1,-1];function Wt(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 Qt=({columnCount:e=0,containerRef:o,disableFocus:t=!1,defaultHighlightedIndex:r,disableHighlightOnFocus:n,highlightedIndex:l,navigationStyle:a,requestScroll:i,onHighlight:s,rowCount:u=0,viewportRowCount:d})=>{var pe;let m=(0,$.useRef)([-1,-1]),b=(0,$.useRef)(),C=(0,$.useRef)([-1,0]),h=(0,$.useRef)(),[x,c]=(0,_t.useControlled)({controlled:l,default:r,name:"UseKeyboardNavigation"});h.current=x;let v=(0,$.useCallback)((f,w=!1)=>{s==null||s(f),c(f)},[s,c]),T=f=>f==null?void 0:f.closest("[role='columnHeader'],[role='cell']"),S=f=>{var w;if(f.role==="columnHeader")return[-1,parseInt((w=f.dataset.idx)!=null?w:"-1",10)];{let y=f.closest("[role='row']");if(y){let W=(0,Ut.getIndexFromRowElement)(y),g=Array.from(y.childNodes).indexOf(f);return[W,g]}}return Wr},D=(0,$.useCallback)(f=>{var w;if(o.current){let y=zt(o,f);y&&(y!==b.current&&((w=b.current)==null||w.removeAttribute("tabindex"),b.current=y,y.setAttribute("tabindex","0")),i==null||i({type:"scroll-row",rowIndex:f[0]}),y.focus({preventScroll:!0}))}},[o,i]),A=(0,$.useCallback)((f,w,y=!1)=>{let W=[f,w];C.current=W,a==="row"?c(f):D(W),y&&(m.current=W)},[D,a,c]),F=(0,$.useCallback)((f,[w,y])=>new Promise(W=>{let g=w;switch(f){case"PageDown":{g=Math.min(u-1,w+d),g!==w&&(i==null||i({type:"scroll-page",direction:"down"}));break}case"PageUp":{g=Math.max(0,w-d),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(()=>{W([g,y])},35)}),[i,u,d]),P=(0,$.useCallback)(()=>{var f;if(n!==!0&&(f=o.current)!=null&&f.contains(document.activeElement)){let w=T(document.activeElement);w&&(m.current=S(w),a==="row"&&c(m.current[0]))}},[n,o,a,c]),z=(0,$.useCallback)(async f=>{let[w,y]=Vt(f)?await F(f,C.current):Wt(f,C.current,e,u),[W,g]=C.current;(w!==W||y!==g)&&A(w,y,!0)},[e,F,u,A]),G=(0,$.useCallback)(f=>{i==null||i({type:"scroll-row",rowIndex:f})},[i]),Z=(0,$.useCallback)(async f=>{let{current:w}=h,[y]=Vt(f)?await F(f,[w!=null?w:-1,0]):Wt(f,[w!=null?w:-1,0],e,u);y!==w&&(v(y),G(y))},[e,F,u,G,v]);(0,$.useEffect)(()=>{l!==void 0&&l!==-1&&G(l)},[l,G]);let ee=(0,$.useCallback)(f=>{u>0&&Br(f.key,a)&&(f.preventDefault(),f.stopPropagation(),a==="row"?Z(f.key):z(f.key))},[u,a,Z,z]),oe=(0,$.useCallback)(f=>{let w=f.target,y=T(w);if(y){let[W,g]=S(y);A(W,g)}},[A]),Y=(0,$.useCallback)(()=>{v(-1)},[v]),K=(0,$.useCallback)(f=>{let w=Ft(f.target);w!==-1&&w!==h.current&&v(w)},[v]),k=(0,$.useCallback)(()=>{z("ArrowDown")},[z]),te=((pe=o.current)==null?void 0:pe.firstChild)!=null;return(0,$.useEffect)(()=>{if(te&&b.current===void 0&&!t){let{current:f}=o,w=(f==null?void 0:f.querySelector(Ao(0)))||(f==null?void 0:f.querySelector(Io(0,0)));w&&(w.setAttribute("tabindex","0"),b.current=w)}},[o,t,te]),{highlightedIndexRef:h,navigate:k,onClick:oe,onFocus:P,onKeyDown:ee,onMouseLeave:a==="row"?Y:void 0,onMouseMove:a==="row"?K:void 0}};var be=require("@vuu-ui/vuu-utils"),Se=require("react"),{IDX:Ur}=be.metadataKeys,_r=[],Xr=["Enter"," "],Jt=({highlightedIndexRef:e,selectionKeys:o=Xr,selectionModel:t,onSelect:r,onSelectionChange:n})=>{let l=(0,Se.useRef)(-1),a=(0,Se.useRef)(_r),i=(0,Se.useCallback)(d=>o.includes(d.key),[o]),s=(0,Se.useCallback)((d,m,b,C)=>{let{[Ur]:h}=m,{current:x}=l,{current:c}=a,T=((0,be.isRowSelected)(m)?be.deselectItem:be.selectItem)(t,c,h,b,C,x);a.current=T,l.current=h,r==null||r(m),n==null||n(T)},[r,n,t]);return{onKeyDown:(0,Se.useCallback)(d=>{if(i(d)){let{current:m}=e;if(m!==void 0&&m!==-1){let b=d.target.querySelector(`[aria-rowindex="${m}"]`);b&&(0,be.dispatchMouseEvent)(b,"click")}}},[e,i]),onRowClick:s}};var Zt=require("@vuu-ui/vuu-popups"),io=require("@vuu-ui/vuu-utils"),Yt=require("react"),Qr=[],jt=({columns:e,data:o,dataSource:t,getSelectedRows:r})=>{let[n]=(0,Zt.useContextMenu)();return(0,Yt.useCallback)(a=>{let i=a.target,s=i==null?void 0:i.closest("div[role='cell']"),u=i==null?void 0:i.closest("div[role='row']");if(s&&u){let{selectedRowsCount:d}=t,m=(0,io.buildColumnMap)(e),b=(0,io.getIndexFromRowElement)(u),C=Array.from(u.childNodes).indexOf(s),h=o.find(([c])=>c===b),x=e[C];n(a,"grid",{columnMap:m,columnName:x,row:h,selectedRows:d===0?Qr:r(),viewport:t.viewport})}},[e,o,t,r,n])};var R=require("@vuu-ui/vuu-utils"),qt=require("@vuu-ui/vuu-ui-controls"),en=require("react"),{info:Fo}=(0,R.logger)("useTableModel"),Jr=100,Zr=({serverDataType:e})=>e===void 0,on=(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"],tn=e=>e===void 0?void 0:Yr.includes(e)?"right":"left",Go=e=>e.type==="columnSettings",Ko=e=>e.type==="tableSettings",jr=(e,o)=>{switch(Fo==null||Fo(`TableModelReducer ${o.type}`),o.type){case"init":return nn(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 $e(e,o);case"tableConfig":return ln(e,o);default:return console.log(`unhandled action ${o.type}`),e}},Oo=(e,o)=>{let[t,r]=(0,en.useReducer)(jr,{tableConfig:e,dataSource:o},nn),{columns:n,headings:l,tableConfig:a,...i}=t;return{columns:n,dispatchTableModelAction:r,headings:l,tableAttributes:i,tableConfig:a}};function nn({dataSource:e,tableConfig:o}){let{columns:t,...r}=o,{config:n,tableSchema:l}=e,a=t.filter((0,R.subscribedOnly)(n==null?void 0:n.columns)).map(rn(r,l)),i=a.some(R.isPinned)?(0,R.sortPinnedColumns)(a):a,s={columns:i,headings:(0,R.getTableHeadings)(i),tableConfig:o,...r};if(n){let{columns:u,...d}=n;s=ln(s,{type:"tableConfig",...d})}return s}var qr=(e,o)=>o==="uppercase"?e.toUpperCase():o==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,rn=(e,o)=>(t,r)=>{let{columnDefaultWidth:n=Jr,columnFormatHeader:l}=e,a=on(t,o),{align:i=tn(a),name:s,label:u=(0,R.getColumnLabel)(t),width:d=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,qt.buildValidationChecker)(t.type.renderer.rules):void 0,index:r+1,label:qr(u,l),name:s,originalIdx:r,serverDataType:a,valueFormatter:(0,R.getValueFormatter)(t,a),width:d};return(0,R.isGroupColumn)(b)&&(b.columns=b.columns.map(C=>rn(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(),[a]=l.splice(n,1);return l.splice(n+t,0,a),{...e,columns:l}}return e}function ol(e,{columns:o}){return o.some(t=>t.hidden!==!0)?o.reduce((t,r)=>r.hidden!==!0?$e(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?$e(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 $e(e,{type:n,column:o,resizing:l});case"end":return $e(e,{type:n,column:o,resizing:l,width:r});case"resize":return $e(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 a;let l=on(n,o);return{...n,align:(a=n.align)!=null?a:tn(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(a=>a.name===r.name);return l?(t=(0,R.replaceColumn)(t,{...l,pin:n}),t=(0,R.sortPinnedColumns)(t),{...e,columns:t}):e}function $e(e,o){let{columns:t,tableConfig:r}=e,{align:n,column:l,hidden:a,label:i,resizing:s,width:u}=o,d=t.find(m=>m.name===l.name);if(d&&((n==="left"||n==="right")&&(t=(0,R.replaceColumn)(t,{...d,align:n})),typeof i=="string"&&(t=(0,R.replaceColumn)(t,{...d,label:i})),typeof s=="boolean"&&(t=(0,R.replaceColumn)(t,{...d,resizing:s})),typeof a=="boolean"&&(t=(0,R.replaceColumn)(t,{...d,hidden:a})),typeof u=="number")){t=(0,R.replaceColumn)(t,{...d,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 ln(e,{confirmed:o,filter:t,groupBy:r,sort:n}){let l=r!==void 0,a=typeof(t==null?void 0:t.filter)=="string",i=n&&n.sortDefs.length>0,s=e;return l&&(s={...e,columns:(0,R.applyGroupByToColumns)(s.columns,r,o)}),i&&(s={...e,columns:(0,R.applySortToColumns)(s.columns,n)}),a?s={...e,columns:(0,R.applyFilterToColumns)(s.columns,t)}:s.columns.some(R.isFilteredColumn)&&(s={...e,columns:(0,R.stripFilterFromColumns)(s.columns)}),s}var ke=require("@vuu-ui/vuu-utils"),H=require("react");var il=100,an=200,sn=e=>{let{clientHeight:o,clientWidth:t,scrollHeight:r,scrollWidth:n}=e;return[n-t,r-o]},al=(e,o)=>{if(e!==void 0){let{scrollTop:t}=e;return o>t?"fwd":"bwd"}},un=(e,o)=>{let{clientHeight:t,clientWidth:r,scrollHeight:n,scrollLeft:l,scrollTop:a,scrollWidth:i}=e,s=i-r,u=l/(i-r),d=n-t,m=a/(n-t),b=al(o,a);return b==="fwd"&&m>.99?m=1:b==="bwd"&&m<.02&&(m=0),[l,u,s,a,m,d]},mn={scrollToIndex:()=>{},scrollToKey:()=>{}},cn=({onAttach:e,onDetach:o})=>{let t=(0,H.useRef)(null);return(0,H.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])},$o=({columns:e,getRowAtPosition:o,onHorizontalScroll:t,onVerticalScroll:r,onVerticalScrollInSitu:n,rowHeight:l,scrollingApiRef:a,setRange:i,viewportMeasurements:s})=>{let u=(0,H.useRef)(0),d=(0,H.useRef)(l),m=(0,H.useRef)(!1),b=(0,H.useRef)({scrollTop:0,scrollLeft:0}),C=(0,H.useRef)(!1),h=(0,H.useRef)({scrollTop:0,scrollLeft:0}),x=(0,H.useRef)(null),c=(0,H.useRef)(null),v=(0,H.useRef)(0),{appliedPageSize:T,isVirtualScroll:S,rowCount:D,totalHeaderHeight:A,viewportWidth:F}=s,P=(0,H.useRef)([]),[,z]=(0,H.useState)({}),G=(0,H.useRef)(0);(0,H.useMemo)(()=>{let[g,E]=(0,ke.getColumnsInViewport)(e,b.current.scrollLeft,b.current.scrollLeft+F+an);G.current=E,P.current=g},[F,e]);let Z=(0,H.useCallback)(g=>{if(b.current.scrollLeft=g,t==null||t(g),Math.abs(g-v.current)>il){v.current=g;let[E,U]=(0,ke.getColumnsInViewport)(e,g,g+F+an);(0,ke.itemsChanged)(P.current,E)&&(G.current=U,P.current=E,z({}))}},[e,t,F]),ee=(0,H.useCallback)((g,E)=>{b.current.scrollTop=g,r==null||r(g,E);let U=o(g);U!==u.current&&(u.current=U,i({from:U,to:U+D})),n==null||n(0)},[o,r,n,i,D]),oe=(0,H.useCallback)(()=>{let{current:g}=c,{current:E}=x,{current:U}=m,{current:q}=h;if(U)m.current=!1;else if(g&&E){C.current=!0;let[j,ce,,J,I]=un(E,q);q.scrollLeft=j,q.scrollTop=J;let[O,ne]=sn(E),V=Math.round(ce*O),He=I*ne;g.scrollTo({left:V,top:He,behavior:"auto"})}n==null||n(0)},[n]),Y=(0,H.useCallback)(()=>{let{current:g}=C,{current:E}=c,{current:U}=x,{current:q}=b;if(E&&U){let[j,ce,J,I,O,ne]=un(E);m.current=!0,g?C.current=!1:(U.scrollLeft=Math.round(ce*J),U.scrollTop=O*ne),q.scrollTop!==I&&ee(I,O),q.scrollLeft!==j&&Z(j)}},[ee,Z]),K=(0,H.useCallback)(g=>{x.current=g,g.addEventListener("scroll",oe,{passive:!0})},[oe]),k=(0,H.useCallback)(g=>{x.current=null,g.removeEventListener("scroll",oe)},[oe]),te=(0,H.useCallback)(g=>{c.current=g,g.addEventListener("scroll",Y,{passive:!0})},[Y]),pe=(0,H.useCallback)(g=>{c.current=null,g.removeEventListener("scroll",Y)},[Y]),f=cn({onAttach:te,onDetach:pe}),w=cn({onAttach:K,onDetach:k}),y=(0,H.useCallback)(g=>{let{current:E}=c;if(E){let[U,q]=sn(E),{scrollLeft:j,scrollTop:ce}=E;if(m.current=!1,g.type==="scroll-row"){let J=(0,ke.getRowElementAtIndex)(E,g.rowIndex);if(J!==null){let[I,O]=Gt(J,A);if(console.log(`outside viewport ? ${I} ${O}`),I&&O)if(S){let ne=I==="down"?1:-1;n==null||n(ne);let V=u.current+ne;u.current=V,i({from:V,to:V+D})}else{let ne=j,V=ce;I==="up"||I==="down"?V=Math.min(Math.max(0,ce+O),q):ne=Math.min(Math.max(0,j+O),U),E.scrollTo({top:V,left:ne,behavior:"smooth"})}}}else if(g.type==="scroll-page"){let{direction:J}=g;if(S){let I=J==="down"?D:-D;n==null||n(I);let O=u.current+I;u.current=O,i({from:O,to:O+D})}else{let I=J==="down"?T:-T,O=Math.min(Math.max(0,ce+I),q);E.scrollTo({top:O,left:j,behavior:"auto"})}}else if(g.type==="scroll-end"){let{direction:J}=g,I=J==="end"?q:0;E.scrollTo({top:I,left:E.scrollLeft,behavior:"auto"})}}},[T,S,n,i,A,D]),W=(0,H.useMemo)(()=>({scrollToIndex:g=>{if(x.current){let E=(g-30)*20;x.current.scrollTop=E}},scrollToKey:g=>{console.log(`scrollToKey ${g}`)}}),[]);return(0,H.useImperativeHandle)(a,()=>x.current?W:mn,[W]),(0,H.useEffect)(()=>{if(l!==d.current)d.current=l,b.current.scrollTop>0&&c.current&&(c.current.scrollTop=0);else{let{current:g}=u,E={from:g,to:g+D};i(E)}},[l,i,D]),{columnsWithinViewport:P.current,scrollbarContainerRef:w,contentContainerRef:f,requestScroll:y,virtualColSpan:G.current}};var Be=require("@vuu-ui/vuu-utils"),se=require("react"),sl=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},Bo=({columns:e,headerHeight:o,headings:t,rowCount:r,rowHeight:n,selectionEndSize:l=4,size:a})=>{let i=(0,se.useRef)(0),s=(0,se.useRef)(0),u=Math.min(n*r,sl),d=r*n,m=d-u,{pinnedWidthLeft:b,pinnedWidthRight:C,unpinnedWidth:h}=(0,se.useMemo)(()=>(0,Be.measurePinnedColumns)(e,l),[e,l]),x=(0,se.useRef)(o);(0,se.useMemo)(()=>{x.current=o*(1+t.length)},[o,t.length]);let[c,v,T]=(0,se.useMemo)(()=>{if(m){let[A,F,P]=(0,Be.virtualRowPositioning)(n,m,s);return[G=>A(G,i.current),F,P]}else return(0,Be.actualRowPositioning)(n)},[m,n]),S=(0,se.useCallback)((A,F)=>{s.current=F},[]),D=(0,se.useCallback)(A=>{A===0?i.current=0:i.current=Math.max(0,i.current+A)},[]);return(0,se.useMemo)(()=>{if(a){let{current:A}=x,F=15,P=b+h+C,z=P>a.width?F:0,G=(a.height-o)/n,Z=Number.isInteger(G)?G:Math.ceil(G),ee=a.height-A,oe=u>ee?F:0,Y=Z*n*(u/d),K=a.width;return{appliedPageSize:Y,contentHeight:u,contentWidth:P,getRowAtPosition:v,getRowOffset:c,isVirtualScroll:T,horizontalScrollbarHeight:z,pinnedWidthLeft:b,pinnedWidthRight:C,rowCount:Z,setInSituRowOffset:D,setScrollTop:S,totalHeaderHeight:A,verticalScrollbarWidth:oe,viewportBodyHeight:ee,viewportWidth:K}}else return ul},[v,c,o,T,b,h,C,u,n,D,S,a,d])};var dn=require("@vuu-ui/vuu-layout"),pn=require("@vuu-ui/vuu-utils"),ue=require("react"),bn=({availableColumns:e,onAvailableColumnsChange:o,onConfigChange:t,onCreateCalculatedColumn:r,onDataSourceConfigChange:n,tableConfig:l})=>{let a=(0,dn.useLayoutProviderDispatch)(),i=(0,ue.useRef)(),[s,u]=(0,ue.useState)(e),d=(0,ue.useCallback)((c,v,T)=>{a({type:"set-props",path:"#context-panel",props:{expanded:!0,content:{type:c,props:T},title:v}})},[a]),m=(0,ue.useCallback)(()=>{requestAnimationFrame(()=>{var c;(c=i.current)==null||c.call(i)})},[]),b=(0,ue.useCallback)(c=>{let v=s.concat({name:c.name,serverDataType:(0,pn.getCalculatedColumnType)(c)});u(v),o==null||o(v),requestAnimationFrame(()=>{var T;(T=i.current)==null||T.call(i)}),r(c)},[s,o,r]),C=(0,ue.useCallback)(c=>{d("ColumnSettings","Column Settings",{column:c.column,onCancelCreateColumn:m,onConfigChange:t,onCreateCalculatedColumn:b,tableConfig:l,vuuTable:c.vuuTable})},[m,b,t,d,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)(()=>{d("TableSettings","DataGrid Settings",{availableColumns:s!=null?s:l.columns.map(({name:c,serverDataType:v})=>({name:c,serverDataType:v})),onAddCalculatedColumn:h,onConfigChange:t,onDataSourceConfigChange:n,onNavigateToColumn:x,tableConfig:l})},[s,h,x,t,n,d,l]),{showColumnSettingsPanel:C,showTableSettingsPanel:i.current}};var fn=require("@vuu-ui/vuu-utils"),gn=require("react"),cl=e=>{let o=[];return e==null||e.forEach(t=>{let r=(0,fn.getRowClassNameGenerator)(t);r&&o.push(r.fn)}),(t,r)=>{let n=[];return o==null||o.forEach(l=>{let a=l(t,r);a&&n.push(a)}),n.join(" ")}},Cn=({rowClassNameGenerators:e})=>(0,gn.useMemo)(()=>cl(e),[e]);var ao=e=>e,{KEY:ml,IS_EXPANDED:vn,IS_LEAF:hn}=B.metadataKeys,dl={draggable:void 0,onMouseDown:void 0},pl=()=>dl,bl=(e,o)=>({...e,columns:e.columns.concat(o)}),xn=({allowDragDrop:e=!1,availableColumns:o,config:t,containerRef:r,dataSource:n,disableFocus:l,headerHeight:a=25,highlightedIndex:i,id:s,navigationStyle:u="cell",onAvailableColumnsChange:d,onConfigChange:m,onDragStart:b,onDrop:C,onFeatureInvocation:h,onHighlight:x,onRowClick:c,onSelect:v,onSelectionChange:T,renderBufferSize:S=0,rowHeight:D=20,scrollingApiRef:A,selectionModel:F,size:P})=>{let[z,G]=(0,M.useState)(n.size);if(n===void 0)throw Error("no data source provided to Vuu Table");let Z=Cn(t),ee=e?wn.useDragDrop:pl,oe=(0,M.useMemo)(()=>Lt(n),[n]),Y=(0,M.useCallback)(p=>{G(p)},[]),{columns:K,dispatchTableModelAction:k,headings:te,tableAttributes:pe,tableConfig:f}=Oo(t,n);(0,B.useLayoutEffectSkipFirst)(()=>{k({type:"init",tableConfig:t,dataSource:n})},[t,n,k]);let w=(0,M.useCallback)(p=>{k({type:"init",tableConfig:p,dataSource:n}),m==null||m(ao(p))},[n,k,m]),y=(0,M.useMemo)(()=>(0,B.buildColumnMap)(n.columns),[n.columns]),W=(0,M.useCallback)(({tableSchema:p})=>{p?k({type:"setTableSchema",tableSchema:p}):console.log("subscription message with no schema")},[k]),{getRowAtPosition:g,getRowOffset:E,setInSituRowOffset:U,setScrollTop:q,...j}=Bo({columns:K,headerHeight:a,headings:te,rowCount:z,rowHeight:D,size:P}),ce=Bt({from:0,to:j.rowCount}),{data:J,dataRef:I,getSelectedRows:O,range:ne,setRange:V}=$t({dataSource:n,onFeatureInvocation:h,renderBufferSize:S,onSizeChange:Y,onSubscribed:W,range:ce}),{requestScroll:He,...fo}=$o({columns:K,getRowAtPosition:g,rowHeight:D,scrollingApiRef:A,setRange:V,onVerticalScroll:q,onVerticalScrollInSitu:U,viewportMeasurements:j}),Qe=(0,M.useCallback)(p=>{k({type:"init",tableConfig:p,dataSource:n}),m==null||m(ao(p))},[n,k,m]),Me=(0,M.useCallback)(p=>{n.config={...n.config,...p}},[n]);(0,M.useEffect)(()=>{n.on("config",(p,L,N)=>{((N==null?void 0:N.filterChanged)||(N==null?void 0:N.groupByChanged))&&n.range.from>0&&He({type:"scroll-end",direction:"home"}),k({type:"tableConfig",...p,confirmed:L})})},[n,k,He]);let $n=(0,M.useCallback)(p=>{n.columns=n.columns.concat(p.name),w(bl(f,p))},[n,f,w]),_o=(0,M.useCallback)(p=>{let{columns:L}=p,N=L.map(re=>re.name),X={...f,columns:f.columns.map(re=>N.includes(re.name)?{...re,hidden:!0}:re)};w(X)},[f,w]),Xo=(0,M.useCallback)(p=>{w({...f,columns:(0,B.updateColumn)(f.columns,{...p.column,pin:p.pin})})},[f,w]),{showColumnSettingsPanel:Qo,showTableSettingsPanel:Jo}=bn({availableColumns:o!=null?o:f.columns.map(({name:p,serverDataType:L="string"})=>({name:p,serverDataType:L})),onAvailableColumnsChange:d,onConfigChange:Qe,onCreateCalculatedColumn:$n,onDataSourceConfigChange:Me,tableConfig:f}),Bn=(0,M.useCallback)(p=>{if(Go(p))Qo(p);else if(Ko(p))Jo();else switch(p.type){case"hideColumns":return _o(p);case"pinColumn":return Xo(p);default:k(p)}},[k,_o,Xo,Qo,Jo]),Vn=It({dataSource:n,onPersistentColumnOperation:Bn}),Wn=(0,M.useCallback)((p,L=!1,N)=>{n&&(n.sort=(0,B.applySort)(n.sort,p,L,N))},[n]),go=(0,M.useRef)(),Un=(0,M.useCallback)((p,L,N)=>{var re,Ue,he;let X=K.find(ae=>ae.name===L);if(X)if(p==="resize")(re=go.current)==null||re.forEach(ae=>{ae.style.width=`${N}px`});else if(p==="end")go.current=void 0,(0,B.isValidNumber)(N)&&(k({type:"resizeColumn",phase:p,column:X,width:N}),m==null||m(ao(Lo(f,{type:"col-size",column:X,width:N}))));else{let ae=`[aria-colindex='${X.index}']`;go.current=Array.from((he=(Ue=r.current)==null?void 0:Ue.querySelectorAll(`.vuuTableCell${ae},.vuuTableHeaderCell${ae}`))!=null?he:[]),k({type:"resizeColumn",phase:p,column:X,width:N})}else throw Error(`useDataTable.handleColumnResize, column ${L} not found`)},[K,k,m,f,r]),_n=(0,M.useCallback)((p,L)=>{var re,Ue;let N=(0,B.isJsonGroup)(L,p,y),X=p[ml];if(p[vn]){if(n.closeTreeNode(X,!0),N){let he=K.indexOf(L),ae=(re=n.getRowsAtDepth)==null?void 0:re.call(n,he+1);ae&&!ae.some(Le=>Le[vn]||Le[hn])&&k({type:"hideColumns",columns:K.slice(he+2)})}}else if(n.openTreeNode(X),N){let he=(Ue=n.getChildRows)==null?void 0:Ue.call(n,X),ae=K.indexOf(L)+1,Le=[K[ae]];he&&he.some(Co=>Co[hn])&&Le.push(K[ae+1]),Le.some(Co=>Co.hidden)&&k({type:"showColumns",columns:Le})}},[y,K,n,k]),{highlightedIndexRef:Zo,navigate:Xn,onFocus:Yo,onKeyDown:jo,...Qn}=Qt({columnCount:K.filter(p=>p.hidden!==!0).length,containerRef:r,disableFocus:l,highlightedIndex:i,navigationStyle:u,requestScroll:He,rowCount:n==null?void 0:n.size,onHighlight:x,viewportRange:ne,viewportRowCount:j.rowCount}),{onBlur:Jn,onDoubleClick:Zn,onKeyDown:qo,onFocus:et}=Ot({navigate:Xn}),Yn=(0,M.useCallback)(p=>{Yo(),p.defaultPrevented||et(p)},[et,Yo]),jn=jt({columns:K,data:J,dataSource:n,getSelectedRows:O}),qn=(0,M.useCallback)(p=>{n.groupBy=p.map(L=>L.name)},[n]),er=(0,M.useCallback)(p=>{(0,B.isGroupColumn)(p)?n.groupBy=[]:n&&n.groupBy.includes(p.name)&&(n.groupBy=n.groupBy.filter(L=>L!==p.name))},[n]),or=(0,M.useCallback)(p=>{n.select(p),T==null||T(p)},[n,T]),tr=(0,M.useCallback)(p=>{v&&v(p===null?null:(0,B.asDataSourceRowObject)(p,y))},[y,v]),{onKeyDown:ot,onRowClick:tt}=Jt({highlightedIndexRef:Zo,onSelect:tr,onSelectionChange:or,selectionModel:F}),nr=(0,M.useCallback)((p,L,N,X)=>{tt(p,L,N,X),c==null||c(p,(0,B.asDataSourceRowObject)(L,y))},[y,c,tt]),rr=(0,M.useCallback)(p=>{jo(p),p.defaultPrevented||qo(p),p.defaultPrevented||ot(p)},[jo,qo,ot]),lr=(0,M.useCallback)(p=>{let L={...f,columns:p};k({type:"init",tableConfig:L,dataSource:n}),m==null||m(ao(L))},[n,k,m,f]),ir=(0,M.useCallback)(p=>{C==null||C(p)},[C]),ar=(0,M.useCallback)(async(p,L,N)=>n.applyEdit(p,L,N),[n]),sr=(0,M.useCallback)(p=>{let{initialDragElement:L}=p,N=(0,B.getIndexFromRowElement)(L),X=I.current.find(re=>re[0]===N);X&&p.setPayload(X),b==null||b(p)},[I,b]),{onMouseDown:ur,draggable:cr}=ee({allowDragDrop:e,containerRef:r,draggableClassName:"vuuTable",id:s,onDragStart:sr,onDrop:ir,orientation:"vertical",itemQuery:".vuuTableRow"});return{...Qn,"aria-rowcount":n.size,rowClassNameGenerator:Z,draggableRow:cr,onBlur:Jn,onDoubleClick:Zn,onFocus:Yn,onKeyDown:rr,onMouseDown:ur,columnMap:y,columns:K,data:J,getRowOffset:E,handleContextMenuAction:Vn,headings:te,highlightedIndex:Zo.current,menuBuilder:oe,onContextMenu:jn,onDataEdited:ar,onMoveColumn:lr,onMoveGroupColumn:qn,onRemoveGroupColumn:er,onRowClick:nr,onSortColumn:Wn,onResizeColumn:Un,onToggleGroup:_n,scrollProps:fo,tableAttributes:pe,tableConfig:f,viewportMeasurements:j}};var Tn=require("@vuu-ui/vuu-utils"),De=require("react"),Rn=({rowHeight:e=0})=>{let[o,t]=(0,De.useState)(e),r=(0,De.useRef)(o),n=(0,De.useMemo)(()=>new ResizeObserver(a=>{for(let i of a){let[{blockSize:s}]=i.borderBoxSize,u=Math.round(s);(0,Tn.isValidNumber)(u)&&r.current!==u&&(r.current=u,t(u))}}),[]),l=(0,De.useCallback)(a=>{if(a){if(e===0){let{height:i}=a.getBoundingClientRect();console.log({boundingClientHeight:i}),console.log(`measured rowHeight = ${i} (${e})`),n.observe(a),t(i)}}else n.disconnect()},[n,e]);return{rowHeight:o,rowRef:l}};var ie=require("react/jsx-runtime"),ve="vuuTable",{IDX:fl,RENDER_IDX:gl}=so.metadataKeys,Cl=({Row:e=Ho,allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:a=!1,highlightedIndex:i,id:s,navigationStyle:u="cell",onAvailableColumnsChange:d,onConfigChange:m,onDragStart:b,onDrop:C,onFeatureInvocation:h,onHighlight:x,onRowClick:c,onSelect:v,onSelectionChange:T,renderBufferSize:S=5,rowHeight:D,scrollingApiRef:A,selectionModel:F="extended",showColumnHeaders:P=!0,headerHeight:z=P?D*1.25:0,size:G})=>{let Z=(0,so.useId)(s),{columnMap:ee,columns:oe,data:Y,draggableRow:K,getRowOffset:k,handleContextMenuAction:te,headings:pe,highlightedIndex:f,menuBuilder:w,onDataEdited:y,onMoveColumn:W,onMoveGroupColumn:g,onRemoveGroupColumn:E,onResizeColumn:U,onRowClick:q,onSortColumn:j,onToggleGroup:ce,rowClassNameGenerator:J,scrollProps:I,tableAttributes:O,tableConfig:ne,viewportMeasurements:V,...He}=xn({allowDragDrop:o,availableColumns:t,config:r,containerRef:n,dataSource:l,disableFocus:a,headerHeight:z,highlightedIndex:i,id:Z,navigationStyle:u,onAvailableColumnsChange:d,onConfigChange:m,onDragStart:b,onDrop:C,onFeatureInvocation:h,onHighlight:x,onRowClick:c,onSelect:v,onSelectionChange:T,renderBufferSize:Math.max(5,S),rowHeight:D,scrollingApiRef:A,selectionModel:F,size:G}),fo=(0,Vo.default)(`${ve}-contentContainer`,{[`${ve}-colLines`]:O.columnSeparators,[`${ve}-rowLines`]:O.rowSeparators,[`${ve}-zebra`]:O.zebraStripes}),Qe={"--content-height":`${V.contentHeight}px`,"--content-width":`${V.contentWidth}px`,"--horizontal-scrollbar-height":`${V.horizontalScrollbarHeight}px`,"--pinned-width-left":`${V.pinnedWidthLeft}px`,"--pinned-width-right":`${V.pinnedWidthRight}px`,"--header-height":`${z}px`,"--row-height-prop":`${D}px`,"--total-header-height":`${V.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${V.verticalScrollbarWidth}px`,"--viewport-body-height":`${V.viewportBodyHeight}px`};return(0,ie.jsxs)(yn.ContextMenuProvider,{menuActionHandler:te,menuBuilder:w,children:[(0,ie.jsx)("div",{className:`${ve}-scrollbarContainer`,ref:I.scrollbarContainerRef,style:Qe,children:(0,ie.jsx)("div",{className:`${ve}-scrollbarContent`})}),(0,ie.jsx)("div",{className:fo,ref:I.contentContainerRef,style:Qe,children:(0,ie.jsxs)("div",{...He,className:`${ve}-table`,role:"table",tabIndex:a?void 0:-1,children:[P?(0,ie.jsx)(Mo,{columns:I.columnsWithinViewport,headings:pe,onMoveColumn:W,onMoveGroupColumn:g,onRemoveGroupColumn:E,onResizeColumn:U,onSortColumn:j,tableConfig:ne,tableId:Z,virtualColSpan:I.virtualColSpan}):null,(0,ie.jsx)("div",{className:`${ve}-body`,children:Y.map(Me=>(0,ie.jsx)(e,{"aria-rowindex":Me[0]+1,classNameGenerator:J,columnMap:ee,columns:I.columnsWithinViewport,highlighted:f===Me[fl],onClick:q,onDataEdited:y,row:Me,offset:k(Me),onToggleGroup:ce,virtualColSpan:I.virtualColSpan,zebraStripes:O.zebraStripes},Me[gl]))})]})}),K]})},vl=(0,Ve.forwardRef)(function({Row:o,allowDragDrop:t,availableColumns:r,className:n,config:l,dataSource:a,disableFocus:i,highlightedIndex:s,id:u,navigationStyle:d,onAvailableColumnsChange:m,onConfigChange:b,onDragStart:C,onDrop:h,onFeatureInvocation:x,onHighlight:c,onRowClick:v,onSelect:T,onSelectionChange:S,renderBufferSize:D,rowHeight:A,scrollingApiRef:F,selectionModel:P,showColumnHeaders:z,headerHeight:G,style:Z,...ee},oe){let Y=(0,Ve.useRef)(null),[K,k]=(0,Ve.useState)(),{rowHeight:te,rowRef:pe}=Rn({rowHeight:A});if(l===void 0)throw Error("vuu Table requires config prop. Minimum config is list of Column Descriptors");if(a===void 0)throw Error("vuu Table requires dataSource prop");return console.log({rowHeight:te}),(0,ie.jsxs)(Dn.MeasuredContainer,{...ee,className:(0,Vo.default)(ve,n),id:u,onResize:k,ref:(0,Hn.useForkRef)(Y,oe),children:[(0,ie.jsx)(Ht,{ref:pe,height:A}),K&&te?(0,ie.jsx)(Cl,{Row:o,allowDragDrop:t,availableColumns:r,config:l,containerRef:Y,dataSource:a,disableFocus:i,headerHeight:G,highlightedIndex:s,id:u,navigationStyle:d,onAvailableColumnsChange:m,onConfigChange:b,onDragStart:C,onDrop:h,onFeatureInvocation:x,onHighlight:c,onRowClick:v,onSelect:T,onSelectionChange:S,renderBufferSize:D,rowHeight:te,scrollingApiRef:F,selectionModel:P,showColumnHeaders:z,size:K}):null]})});var uo=require("react"),co=require("@vuu-ui/vuu-ui-controls"),Mn=require("@salt-ds/core"),We=require("@vuu-ui/vuu-utils");var Wo=require("react/jsx-runtime"),Uo=(0,uo.memo)(({column:e,columnMap:o,onCommit:t=co.WarnCommit,row:r})=>{let n=o[e.name],l=!!r[n],a=(0,uo.useCallback)(i=>async s=>{let u=await t(i);return u===!0&&(0,We.dispatchCustomEvent)(s.target,"vuu-commit"),u},[t]);return e.editable?(0,Wo.jsx)(Mn.Checkbox,{checked:l,onClick:a(!l)}):(0,Wo.jsx)(co.CheckboxIcon,{checked:l,disabled:!0})},We.dataColumnAndKeyUnchanged);Uo.displayName="CheckboxCell";(0,We.registerComponent)("checkbox-cell",Uo,"cell-renderer",{serverDataType:"boolean"});var Pn=require("@vuu-ui/vuu-utils"),En=require("@salt-ds/core"),Sn=require("@vuu-ui/vuu-ui-controls"),kn=me(require("clsx"));var po=require("react/jsx-runtime"),mo="vuuTableInputCell",hl=()=>(console.warn("onCommit handler has not been provided to InputCell cell renderer"),Promise.resolve(!0)),Ln=({column:e,columnMap:o,onCommit:t=hl,row:r})=>{let n=o[e.name],l=r[n],{align:a="left",clientSideEditValidationCheck:i}=e,{warningMessage:s,...u}=(0,Sn.useEditableText)({initialValue:l,onCommit:t,clientSideEditValidationCheck:i}),d=s&&a==="left"?(0,po.jsx)("span",{className:`${mo}-icon`,"data-icon":"error"}):void 0,m=s&&a==="right"?(0,po.jsx)("span",{className:`${mo}-icon`,"data-icon":"error"}):void 0;return(0,po.jsx)(En.Input,{...u,className:(0,kn.default)(mo,{[`${mo}-error`]:s!==void 0}),endAdornment:d,startAdornment:m})};(0,Pn.registerComponent)("input-cell",Ln,"cell-renderer",{userCanAssign:!1});var In=require("@vuu-ui/vuu-ui-controls"),fe=require("@vuu-ui/vuu-utils"),zn=me(require("clsx")),bo=require("react"),Nn=require("@vuu-ui/vuu-ui-controls");var Gn=require("react/jsx-runtime"),An="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`)},Fn=(0,bo.memo)(function({column:o,columnMap:t,onCommit:r=In.WarnCommit,row:n}){let l=wl(o),a=t[o.name],i=n[a],s=(0,bo.useCallback)((u,d)=>r(d).then(m=>(m===!0&&(0,fe.dispatchCustomEvent)(u.target,"vuu-commit"),m)),[r]);return(0,Gn.jsx)(Nn.CycleStateButton,{className:(0,zn.default)(An,`${An}-${o.name}`),onCommit:s,value:i,values:l,variant:"cta",children:i})},fe.dataColumnAndKeyUnchanged);(0,fe.registerComponent)("toggle-cell",Fn,"cell-renderer",{userCanAssign:!1});var Kn=require("@vuu-ui/vuu-ui-controls"),On=require("@vuu-ui/vuu-utils"),Xe=require("react"),xl=(e,o)=>{let t=(0,Xe.useRef)(null),[r,n]=(0,Kn.useStateRef)(e),l=(0,Xe.useCallback)(i=>{var s;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,d=(s=t.current)==null?void 0:s.querySelector(`[aria-rowindex="${u}"]`);d&&(0,On.dispatchMouseEvent)(d,"click")}},[r,o,n]),a=(0,Xe.useCallback)(i=>{n(i)},[n]);return{highlightedIndexRef:r,onHighlight:a,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(selectOperation === import_vuu_utils15.selectItem ? row : null);
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 = (0, import_vuu_utils15.getRowElementAtIndex)(e.target, rowIndex);
1756
+ if (rowEl) {
1757
+ (0, import_vuu_utils15.dispatchMouseEvent)(rowEl, "click");
1758
+ }
1759
+ }
1760
+ }
1761
+ },
1762
+ [highlightedIndexRef, isSelectionEvent]
1763
+ );
1764
+ return {
1765
+ onKeyDown: handleKeyDown,
1766
+ onRowClick: handleRowClick
1767
+ };
1768
+ };
1769
+
1770
+ // src/useTableContextMenu.ts
1771
+ var import_vuu_popups2 = require("@vuu-ui/vuu-popups");
1772
+ var import_vuu_utils16 = require("@vuu-ui/vuu-utils");
1773
+ var import_react18 = require("react");
1774
+ var NO_ROWS = [];
1775
+ var useTableContextMenu = ({
1776
+ columns,
1777
+ data,
1778
+ dataSource,
1779
+ getSelectedRows
1780
+ }) => {
1781
+ const [showContextMenu] = (0, import_vuu_popups2.useContextMenu)();
1782
+ const onContextMenu = (0, import_react18.useCallback)(
1783
+ (evt) => {
1784
+ const target = evt.target;
1785
+ const cellEl = target == null ? void 0 : target.closest("div[role='cell']");
1786
+ const rowEl = target == null ? void 0 : target.closest("div[role='row']");
1787
+ if (cellEl && rowEl) {
1788
+ const { selectedRowsCount } = dataSource;
1789
+ const columnMap = (0, import_vuu_utils16.buildColumnMap)(columns);
1790
+ const rowIndex = (0, import_vuu_utils16.getIndexFromRowElement)(rowEl);
1791
+ const cellIndex = Array.from(rowEl.childNodes).indexOf(cellEl);
1792
+ const row = data.find(([idx]) => idx === rowIndex);
1793
+ const columnName = columns[cellIndex];
1794
+ showContextMenu(evt, "grid", {
1795
+ columnMap,
1796
+ columnName,
1797
+ row,
1798
+ selectedRows: selectedRowsCount === 0 ? NO_ROWS : getSelectedRows(),
1799
+ viewport: dataSource.viewport
1800
+ });
1801
+ }
1802
+ },
1803
+ [columns, data, dataSource, getSelectedRows, showContextMenu]
1804
+ );
1805
+ return onContextMenu;
1806
+ };
1807
+
1808
+ // src/useTableModel.ts
1809
+ var import_vuu_utils17 = require("@vuu-ui/vuu-utils");
1810
+ var import_vuu_ui_controls3 = require("@vuu-ui/vuu-ui-controls");
1811
+ var import_react19 = require("react");
1812
+ var { info } = (0, import_vuu_utils17.logger)("useTableModel");
1813
+ var DEFAULT_COLUMN_WIDTH = 100;
1814
+ var columnWithoutDataType = ({ serverDataType }) => serverDataType === void 0;
1815
+ var getDataType = (column, tableSchema) => {
1816
+ const schemaColumn = tableSchema == null ? void 0 : tableSchema.columns.find(
1817
+ ({ name }) => name === column.name
1818
+ );
1819
+ if (schemaColumn) {
1820
+ return schemaColumn.serverDataType;
1821
+ } else {
1822
+ return column.serverDataType;
1823
+ }
1824
+ };
1825
+ var numericTypes = ["int", "long", "double"];
1826
+ var getDefaultAlignment = (serverDataType) => serverDataType === void 0 ? void 0 : numericTypes.includes(serverDataType) ? "right" : "left";
1827
+ var isShowColumnSettings = (action) => action.type === "columnSettings";
1828
+ var isShowTableSettings = (action) => action.type === "tableSettings";
1829
+ var columnReducer = (state, action) => {
1830
+ info == null ? void 0 : info(`TableModelReducer ${action.type}`);
1831
+ switch (action.type) {
1832
+ case "init":
1833
+ return init(action);
1834
+ case "moveColumn":
1835
+ return moveColumn(state, action);
1836
+ case "resizeColumn":
1837
+ return resizeColumn(state, action);
1838
+ case "setTableSchema":
1839
+ return setTableSchema(state, action);
1840
+ case "hideColumns":
1841
+ return hideColumns(state, action);
1842
+ case "showColumns":
1843
+ return showColumns(state, action);
1844
+ case "pinColumn":
1845
+ return pinColumn2(state, action);
1846
+ case "updateColumnProp":
1847
+ return updateColumnProp(state, action);
1848
+ case "tableConfig":
1849
+ return updateTableConfig2(state, action);
1850
+ default:
1851
+ console.log(`unhandled action ${action.type}`);
1852
+ return state;
1853
+ }
1854
+ };
1855
+ var useTableModel = (tableConfigProp, dataSource) => {
1856
+ const [state, dispatchTableModelAction] = (0, import_react19.useReducer)(columnReducer, { tableConfig: tableConfigProp, dataSource }, init);
1857
+ const { columns, headings, tableConfig, ...tableAttributes } = state;
1858
+ return {
1859
+ columns,
1860
+ dispatchTableModelAction,
1861
+ headings,
1862
+ tableAttributes,
1863
+ tableConfig
1864
+ };
1865
+ };
1866
+ function init({ dataSource, tableConfig }) {
1867
+ const { columns, ...tableAttributes } = tableConfig;
1868
+ const { config: dataSourceConfig, tableSchema } = dataSource;
1869
+ const runtimeColumns = columns.filter((0, import_vuu_utils17.subscribedOnly)(dataSourceConfig == null ? void 0 : dataSourceConfig.columns)).map(
1870
+ columnDescriptorToRuntimeColumDescriptor(tableAttributes, tableSchema)
1871
+ );
1872
+ const maybePinnedColumns = runtimeColumns.some(import_vuu_utils17.isPinned) ? (0, import_vuu_utils17.sortPinnedColumns)(runtimeColumns) : runtimeColumns;
1873
+ let state = {
1874
+ columns: maybePinnedColumns,
1875
+ headings: (0, import_vuu_utils17.getTableHeadings)(maybePinnedColumns),
1876
+ tableConfig,
1877
+ ...tableAttributes
1878
+ };
1879
+ if (dataSourceConfig) {
1880
+ const { columns: _, ...rest } = dataSourceConfig;
1881
+ state = updateTableConfig2(state, {
1882
+ type: "tableConfig",
1883
+ ...rest
1884
+ });
1885
+ }
1886
+ return state;
1887
+ }
1888
+ var getLabel = (label, columnFormatHeader) => {
1889
+ if (columnFormatHeader === "uppercase") {
1890
+ return label.toUpperCase();
1891
+ } else if (columnFormatHeader === "capitalize") {
1892
+ return label[0].toUpperCase() + label.slice(1).toLowerCase();
1893
+ }
1894
+ return label;
1895
+ };
1896
+ var columnDescriptorToRuntimeColumDescriptor = (tableAttributes, tableSchema) => (column, index) => {
1897
+ const { columnDefaultWidth = DEFAULT_COLUMN_WIDTH, columnFormatHeader } = tableAttributes;
1898
+ const serverDataType = getDataType(column, tableSchema);
1899
+ const {
1900
+ align = getDefaultAlignment(serverDataType),
1901
+ name,
1902
+ label = (0, import_vuu_utils17.getColumnLabel)(column),
1903
+ width = columnDefaultWidth,
1904
+ ...rest
1905
+ } = column;
1906
+ const runtimeColumnWithDefaults = {
1907
+ ...rest,
1908
+ align,
1909
+ CellRenderer: (0, import_vuu_utils17.getCellRenderer)(column),
1910
+ HeaderCellContentRenderer: (0, import_vuu_utils17.getColumnHeaderContentRenderer)(column),
1911
+ HeaderCellLabelRenderer: (0, import_vuu_utils17.getColumnHeaderLabelRenderer)(column),
1912
+ clientSideEditValidationCheck: (0, import_vuu_utils17.hasValidationRules)(column.type) ? (0, import_vuu_ui_controls3.buildValidationChecker)(column.type.renderer.rules) : void 0,
1913
+ index: index + 1,
1914
+ label: getLabel(label, columnFormatHeader),
1915
+ name,
1916
+ originalIdx: index,
1917
+ serverDataType,
1918
+ valueFormatter: (0, import_vuu_utils17.getValueFormatter)(column, serverDataType),
1919
+ width
1920
+ };
1921
+ if ((0, import_vuu_utils17.isGroupColumn)(runtimeColumnWithDefaults)) {
1922
+ runtimeColumnWithDefaults.columns = runtimeColumnWithDefaults.columns.map(
1923
+ (col) => columnDescriptorToRuntimeColumDescriptor(tableAttributes)(col, index)
1924
+ );
1925
+ }
1926
+ return runtimeColumnWithDefaults;
1927
+ };
1928
+ function moveColumn(state, { column, moveBy }) {
1929
+ const { columns } = state;
1930
+ if (typeof moveBy === "number") {
1931
+ const idx = columns.indexOf(column);
1932
+ const newColumns = columns.slice();
1933
+ const [movedColumns] = newColumns.splice(idx, 1);
1934
+ newColumns.splice(idx + moveBy, 0, movedColumns);
1935
+ return {
1936
+ ...state,
1937
+ columns: newColumns
1938
+ };
1939
+ }
1940
+ return state;
1941
+ }
1942
+ function hideColumns(state, { columns }) {
1943
+ if (columns.some((col) => col.hidden !== true)) {
1944
+ return columns.reduce((s, c) => {
1945
+ if (c.hidden !== true) {
1946
+ return updateColumnProp(s, {
1947
+ type: "updateColumnProp",
1948
+ column: c,
1949
+ hidden: true
1950
+ });
1951
+ } else {
1952
+ return s;
1953
+ }
1954
+ }, state);
1955
+ } else {
1956
+ return state;
1957
+ }
1958
+ }
1959
+ function showColumns(state, { columns }) {
1960
+ if (columns.some((col) => col.hidden)) {
1961
+ return columns.reduce((s, c) => {
1962
+ if (c.hidden) {
1963
+ return updateColumnProp(s, {
1964
+ type: "updateColumnProp",
1965
+ column: c,
1966
+ hidden: false
1967
+ });
1968
+ } else {
1969
+ return s;
1970
+ }
1971
+ }, state);
1972
+ } else {
1973
+ return state;
1974
+ }
1975
+ }
1976
+ function resizeColumn(state, { column, phase, width }) {
1977
+ const type = "updateColumnProp";
1978
+ const resizing = phase !== "end";
1979
+ switch (phase) {
1980
+ case "begin":
1981
+ return updateColumnProp(state, { type, column, resizing });
1982
+ case "end":
1983
+ return updateColumnProp(state, { type, column, resizing, width });
1984
+ case "resize":
1985
+ return updateColumnProp(state, { type, column, width });
1986
+ default:
1987
+ throw Error(`useTableModel.resizeColumn, invalid resizePhase ${phase}`);
1988
+ }
1989
+ }
1990
+ function setTableSchema(state, { tableSchema }) {
1991
+ const { columns } = state;
1992
+ if (columns.some(columnWithoutDataType)) {
1993
+ const cols = columns.map((column) => {
1994
+ var _a;
1995
+ const serverDataType = getDataType(column, tableSchema);
1996
+ return {
1997
+ ...column,
1998
+ align: (_a = column.align) != null ? _a : getDefaultAlignment(serverDataType),
1999
+ serverDataType
2000
+ };
2001
+ });
2002
+ return {
2003
+ ...state,
2004
+ columns: cols
2005
+ };
2006
+ } else {
2007
+ return state;
2008
+ }
2009
+ }
2010
+ function pinColumn2(state, action) {
2011
+ let { columns } = state;
2012
+ const { column, pin } = action;
2013
+ const targetColumn = columns.find((col) => col.name === column.name);
2014
+ if (targetColumn) {
2015
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, pin });
2016
+ columns = (0, import_vuu_utils17.sortPinnedColumns)(columns);
2017
+ return {
2018
+ ...state,
2019
+ columns
2020
+ };
2021
+ } else {
2022
+ return state;
2023
+ }
2024
+ }
2025
+ function updateColumnProp(state, action) {
2026
+ let { columns, tableConfig } = state;
2027
+ const { align, column, hidden, label, resizing, width } = action;
2028
+ const targetColumn = columns.find((col) => col.name === column.name);
2029
+ if (targetColumn) {
2030
+ if (align === "left" || align === "right") {
2031
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, align });
2032
+ }
2033
+ if (typeof label === "string") {
2034
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, label });
2035
+ }
2036
+ if (typeof resizing === "boolean") {
2037
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, resizing });
2038
+ }
2039
+ if (typeof hidden === "boolean") {
2040
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, hidden });
2041
+ }
2042
+ if (typeof width === "number") {
2043
+ columns = (0, import_vuu_utils17.replaceColumn)(columns, { ...targetColumn, width });
2044
+ const targetConfigColumn = tableConfig.columns.find(
2045
+ (col) => col.name === column.name
2046
+ );
2047
+ if (targetConfigColumn) {
2048
+ tableConfig = {
2049
+ ...tableConfig,
2050
+ columns: (0, import_vuu_utils17.replaceColumn)(tableConfig.columns, {
2051
+ ...targetConfigColumn,
2052
+ width
2053
+ })
2054
+ };
2055
+ }
2056
+ }
2057
+ }
2058
+ return {
2059
+ ...state,
2060
+ columns,
2061
+ tableConfig
2062
+ };
2063
+ }
2064
+ function updateTableConfig2(state, { confirmed, filter, groupBy, sort }) {
2065
+ const hasGroupBy = groupBy !== void 0;
2066
+ const hasFilter = typeof (filter == null ? void 0 : filter.filter) === "string";
2067
+ const hasSort = sort && sort.sortDefs.length > 0;
2068
+ let result = state;
2069
+ if (hasGroupBy) {
2070
+ result = {
2071
+ ...state,
2072
+ columns: (0, import_vuu_utils17.applyGroupByToColumns)(result.columns, groupBy, confirmed)
2073
+ };
2074
+ }
2075
+ if (hasSort) {
2076
+ result = {
2077
+ ...state,
2078
+ columns: (0, import_vuu_utils17.applySortToColumns)(result.columns, sort)
2079
+ };
2080
+ }
2081
+ if (hasFilter) {
2082
+ result = {
2083
+ ...state,
2084
+ columns: (0, import_vuu_utils17.applyFilterToColumns)(result.columns, filter)
2085
+ };
2086
+ } else if (result.columns.some(import_vuu_utils17.isFilteredColumn)) {
2087
+ result = {
2088
+ ...state,
2089
+ columns: (0, import_vuu_utils17.stripFilterFromColumns)(result.columns)
2090
+ };
2091
+ }
2092
+ return result;
2093
+ }
2094
+
2095
+ // src/useTableScroll.ts
2096
+ var import_vuu_utils18 = require("@vuu-ui/vuu-utils");
2097
+ var import_react20 = require("react");
2098
+ var SCROLL_MOVE_CHECK_THRESHOLD = 100;
2099
+ var HORIZONTAL_SCROLL_BUFFER = 200;
2100
+ var getMaxScroll = (container) => {
2101
+ const { clientHeight, clientWidth, scrollHeight, scrollWidth } = container;
2102
+ return [scrollWidth - clientWidth, scrollHeight - clientHeight];
2103
+ };
2104
+ var getScrollDirection = (prevScrollPositions, scrollPos) => {
2105
+ if (prevScrollPositions === void 0) {
2106
+ return void 0;
2107
+ } else {
2108
+ const { scrollTop: prevTop } = prevScrollPositions;
2109
+ return scrollPos > prevTop ? "fwd" : "bwd";
2110
+ }
2111
+ };
2112
+ var getPctScroll = (container, currentScrollPos) => {
2113
+ const {
2114
+ clientHeight,
2115
+ clientWidth,
2116
+ scrollHeight,
2117
+ scrollLeft,
2118
+ scrollTop,
2119
+ scrollWidth
2120
+ } = container;
2121
+ const maxScrollLeft = scrollWidth - clientWidth;
2122
+ const pctScrollLeft = scrollLeft / (scrollWidth - clientWidth);
2123
+ const maxScrollTop = scrollHeight - clientHeight;
2124
+ let pctScrollTop = scrollTop / (scrollHeight - clientHeight);
2125
+ const scrollDirection = getScrollDirection(currentScrollPos, scrollTop);
2126
+ if (scrollDirection === "fwd" && pctScrollTop > 0.99) {
2127
+ pctScrollTop = 1;
2128
+ } else if (scrollDirection === "bwd" && pctScrollTop < 0.02) {
2129
+ pctScrollTop = 0;
2130
+ }
2131
+ return [
2132
+ scrollLeft,
2133
+ pctScrollLeft,
2134
+ maxScrollLeft,
2135
+ scrollTop,
2136
+ pctScrollTop,
2137
+ maxScrollTop
2138
+ ];
2139
+ };
2140
+ var noScrolling = {
2141
+ scrollToIndex: () => void 0,
2142
+ scrollToKey: () => void 0
2143
+ };
2144
+ var useCallbackRef = ({
2145
+ onAttach,
2146
+ onDetach
2147
+ }) => {
2148
+ const ref = (0, import_react20.useRef)(null);
2149
+ const callbackRef = (0, import_react20.useCallback)(
2150
+ (el) => {
2151
+ if (el) {
2152
+ ref.current = el;
2153
+ onAttach == null ? void 0 : onAttach(el);
2154
+ } else if (ref.current) {
2155
+ const { current: originalRef } = ref;
2156
+ ref.current = el;
2157
+ onDetach == null ? void 0 : onDetach(originalRef);
2158
+ }
2159
+ },
2160
+ [onAttach, onDetach]
2161
+ );
2162
+ return callbackRef;
2163
+ };
2164
+ var useTableScroll = ({
2165
+ columns,
2166
+ getRowAtPosition,
2167
+ onHorizontalScroll,
2168
+ onVerticalScroll,
2169
+ onVerticalScrollInSitu,
2170
+ rowHeight,
2171
+ scrollingApiRef,
2172
+ setRange,
2173
+ viewportMeasurements
2174
+ }) => {
2175
+ const firstRowRef = (0, import_react20.useRef)(0);
2176
+ const rowHeightRef = (0, import_react20.useRef)(rowHeight);
2177
+ const contentContainerScrolledRef = (0, import_react20.useRef)(false);
2178
+ const contentContainerPosRef = (0, import_react20.useRef)({
2179
+ scrollTop: 0,
2180
+ scrollLeft: 0
2181
+ });
2182
+ const scrollbarContainerScrolledRef = (0, import_react20.useRef)(false);
2183
+ const scrollbarContainerPosRef = (0, import_react20.useRef)({
2184
+ scrollTop: 0,
2185
+ scrollLeft: 0
2186
+ });
2187
+ const scrollbarContainerRef = (0, import_react20.useRef)(null);
2188
+ const contentContainerRef = (0, import_react20.useRef)(null);
2189
+ const lastHorizontalScrollCheckPoint = (0, import_react20.useRef)(0);
2190
+ const {
2191
+ appliedPageSize,
2192
+ isVirtualScroll,
2193
+ rowCount: viewportRowCount,
2194
+ totalHeaderHeight,
2195
+ viewportWidth
2196
+ } = viewportMeasurements;
2197
+ const columnsWithinViewportRef = (0, import_react20.useRef)([]);
2198
+ const [, forceRefresh] = (0, import_react20.useState)({});
2199
+ const preSpanRef = (0, import_react20.useRef)(0);
2200
+ (0, import_react20.useMemo)(() => {
2201
+ const [visibleColumns, offset] = (0, import_vuu_utils18.getColumnsInViewport)(
2202
+ columns,
2203
+ contentContainerPosRef.current.scrollLeft,
2204
+ contentContainerPosRef.current.scrollLeft + viewportWidth + HORIZONTAL_SCROLL_BUFFER
2205
+ );
2206
+ preSpanRef.current = offset;
2207
+ columnsWithinViewportRef.current = visibleColumns;
2208
+ }, [viewportWidth, columns]);
2209
+ const handleHorizontalScroll = (0, import_react20.useCallback)(
2210
+ (scrollLeft) => {
2211
+ contentContainerPosRef.current.scrollLeft = scrollLeft;
2212
+ onHorizontalScroll == null ? void 0 : onHorizontalScroll(scrollLeft);
2213
+ if (Math.abs(scrollLeft - lastHorizontalScrollCheckPoint.current) > SCROLL_MOVE_CHECK_THRESHOLD) {
2214
+ lastHorizontalScrollCheckPoint.current = scrollLeft;
2215
+ const [visibleColumns, pre] = (0, import_vuu_utils18.getColumnsInViewport)(
2216
+ columns,
2217
+ scrollLeft,
2218
+ scrollLeft + viewportWidth + HORIZONTAL_SCROLL_BUFFER
2219
+ );
2220
+ if ((0, import_vuu_utils18.itemsChanged)(columnsWithinViewportRef.current, visibleColumns)) {
2221
+ preSpanRef.current = pre;
2222
+ columnsWithinViewportRef.current = visibleColumns;
2223
+ forceRefresh({});
2224
+ }
2225
+ }
2226
+ },
2227
+ [columns, onHorizontalScroll, viewportWidth]
2228
+ );
2229
+ const handleVerticalScroll = (0, import_react20.useCallback)(
2230
+ (scrollTop, pctScrollTop) => {
2231
+ contentContainerPosRef.current.scrollTop = scrollTop;
2232
+ onVerticalScroll == null ? void 0 : onVerticalScroll(scrollTop, pctScrollTop);
2233
+ const firstRow = getRowAtPosition(scrollTop);
2234
+ if (firstRow !== firstRowRef.current) {
2235
+ firstRowRef.current = firstRow;
2236
+ setRange({ from: firstRow, to: firstRow + viewportRowCount });
2237
+ }
2238
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(0);
2239
+ },
2240
+ [
2241
+ getRowAtPosition,
2242
+ onVerticalScroll,
2243
+ onVerticalScrollInSitu,
2244
+ setRange,
2245
+ viewportRowCount
2246
+ ]
2247
+ );
2248
+ const handleScrollbarContainerScroll = (0, import_react20.useCallback)(() => {
2249
+ const { current: contentContainer } = contentContainerRef;
2250
+ const { current: scrollbarContainer } = scrollbarContainerRef;
2251
+ const { current: contentContainerScrolled } = contentContainerScrolledRef;
2252
+ const { current: scrollPos } = scrollbarContainerPosRef;
2253
+ if (contentContainerScrolled) {
2254
+ contentContainerScrolledRef.current = false;
2255
+ } else if (contentContainer && scrollbarContainer) {
2256
+ scrollbarContainerScrolledRef.current = true;
2257
+ const [scrollLeft, pctScrollLeft, , scrollTop, pctScrollTop] = getPctScroll(scrollbarContainer, scrollPos);
2258
+ scrollPos.scrollLeft = scrollLeft;
2259
+ scrollPos.scrollTop = scrollTop;
2260
+ const [maxScrollLeft, maxScrollTop] = getMaxScroll(scrollbarContainer);
2261
+ const contentScrollLeft = Math.round(pctScrollLeft * maxScrollLeft);
2262
+ const contentScrollTop = pctScrollTop * maxScrollTop;
2263
+ contentContainer.scrollTo({
2264
+ left: contentScrollLeft,
2265
+ top: contentScrollTop,
2266
+ behavior: "auto"
2267
+ });
2268
+ }
2269
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(0);
2270
+ }, [onVerticalScrollInSitu]);
2271
+ const handleContentContainerScroll = (0, import_react20.useCallback)(() => {
2272
+ const { current: scrollbarContainerScrolled } = scrollbarContainerScrolledRef;
2273
+ const { current: contentContainer } = contentContainerRef;
2274
+ const { current: scrollbarContainer } = scrollbarContainerRef;
2275
+ const { current: scrollPos } = contentContainerPosRef;
2276
+ if (contentContainer && scrollbarContainer) {
2277
+ const [
2278
+ scrollLeft,
2279
+ pctScrollLeft,
2280
+ maxScrollLeft,
2281
+ scrollTop,
2282
+ pctScrollTop,
2283
+ maxScrollTop
2284
+ ] = getPctScroll(contentContainer);
2285
+ contentContainerScrolledRef.current = true;
2286
+ if (scrollbarContainerScrolled) {
2287
+ scrollbarContainerScrolledRef.current = false;
2288
+ } else {
2289
+ scrollbarContainer.scrollLeft = Math.round(
2290
+ pctScrollLeft * maxScrollLeft
2291
+ );
2292
+ scrollbarContainer.scrollTop = pctScrollTop * maxScrollTop;
2293
+ }
2294
+ if (scrollPos.scrollTop !== scrollTop) {
2295
+ handleVerticalScroll(scrollTop, pctScrollTop);
2296
+ }
2297
+ if (scrollPos.scrollLeft !== scrollLeft) {
2298
+ handleHorizontalScroll(scrollLeft);
2299
+ }
2300
+ }
2301
+ }, [handleVerticalScroll, handleHorizontalScroll]);
2302
+ const handleAttachScrollbarContainer = (0, import_react20.useCallback)(
2303
+ (el) => {
2304
+ scrollbarContainerRef.current = el;
2305
+ el.addEventListener("scroll", handleScrollbarContainerScroll, {
2306
+ passive: true
2307
+ });
2308
+ },
2309
+ [handleScrollbarContainerScroll]
2310
+ );
2311
+ const handleDetachScrollbarContainer = (0, import_react20.useCallback)(
2312
+ (el) => {
2313
+ scrollbarContainerRef.current = null;
2314
+ el.removeEventListener("scroll", handleScrollbarContainerScroll);
2315
+ },
2316
+ [handleScrollbarContainerScroll]
2317
+ );
2318
+ const handleAttachContentContainer = (0, import_react20.useCallback)(
2319
+ (el) => {
2320
+ contentContainerRef.current = el;
2321
+ el.addEventListener("scroll", handleContentContainerScroll, {
2322
+ passive: true
2323
+ });
2324
+ },
2325
+ [handleContentContainerScroll]
2326
+ );
2327
+ const handleDetachContentContainer = (0, import_react20.useCallback)(
2328
+ (el) => {
2329
+ contentContainerRef.current = null;
2330
+ el.removeEventListener("scroll", handleContentContainerScroll);
2331
+ },
2332
+ [handleContentContainerScroll]
2333
+ );
2334
+ const contentContainerCallbackRef = useCallbackRef({
2335
+ onAttach: handleAttachContentContainer,
2336
+ onDetach: handleDetachContentContainer
2337
+ });
2338
+ const scrollbarContainerCallbackRef = useCallbackRef({
2339
+ onAttach: handleAttachScrollbarContainer,
2340
+ onDetach: handleDetachScrollbarContainer
2341
+ });
2342
+ const requestScroll = (0, import_react20.useCallback)(
2343
+ (scrollRequest) => {
2344
+ const { current: contentContainer } = contentContainerRef;
2345
+ if (contentContainer) {
2346
+ const [maxScrollLeft, maxScrollTop] = getMaxScroll(contentContainer);
2347
+ const { scrollLeft, scrollTop } = contentContainer;
2348
+ contentContainerScrolledRef.current = false;
2349
+ if (scrollRequest.type === "scroll-row") {
2350
+ const activeRow = (0, import_vuu_utils18.getRowElementAtIndex)(
2351
+ contentContainer,
2352
+ scrollRequest.rowIndex
2353
+ );
2354
+ if (activeRow !== null) {
2355
+ const [direction, distance] = howFarIsRowOutsideViewport(
2356
+ activeRow,
2357
+ totalHeaderHeight
2358
+ );
2359
+ console.log(`outside viewport ? ${direction} ${distance}`);
2360
+ if (direction && distance) {
2361
+ if (isVirtualScroll) {
2362
+ const offset = direction === "down" ? 1 : -1;
2363
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(offset);
2364
+ const firstRow = firstRowRef.current + offset;
2365
+ firstRowRef.current = firstRow;
2366
+ setRange({
2367
+ from: firstRow,
2368
+ to: firstRow + viewportRowCount
2369
+ });
2370
+ } else {
2371
+ let newScrollLeft = scrollLeft;
2372
+ let newScrollTop = scrollTop;
2373
+ if (direction === "up" || direction === "down") {
2374
+ newScrollTop = Math.min(
2375
+ Math.max(0, scrollTop + distance),
2376
+ maxScrollTop
2377
+ );
2378
+ } else {
2379
+ newScrollLeft = Math.min(
2380
+ Math.max(0, scrollLeft + distance),
2381
+ maxScrollLeft
2382
+ );
2383
+ }
2384
+ contentContainer.scrollTo({
2385
+ top: newScrollTop,
2386
+ left: newScrollLeft,
2387
+ behavior: "smooth"
2388
+ });
2389
+ }
2390
+ }
2391
+ }
2392
+ } else if (scrollRequest.type === "scroll-page") {
2393
+ const { direction } = scrollRequest;
2394
+ if (isVirtualScroll) {
2395
+ const offset = direction === "down" ? viewportRowCount : -viewportRowCount;
2396
+ onVerticalScrollInSitu == null ? void 0 : onVerticalScrollInSitu(offset);
2397
+ const firstRow = firstRowRef.current + offset;
2398
+ firstRowRef.current = firstRow;
2399
+ setRange({ from: firstRow, to: firstRow + viewportRowCount });
2400
+ } else {
2401
+ const scrollBy = direction === "down" ? appliedPageSize : -appliedPageSize;
2402
+ const newScrollTop = Math.min(
2403
+ Math.max(0, scrollTop + scrollBy),
2404
+ maxScrollTop
2405
+ );
2406
+ contentContainer.scrollTo({
2407
+ top: newScrollTop,
2408
+ left: scrollLeft,
2409
+ behavior: "auto"
2410
+ });
2411
+ }
2412
+ } else if (scrollRequest.type === "scroll-end") {
2413
+ const { direction } = scrollRequest;
2414
+ const scrollTo = direction === "end" ? maxScrollTop : 0;
2415
+ contentContainer.scrollTo({
2416
+ top: scrollTo,
2417
+ left: contentContainer.scrollLeft,
2418
+ behavior: "auto"
2419
+ });
2420
+ }
2421
+ }
2422
+ },
2423
+ [
2424
+ appliedPageSize,
2425
+ isVirtualScroll,
2426
+ onVerticalScrollInSitu,
2427
+ setRange,
2428
+ totalHeaderHeight,
2429
+ viewportRowCount
2430
+ ]
2431
+ );
2432
+ const scrollHandles = (0, import_react20.useMemo)(
2433
+ // TODO not complete yet
2434
+ () => ({
2435
+ scrollToIndex: (rowIndex) => {
2436
+ if (scrollbarContainerRef.current) {
2437
+ const scrollPos = (rowIndex - 30) * 20;
2438
+ scrollbarContainerRef.current.scrollTop = scrollPos;
2439
+ }
2440
+ },
2441
+ scrollToKey: (rowKey) => {
2442
+ console.log(`scrollToKey ${rowKey}`);
2443
+ }
2444
+ }),
2445
+ []
2446
+ );
2447
+ (0, import_react20.useImperativeHandle)(
2448
+ scrollingApiRef,
2449
+ () => {
2450
+ if (scrollbarContainerRef.current) {
2451
+ return scrollHandles;
2452
+ } else {
2453
+ return noScrolling;
2454
+ }
2455
+ },
2456
+ [scrollHandles]
2457
+ );
2458
+ (0, import_react20.useEffect)(() => {
2459
+ if (rowHeight !== rowHeightRef.current) {
2460
+ rowHeightRef.current = rowHeight;
2461
+ if (contentContainerPosRef.current.scrollTop > 0) {
2462
+ if (contentContainerRef.current) {
2463
+ contentContainerRef.current.scrollTop = 0;
2464
+ }
2465
+ }
2466
+ } else {
2467
+ const { current: from } = firstRowRef;
2468
+ const rowRange = { from, to: from + viewportRowCount };
2469
+ setRange(rowRange);
2470
+ }
2471
+ }, [rowHeight, setRange, viewportRowCount]);
2472
+ return {
2473
+ columnsWithinViewport: columnsWithinViewportRef.current,
2474
+ /** Ref to be assigned to ScrollbarContainer */
2475
+ scrollbarContainerRef: scrollbarContainerCallbackRef,
2476
+ /** Ref to be assigned to ContentContainer */
2477
+ contentContainerRef: contentContainerCallbackRef,
2478
+ /** Scroll the table */
2479
+ requestScroll,
2480
+ /** number of leading columns not rendered because of virtualization */
2481
+ virtualColSpan: preSpanRef.current
2482
+ };
2483
+ };
2484
+
2485
+ // src/useTableViewport.ts
2486
+ var import_vuu_utils19 = require("@vuu-ui/vuu-utils");
2487
+ var import_react21 = require("react");
2488
+ var MAX_PIXEL_HEIGHT = 1e7;
2489
+ var UNMEASURED_VIEWPORT = {
2490
+ appliedPageSize: 0,
2491
+ contentHeight: 0,
2492
+ contentWidth: 0,
2493
+ getRowAtPosition: () => -1,
2494
+ getRowOffset: () => -1,
2495
+ horizontalScrollbarHeight: 0,
2496
+ isVirtualScroll: false,
2497
+ pinnedWidthLeft: 0,
2498
+ pinnedWidthRight: 0,
2499
+ rowCount: 0,
2500
+ setInSituRowOffset: () => void 0,
2501
+ setScrollTop: () => void 0,
2502
+ totalHeaderHeight: 0,
2503
+ verticalScrollbarWidth: 0,
2504
+ viewportBodyHeight: 0,
2505
+ viewportWidth: 0
2506
+ };
2507
+ var useTableViewport = ({
2508
+ columns,
2509
+ headerHeight,
2510
+ headings,
2511
+ rowCount,
2512
+ rowHeight,
2513
+ selectionEndSize = 4,
2514
+ size
2515
+ }) => {
2516
+ const inSituRowOffsetRef = (0, import_react21.useRef)(0);
2517
+ const pctScrollTopRef = (0, import_react21.useRef)(0);
2518
+ const pixelContentHeight = Math.min(rowHeight * rowCount, MAX_PIXEL_HEIGHT);
2519
+ const virtualContentHeight = rowCount * rowHeight;
2520
+ const virtualisedExtent = virtualContentHeight - pixelContentHeight;
2521
+ const { pinnedWidthLeft, pinnedWidthRight, unpinnedWidth } = (0, import_react21.useMemo)(
2522
+ () => (0, import_vuu_utils19.measurePinnedColumns)(columns, selectionEndSize),
2523
+ [columns, selectionEndSize]
2524
+ );
2525
+ const totalHeaderHeightRef = (0, import_react21.useRef)(headerHeight);
2526
+ (0, import_react21.useMemo)(() => {
2527
+ totalHeaderHeightRef.current = headerHeight * (1 + headings.length);
2528
+ }, [headerHeight, headings.length]);
2529
+ const [getRowOffset, getRowAtPosition, isVirtualScroll] = (0, import_react21.useMemo)(() => {
2530
+ if (virtualisedExtent) {
2531
+ const [_getRowOffset, getRowAtPosition2, _isVirtual] = (0, import_vuu_utils19.virtualRowPositioning)(rowHeight, virtualisedExtent, pctScrollTopRef);
2532
+ const getOffset = (row) => {
2533
+ return _getRowOffset(row, inSituRowOffsetRef.current);
2534
+ };
2535
+ return [getOffset, getRowAtPosition2, _isVirtual];
2536
+ } else {
2537
+ return (0, import_vuu_utils19.actualRowPositioning)(rowHeight);
2538
+ }
2539
+ }, [virtualisedExtent, rowHeight]);
2540
+ const setScrollTop = (0, import_react21.useCallback)((_, scrollPct) => {
2541
+ pctScrollTopRef.current = scrollPct;
2542
+ }, []);
2543
+ const setInSituRowOffset = (0, import_react21.useCallback)((rowIndexOffset) => {
2544
+ if (rowIndexOffset === 0) {
2545
+ inSituRowOffsetRef.current = 0;
2546
+ } else {
2547
+ inSituRowOffsetRef.current = Math.max(
2548
+ 0,
2549
+ inSituRowOffsetRef.current + rowIndexOffset
2550
+ );
2551
+ }
2552
+ }, []);
2553
+ return (0, import_react21.useMemo)(() => {
2554
+ if (size) {
2555
+ const { current: totalHeaderHeight } = totalHeaderHeightRef;
2556
+ const scrollbarSize = 15;
2557
+ const contentWidth = pinnedWidthLeft + unpinnedWidth + pinnedWidthRight;
2558
+ const horizontalScrollbarHeight = contentWidth > size.width ? scrollbarSize : 0;
2559
+ const visibleRows = (size.height - headerHeight) / rowHeight;
2560
+ const count = Number.isInteger(visibleRows) ? visibleRows : Math.ceil(visibleRows);
2561
+ const viewportBodyHeight = size.height - totalHeaderHeight;
2562
+ const verticalScrollbarWidth = pixelContentHeight > viewportBodyHeight ? scrollbarSize : 0;
2563
+ const appliedPageSize = count * rowHeight * (pixelContentHeight / virtualContentHeight);
2564
+ const viewportWidth = size.width;
2565
+ return {
2566
+ appliedPageSize,
2567
+ contentHeight: pixelContentHeight,
2568
+ contentWidth,
2569
+ getRowAtPosition,
2570
+ getRowOffset,
2571
+ isVirtualScroll,
2572
+ horizontalScrollbarHeight,
2573
+ pinnedWidthLeft,
2574
+ pinnedWidthRight,
2575
+ rowCount: count,
2576
+ setInSituRowOffset,
2577
+ setScrollTop,
2578
+ totalHeaderHeight,
2579
+ verticalScrollbarWidth,
2580
+ viewportBodyHeight,
2581
+ viewportWidth
2582
+ };
2583
+ } else {
2584
+ return UNMEASURED_VIEWPORT;
2585
+ }
2586
+ }, [
2587
+ getRowAtPosition,
2588
+ getRowOffset,
2589
+ headerHeight,
2590
+ isVirtualScroll,
2591
+ pinnedWidthLeft,
2592
+ unpinnedWidth,
2593
+ pinnedWidthRight,
2594
+ pixelContentHeight,
2595
+ rowHeight,
2596
+ setInSituRowOffset,
2597
+ setScrollTop,
2598
+ size,
2599
+ virtualContentHeight
2600
+ ]);
2601
+ };
2602
+
2603
+ // src/useTableAndColumnSettings.ts
2604
+ var import_vuu_layout = require("@vuu-ui/vuu-layout");
2605
+ var import_vuu_utils20 = require("@vuu-ui/vuu-utils");
2606
+ var import_react22 = require("react");
2607
+ var useTableAndColumnSettings = ({
2608
+ availableColumns: availableColumnsProps,
2609
+ onAvailableColumnsChange,
2610
+ onConfigChange,
2611
+ onCreateCalculatedColumn,
2612
+ onDataSourceConfigChange,
2613
+ tableConfig
2614
+ }) => {
2615
+ const dispatchLayoutAction = (0, import_vuu_layout.useLayoutProviderDispatch)();
2616
+ const showTableSettingsRef = (0, import_react22.useRef)();
2617
+ const [availableColumns, setAvailableColumns] = (0, import_react22.useState)(
2618
+ availableColumnsProps
2619
+ );
2620
+ const showContextPanel = (0, import_react22.useCallback)(
2621
+ (componentType, title, props) => {
2622
+ dispatchLayoutAction({
2623
+ type: "set-props",
2624
+ path: "#context-panel",
2625
+ props: {
2626
+ expanded: true,
2627
+ content: {
2628
+ type: componentType,
2629
+ props
2630
+ },
2631
+ title
2632
+ }
2633
+ });
2634
+ },
2635
+ [dispatchLayoutAction]
2636
+ );
2637
+ const handleCancelCreateColumn = (0, import_react22.useCallback)(() => {
2638
+ requestAnimationFrame(() => {
2639
+ var _a;
2640
+ (_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
2641
+ });
2642
+ }, []);
2643
+ const handleCreateCalculatedColumn = (0, import_react22.useCallback)(
2644
+ (column) => {
2645
+ const newAvailableColumns = availableColumns.concat({
2646
+ name: column.name,
2647
+ serverDataType: (0, import_vuu_utils20.getCalculatedColumnType)(column)
2648
+ });
2649
+ setAvailableColumns(newAvailableColumns);
2650
+ onAvailableColumnsChange == null ? void 0 : onAvailableColumnsChange(newAvailableColumns);
2651
+ requestAnimationFrame(() => {
2652
+ var _a;
2653
+ (_a = showTableSettingsRef.current) == null ? void 0 : _a.call(showTableSettingsRef);
2654
+ });
2655
+ onCreateCalculatedColumn(column);
2656
+ },
2657
+ [availableColumns, onAvailableColumnsChange, onCreateCalculatedColumn]
2658
+ );
2659
+ const showColumnSettingsPanel = (0, import_react22.useCallback)(
2660
+ (action) => {
2661
+ showContextPanel("ColumnSettings", "Column Settings", {
2662
+ column: action.column,
2663
+ onCancelCreateColumn: handleCancelCreateColumn,
2664
+ onConfigChange,
2665
+ onCreateCalculatedColumn: handleCreateCalculatedColumn,
2666
+ tableConfig,
2667
+ vuuTable: action.vuuTable
2668
+ });
2669
+ },
2670
+ [
2671
+ handleCancelCreateColumn,
2672
+ handleCreateCalculatedColumn,
2673
+ onConfigChange,
2674
+ showContextPanel,
2675
+ tableConfig
2676
+ ]
2677
+ );
2678
+ const handleAddCalculatedColumn = (0, import_react22.useCallback)(() => {
2679
+ showColumnSettingsPanel({
2680
+ column: {
2681
+ name: "::",
2682
+ serverDataType: "string"
2683
+ },
2684
+ type: "columnSettings",
2685
+ vuuTable: { module: "SIMUL", table: "instruments" }
2686
+ });
2687
+ }, [showColumnSettingsPanel]);
2688
+ const handleNavigateToColumn = (0, import_react22.useCallback)(
2689
+ (columnName) => {
2690
+ const column = tableConfig.columns.find((c) => c.name === columnName);
2691
+ if (column) {
2692
+ showColumnSettingsPanel({
2693
+ type: "columnSettings",
2694
+ column,
2695
+ //TODO where do we get this from
2696
+ vuuTable: { module: "SIMUL", table: "instruments" }
2697
+ });
2698
+ }
2699
+ },
2700
+ [showColumnSettingsPanel, tableConfig.columns]
2701
+ );
2702
+ showTableSettingsRef.current = (0, import_react22.useCallback)(() => {
2703
+ showContextPanel("TableSettings", "DataGrid Settings", {
2704
+ availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType }) => ({
2705
+ name,
2706
+ serverDataType
2707
+ })),
2708
+ onAddCalculatedColumn: handleAddCalculatedColumn,
2709
+ onConfigChange,
2710
+ onDataSourceConfigChange,
2711
+ onNavigateToColumn: handleNavigateToColumn,
2712
+ tableConfig
2713
+ });
2714
+ }, [
2715
+ availableColumns,
2716
+ handleAddCalculatedColumn,
2717
+ handleNavigateToColumn,
2718
+ onConfigChange,
2719
+ onDataSourceConfigChange,
2720
+ showContextPanel,
2721
+ tableConfig
2722
+ ]);
2723
+ return {
2724
+ showColumnSettingsPanel,
2725
+ showTableSettingsPanel: showTableSettingsRef.current
2726
+ };
2727
+ };
2728
+
2729
+ // src/useRowClassNameGenerators.ts
2730
+ var import_vuu_utils21 = require("@vuu-ui/vuu-utils");
2731
+ var import_react23 = require("react");
2732
+ var createClassNameGenerator = (ids) => {
2733
+ const functions = [];
2734
+ ids == null ? void 0 : ids.forEach((id) => {
2735
+ const fn = (0, import_vuu_utils21.getRowClassNameGenerator)(id);
2736
+ if (fn) {
2737
+ functions.push(fn.fn);
2738
+ }
2739
+ });
2740
+ return (row, columnMap) => {
2741
+ const classNames = [];
2742
+ functions == null ? void 0 : functions.forEach((fn) => {
2743
+ const className = fn(row, columnMap);
2744
+ if (className) {
2745
+ classNames.push(className);
2746
+ }
2747
+ });
2748
+ return classNames.join(" ");
2749
+ };
2750
+ };
2751
+ var useRowClassNameGenerators = ({
2752
+ rowClassNameGenerators
2753
+ }) => {
2754
+ return (0, import_react23.useMemo)(() => {
2755
+ return createClassNameGenerator(rowClassNameGenerators);
2756
+ }, [rowClassNameGenerators]);
2757
+ };
2758
+
2759
+ // src/useTable.ts
2760
+ var stripInternalProperties = (tableConfig) => {
2761
+ return tableConfig;
2762
+ };
2763
+ var { KEY, IS_EXPANDED: IS_EXPANDED2, IS_LEAF: IS_LEAF2 } = import_vuu_utils22.metadataKeys;
2764
+ var NULL_DRAG_DROP = {
2765
+ draggable: void 0,
2766
+ onMouseDown: void 0
2767
+ };
2768
+ var useNullDragDrop = () => NULL_DRAG_DROP;
2769
+ var addColumn = (tableConfig, column) => ({
2770
+ ...tableConfig,
2771
+ columns: tableConfig.columns.concat(column)
2772
+ });
2773
+ var useTable = ({
2774
+ allowDragDrop = false,
2775
+ availableColumns,
2776
+ config,
2777
+ containerRef,
2778
+ dataSource,
2779
+ disableFocus,
2780
+ headerHeight = 25,
2781
+ highlightedIndex: highlightedIndexProp,
2782
+ id,
2783
+ navigationStyle = "cell",
2784
+ onAvailableColumnsChange,
2785
+ onConfigChange,
2786
+ onDragStart,
2787
+ onDrop,
2788
+ onFeatureInvocation,
2789
+ onHighlight,
2790
+ onRowClick: onRowClickProp,
2791
+ onSelect,
2792
+ onSelectionChange,
2793
+ renderBufferSize = 0,
2794
+ rowHeight = 20,
2795
+ scrollingApiRef,
2796
+ selectionModel,
2797
+ size
2798
+ }) => {
2799
+ const [rowCount, setRowCount] = (0, import_react24.useState)(dataSource.size);
2800
+ if (dataSource === void 0) {
2801
+ throw Error("no data source provided to Vuu Table");
2802
+ }
2803
+ const rowClassNameGenerator = useRowClassNameGenerators(config);
2804
+ const useRowDragDrop = allowDragDrop ? import_vuu_ui_controls4.useDragDrop : useNullDragDrop;
2805
+ const menuBuilder = (0, import_react24.useMemo)(
2806
+ () => buildContextMenuDescriptors(dataSource),
2807
+ [dataSource]
2808
+ );
2809
+ const onDataRowcountChange = (0, import_react24.useCallback)((size2) => {
2810
+ setRowCount(size2);
2811
+ }, []);
2812
+ const {
2813
+ columns,
2814
+ dispatchTableModelAction,
2815
+ headings,
2816
+ tableAttributes,
2817
+ tableConfig
2818
+ } = useTableModel(config, dataSource);
2819
+ (0, import_vuu_utils22.useLayoutEffectSkipFirst)(() => {
2820
+ dispatchTableModelAction({
2821
+ type: "init",
2822
+ tableConfig: config,
2823
+ dataSource
2824
+ });
2825
+ }, [config, dataSource, dispatchTableModelAction]);
2826
+ const applyTableConfigChange = (0, import_react24.useCallback)(
2827
+ (config2) => {
2828
+ dispatchTableModelAction({
2829
+ type: "init",
2830
+ tableConfig: config2,
2831
+ dataSource
2832
+ });
2833
+ onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(config2));
2834
+ },
2835
+ [dataSource, dispatchTableModelAction, onConfigChange]
2836
+ );
2837
+ const columnMap = (0, import_react24.useMemo)(
2838
+ () => (0, import_vuu_utils22.buildColumnMap)(dataSource.columns),
2839
+ [dataSource.columns]
2840
+ );
2841
+ const onSubscribed = (0, import_react24.useCallback)(
2842
+ ({ tableSchema }) => {
2843
+ if (tableSchema) {
2844
+ dispatchTableModelAction({
2845
+ type: "setTableSchema",
2846
+ tableSchema
2847
+ });
2848
+ } else {
2849
+ console.log("subscription message with no schema");
2850
+ }
2851
+ },
2852
+ [dispatchTableModelAction]
2853
+ );
2854
+ const {
2855
+ getRowAtPosition,
2856
+ getRowOffset,
2857
+ setInSituRowOffset: viewportHookSetInSituRowOffset,
2858
+ setScrollTop: viewportHookSetScrollTop,
2859
+ ...viewportMeasurements
2860
+ } = useTableViewport({
2861
+ columns,
2862
+ headerHeight,
2863
+ headings,
2864
+ rowCount,
2865
+ rowHeight,
2866
+ size
2867
+ });
2868
+ const initialRange = useInitialValue({
2869
+ from: 0,
2870
+ to: viewportMeasurements.rowCount
2871
+ });
2872
+ const { data, dataRef, getSelectedRows, range, setRange } = useDataSource({
2873
+ dataSource,
2874
+ // We need to factor this out of Table
2875
+ onFeatureInvocation,
2876
+ renderBufferSize,
2877
+ onSizeChange: onDataRowcountChange,
2878
+ onSubscribed,
2879
+ range: initialRange
2880
+ });
2881
+ const { requestScroll, ...scrollProps } = useTableScroll({
2882
+ columns,
2883
+ getRowAtPosition,
2884
+ rowHeight,
2885
+ scrollingApiRef,
2886
+ setRange,
2887
+ onVerticalScroll: viewportHookSetScrollTop,
2888
+ onVerticalScrollInSitu: viewportHookSetInSituRowOffset,
2889
+ viewportMeasurements
2890
+ });
2891
+ const handleConfigEditedInSettingsPanel = (0, import_react24.useCallback)(
2892
+ (tableConfig2) => {
2893
+ dispatchTableModelAction({
2894
+ type: "init",
2895
+ tableConfig: tableConfig2,
2896
+ dataSource
2897
+ });
2898
+ onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(tableConfig2));
2899
+ },
2900
+ [dataSource, dispatchTableModelAction, onConfigChange]
2901
+ );
2902
+ const handleDataSourceConfigChanged = (0, import_react24.useCallback)(
2903
+ (dataSourceConfig) => {
2904
+ dataSource.config = {
2905
+ ...dataSource.config,
2906
+ ...dataSourceConfig
2907
+ };
2908
+ },
2909
+ [dataSource]
2910
+ );
2911
+ (0, import_react24.useEffect)(() => {
2912
+ dataSource.on("config", (config2, confirmed, changes) => {
2913
+ const scrollSensitiveChanges = (changes == null ? void 0 : changes.filterChanged) || (changes == null ? void 0 : changes.groupByChanged);
2914
+ if (scrollSensitiveChanges && dataSource.range.from > 0) {
2915
+ requestScroll({
2916
+ type: "scroll-end",
2917
+ direction: "home"
2918
+ });
2919
+ }
2920
+ dispatchTableModelAction({
2921
+ type: "tableConfig",
2922
+ ...config2,
2923
+ confirmed
2924
+ });
2925
+ });
2926
+ }, [dataSource, dispatchTableModelAction, requestScroll]);
2927
+ const handleCreateCalculatedColumn = (0, import_react24.useCallback)(
2928
+ (column) => {
2929
+ dataSource.columns = dataSource.columns.concat(column.name);
2930
+ applyTableConfigChange(addColumn(tableConfig, column));
2931
+ },
2932
+ [dataSource, tableConfig, applyTableConfigChange]
2933
+ );
2934
+ const hideColumns2 = (0, import_react24.useCallback)(
2935
+ (action) => {
2936
+ const { columns: columns2 } = action;
2937
+ const hiddenColumns = columns2.map((c) => c.name);
2938
+ const newTableConfig = {
2939
+ ...tableConfig,
2940
+ columns: tableConfig.columns.map(
2941
+ (col) => hiddenColumns.includes(col.name) ? { ...col, hidden: true } : col
2942
+ )
2943
+ };
2944
+ applyTableConfigChange(newTableConfig);
2945
+ },
2946
+ [tableConfig, applyTableConfigChange]
2947
+ );
2948
+ const pinColumn3 = (0, import_react24.useCallback)(
2949
+ (action) => {
2950
+ applyTableConfigChange({
2951
+ ...tableConfig,
2952
+ columns: (0, import_vuu_utils22.updateColumn)(tableConfig.columns, {
2953
+ ...action.column,
2954
+ pin: action.pin
2955
+ })
2956
+ });
2957
+ },
2958
+ [tableConfig, applyTableConfigChange]
2959
+ );
2960
+ const { showColumnSettingsPanel, showTableSettingsPanel } = useTableAndColumnSettings({
2961
+ availableColumns: availableColumns != null ? availableColumns : tableConfig.columns.map(({ name, serverDataType = "string" }) => ({
2962
+ name,
2963
+ serverDataType
2964
+ })),
2965
+ onAvailableColumnsChange,
2966
+ onConfigChange: handleConfigEditedInSettingsPanel,
2967
+ onCreateCalculatedColumn: handleCreateCalculatedColumn,
2968
+ onDataSourceConfigChange: handleDataSourceConfigChanged,
2969
+ tableConfig
2970
+ });
2971
+ const onPersistentColumnOperation = (0, import_react24.useCallback)(
2972
+ (action) => {
2973
+ if (isShowColumnSettings(action)) {
2974
+ showColumnSettingsPanel(action);
2975
+ } else if (isShowTableSettings(action)) {
2976
+ showTableSettingsPanel();
2977
+ } else {
2978
+ switch (action.type) {
2979
+ case "hideColumns":
2980
+ return hideColumns2(action);
2981
+ case "pinColumn":
2982
+ return pinColumn3(action);
2983
+ default:
2984
+ dispatchTableModelAction(action);
2985
+ }
2986
+ }
2987
+ },
2988
+ [
2989
+ dispatchTableModelAction,
2990
+ hideColumns2,
2991
+ pinColumn3,
2992
+ showColumnSettingsPanel,
2993
+ showTableSettingsPanel
2994
+ ]
2995
+ );
2996
+ const handleContextMenuAction = useHandleTableContextMenu({
2997
+ dataSource,
2998
+ onPersistentColumnOperation
2999
+ });
3000
+ const handleSort = (0, import_react24.useCallback)(
3001
+ (column, extendSort = false, sortType) => {
3002
+ if (dataSource) {
3003
+ dataSource.sort = (0, import_vuu_utils22.applySort)(
3004
+ dataSource.sort,
3005
+ column,
3006
+ extendSort,
3007
+ sortType
3008
+ );
3009
+ }
3010
+ },
3011
+ [dataSource]
3012
+ );
3013
+ const resizeCells = (0, import_react24.useRef)();
3014
+ const onResizeColumn = (0, import_react24.useCallback)(
3015
+ (phase, columnName, width) => {
3016
+ var _a, _b, _c;
3017
+ const column = columns.find((column2) => column2.name === columnName);
3018
+ if (column) {
3019
+ if (phase === "resize") {
3020
+ (_a = resizeCells.current) == null ? void 0 : _a.forEach((cell) => {
3021
+ cell.style.width = `${width}px`;
3022
+ });
3023
+ } else if (phase === "end") {
3024
+ resizeCells.current = void 0;
3025
+ if ((0, import_vuu_utils22.isValidNumber)(width)) {
3026
+ dispatchTableModelAction({
3027
+ type: "resizeColumn",
3028
+ phase,
3029
+ column,
3030
+ width
3031
+ });
3032
+ onConfigChange == null ? void 0 : onConfigChange(
3033
+ stripInternalProperties(
3034
+ updateTableConfig(tableConfig, {
3035
+ type: "col-size",
3036
+ column,
3037
+ width
3038
+ })
3039
+ )
3040
+ );
3041
+ }
3042
+ } else {
3043
+ const byColIndex = `[aria-colindex='${column.index}']`;
3044
+ resizeCells.current = Array.from(
3045
+ (_c = (_b = containerRef.current) == null ? void 0 : _b.querySelectorAll(
3046
+ `.vuuTableCell${byColIndex},.vuuTableHeaderCell${byColIndex}`
3047
+ )) != null ? _c : []
3048
+ );
3049
+ dispatchTableModelAction({
3050
+ type: "resizeColumn",
3051
+ phase,
3052
+ column,
3053
+ width
3054
+ });
3055
+ }
3056
+ } else {
3057
+ throw Error(
3058
+ `useDataTable.handleColumnResize, column ${columnName} not found`
3059
+ );
3060
+ }
3061
+ },
3062
+ [
3063
+ columns,
3064
+ dispatchTableModelAction,
3065
+ onConfigChange,
3066
+ tableConfig,
3067
+ containerRef
3068
+ ]
3069
+ );
3070
+ const onToggleGroup = (0, import_react24.useCallback)(
3071
+ (row, column) => {
3072
+ var _a, _b;
3073
+ const isJson = (0, import_vuu_utils22.isJsonGroup)(column, row, columnMap);
3074
+ const key = row[KEY];
3075
+ if (row[IS_EXPANDED2]) {
3076
+ dataSource.closeTreeNode(key, true);
3077
+ if (isJson) {
3078
+ const idx = columns.indexOf(column);
3079
+ const rows = (_a = dataSource.getRowsAtDepth) == null ? void 0 : _a.call(dataSource, idx + 1);
3080
+ if (rows && !rows.some((row2) => row2[IS_EXPANDED2] || row2[IS_LEAF2])) {
3081
+ dispatchTableModelAction({
3082
+ type: "hideColumns",
3083
+ columns: columns.slice(idx + 2)
3084
+ });
3085
+ }
3086
+ }
3087
+ } else {
3088
+ dataSource.openTreeNode(key);
3089
+ if (isJson) {
3090
+ const childRows = (_b = dataSource.getChildRows) == null ? void 0 : _b.call(dataSource, key);
3091
+ const idx = columns.indexOf(column) + 1;
3092
+ const columnsToShow = [columns[idx]];
3093
+ if (childRows && childRows.some((row2) => row2[IS_LEAF2])) {
3094
+ columnsToShow.push(columns[idx + 1]);
3095
+ }
3096
+ if (columnsToShow.some((col) => col.hidden)) {
3097
+ dispatchTableModelAction({
3098
+ type: "showColumns",
3099
+ columns: columnsToShow
3100
+ });
3101
+ }
3102
+ }
3103
+ }
3104
+ },
3105
+ [columnMap, columns, dataSource, dispatchTableModelAction]
3106
+ );
3107
+ const {
3108
+ highlightedIndexRef,
3109
+ navigate,
3110
+ onFocus: navigationFocus,
3111
+ onKeyDown: navigationKeyDown,
3112
+ ...containerProps
3113
+ } = useKeyboardNavigation({
3114
+ columnCount: columns.filter((c) => c.hidden !== true).length,
3115
+ containerRef,
3116
+ disableFocus,
3117
+ highlightedIndex: highlightedIndexProp,
3118
+ navigationStyle,
3119
+ requestScroll,
3120
+ rowCount: dataSource == null ? void 0 : dataSource.size,
3121
+ onHighlight,
3122
+ viewportRange: range,
3123
+ viewportRowCount: viewportMeasurements.rowCount
3124
+ });
3125
+ const {
3126
+ onBlur: editingBlur,
3127
+ onDoubleClick: editingDoubleClick,
3128
+ onKeyDown: editingKeyDown,
3129
+ onFocus: editingFocus
3130
+ } = useCellEditing({
3131
+ navigate
3132
+ });
3133
+ const handleFocus = (0, import_react24.useCallback)(
3134
+ (e) => {
3135
+ navigationFocus();
3136
+ if (!e.defaultPrevented) {
3137
+ editingFocus(e);
3138
+ }
3139
+ },
3140
+ [editingFocus, navigationFocus]
3141
+ );
3142
+ const onContextMenu = useTableContextMenu({
3143
+ columns,
3144
+ data,
3145
+ dataSource,
3146
+ getSelectedRows
3147
+ });
3148
+ const onMoveGroupColumn = (0, import_react24.useCallback)(
3149
+ (columns2) => {
3150
+ dataSource.groupBy = columns2.map((col) => col.name);
3151
+ },
3152
+ [dataSource]
3153
+ );
3154
+ const onRemoveGroupColumn = (0, import_react24.useCallback)(
3155
+ (column) => {
3156
+ if ((0, import_vuu_utils22.isGroupColumn)(column)) {
3157
+ dataSource.groupBy = [];
3158
+ } else {
3159
+ if (dataSource && dataSource.groupBy.includes(column.name)) {
3160
+ dataSource.groupBy = dataSource.groupBy.filter(
3161
+ (columnName) => columnName !== column.name
3162
+ );
3163
+ }
3164
+ }
3165
+ },
3166
+ [dataSource]
3167
+ );
3168
+ const handleSelectionChange = (0, import_react24.useCallback)(
3169
+ (selected) => {
3170
+ dataSource.select(selected);
3171
+ onSelectionChange == null ? void 0 : onSelectionChange(selected);
3172
+ },
3173
+ [dataSource, onSelectionChange]
3174
+ );
3175
+ const handleSelect = (0, import_react24.useCallback)(
3176
+ (row) => {
3177
+ if (onSelect) {
3178
+ onSelect(row === null ? null : (0, import_vuu_utils22.asDataSourceRowObject)(row, columnMap));
3179
+ }
3180
+ },
3181
+ [columnMap, onSelect]
3182
+ );
3183
+ const {
3184
+ onKeyDown: selectionHookKeyDown,
3185
+ onRowClick: selectionHookOnRowClick
3186
+ } = useSelection({
3187
+ highlightedIndexRef,
3188
+ onSelect: handleSelect,
3189
+ onSelectionChange: handleSelectionChange,
3190
+ selectionModel
3191
+ });
3192
+ const handleRowClick = (0, import_react24.useCallback)(
3193
+ (evt, row, rangeSelect, keepExistingSelection) => {
3194
+ selectionHookOnRowClick(evt, row, rangeSelect, keepExistingSelection);
3195
+ onRowClickProp == null ? void 0 : onRowClickProp(evt, (0, import_vuu_utils22.asDataSourceRowObject)(row, columnMap));
3196
+ },
3197
+ [columnMap, onRowClickProp, selectionHookOnRowClick]
3198
+ );
3199
+ const handleKeyDown = (0, import_react24.useCallback)(
3200
+ (e) => {
3201
+ navigationKeyDown(e);
3202
+ if (!e.defaultPrevented) {
3203
+ editingKeyDown(e);
3204
+ }
3205
+ if (!e.defaultPrevented) {
3206
+ selectionHookKeyDown(e);
3207
+ }
3208
+ },
3209
+ [navigationKeyDown, editingKeyDown, selectionHookKeyDown]
3210
+ );
3211
+ const onMoveColumn = (0, import_react24.useCallback)(
3212
+ (columns2) => {
3213
+ const newTableConfig = {
3214
+ ...tableConfig,
3215
+ columns: columns2
3216
+ };
3217
+ dispatchTableModelAction({
3218
+ type: "init",
3219
+ tableConfig: newTableConfig,
3220
+ dataSource
3221
+ });
3222
+ onConfigChange == null ? void 0 : onConfigChange(stripInternalProperties(newTableConfig));
3223
+ },
3224
+ [dataSource, dispatchTableModelAction, onConfigChange, tableConfig]
3225
+ );
3226
+ const handleDropRow = (0, import_react24.useCallback)(
3227
+ (dragDropState) => {
3228
+ onDrop == null ? void 0 : onDrop(dragDropState);
3229
+ },
3230
+ [onDrop]
3231
+ );
3232
+ const handleDataEdited = (0, import_react24.useCallback)(
3233
+ async (row, columnName, value) => dataSource.applyEdit(row, columnName, value),
3234
+ [dataSource]
3235
+ );
3236
+ const handleDragStartRow = (0, import_react24.useCallback)(
3237
+ (dragDropState) => {
3238
+ const { initialDragElement } = dragDropState;
3239
+ const rowIndex = (0, import_vuu_utils22.getIndexFromRowElement)(initialDragElement);
3240
+ const row = dataRef.current.find((row2) => row2[0] === rowIndex);
3241
+ if (row) {
3242
+ dragDropState.setPayload(row);
3243
+ } else {
3244
+ }
3245
+ onDragStart == null ? void 0 : onDragStart(dragDropState);
3246
+ },
3247
+ [dataRef, onDragStart]
3248
+ );
3249
+ const { onMouseDown: rowDragMouseDown, draggable: draggableRow } = useRowDragDrop({
3250
+ allowDragDrop,
3251
+ containerRef,
3252
+ draggableClassName: `vuuTable`,
3253
+ id,
3254
+ onDragStart: handleDragStartRow,
3255
+ onDrop: handleDropRow,
3256
+ orientation: "vertical",
3257
+ itemQuery: ".vuuTableRow"
3258
+ });
3259
+ return {
3260
+ ...containerProps,
3261
+ "aria-rowcount": dataSource.size,
3262
+ rowClassNameGenerator,
3263
+ draggableRow,
3264
+ onBlur: editingBlur,
3265
+ onDoubleClick: editingDoubleClick,
3266
+ onFocus: handleFocus,
3267
+ onKeyDown: handleKeyDown,
3268
+ onMouseDown: rowDragMouseDown,
3269
+ columnMap,
3270
+ columns,
3271
+ data,
3272
+ getRowOffset,
3273
+ handleContextMenuAction,
3274
+ headings,
3275
+ highlightedIndex: highlightedIndexRef.current,
3276
+ menuBuilder,
3277
+ onContextMenu,
3278
+ onDataEdited: handleDataEdited,
3279
+ onMoveColumn,
3280
+ onMoveGroupColumn,
3281
+ onRemoveGroupColumn,
3282
+ onRowClick: handleRowClick,
3283
+ onSortColumn: handleSort,
3284
+ onResizeColumn,
3285
+ onToggleGroup,
3286
+ scrollProps,
3287
+ // TODO don't think we need these ...
3288
+ tableAttributes,
3289
+ tableConfig,
3290
+ viewportMeasurements
3291
+ };
3292
+ };
3293
+
3294
+ // src/useRowHeight.ts
3295
+ var import_vuu_utils23 = require("@vuu-ui/vuu-utils");
3296
+ var import_react25 = require("react");
3297
+ var useRowHeight = ({
3298
+ rowHeight: rowHeightProp = 0
3299
+ }) => {
3300
+ const [rowHeight, setRowHeight] = (0, import_react25.useState)(rowHeightProp);
3301
+ const heightRef = (0, import_react25.useRef)(rowHeight);
3302
+ const resizeObserver = (0, import_react25.useMemo)(() => {
3303
+ return new ResizeObserver((entries) => {
3304
+ for (const entry of entries) {
3305
+ const [{ blockSize: measuredSize }] = entry.borderBoxSize;
3306
+ const newHeight = Math.round(measuredSize);
3307
+ if ((0, import_vuu_utils23.isValidNumber)(newHeight) && heightRef.current !== newHeight) {
3308
+ heightRef.current = newHeight;
3309
+ setRowHeight(newHeight);
3310
+ }
3311
+ }
3312
+ });
3313
+ }, []);
3314
+ const rowRef = (0, import_react25.useCallback)(
3315
+ (el) => {
3316
+ if (el) {
3317
+ if (rowHeightProp === 0) {
3318
+ const { height } = el.getBoundingClientRect();
3319
+ console.log({ boundingClientHeight: height });
3320
+ console.log(`measured rowHeight = ${height} (${rowHeightProp})`);
3321
+ resizeObserver.observe(el);
3322
+ setRowHeight(height);
3323
+ }
3324
+ } else {
3325
+ resizeObserver.disconnect();
3326
+ }
3327
+ },
3328
+ [resizeObserver, rowHeightProp]
3329
+ );
3330
+ return { rowHeight, rowRef };
3331
+ };
3332
+
3333
+ // src/Table.tsx
3334
+ var import_jsx_runtime12 = require("react/jsx-runtime");
3335
+ var classBase8 = "vuuTable";
3336
+ var { IDX: IDX3, RENDER_IDX } = import_vuu_utils24.metadataKeys;
3337
+ var TableCore = ({
3338
+ Row: Row2 = Row,
3339
+ allowDragDrop,
3340
+ availableColumns,
3341
+ config,
3342
+ containerRef,
3343
+ dataSource,
3344
+ disableFocus = false,
3345
+ highlightedIndex: highlightedIndexProp,
3346
+ id: idProp,
3347
+ navigationStyle = "cell",
3348
+ onAvailableColumnsChange,
3349
+ onConfigChange,
3350
+ onDragStart,
3351
+ onDrop,
3352
+ onFeatureInvocation,
3353
+ onHighlight,
3354
+ onRowClick: onRowClickProp,
3355
+ onSelect,
3356
+ onSelectionChange,
3357
+ renderBufferSize = 5,
3358
+ rowHeight,
3359
+ scrollingApiRef,
3360
+ selectionModel = "extended",
3361
+ showColumnHeaders = true,
3362
+ headerHeight = showColumnHeaders ? rowHeight * 1.25 : 0,
3363
+ size
3364
+ }) => {
3365
+ const id = (0, import_vuu_utils24.useId)(idProp);
3366
+ const {
3367
+ columnMap,
3368
+ columns,
3369
+ data,
3370
+ draggableRow,
3371
+ getRowOffset,
3372
+ handleContextMenuAction,
3373
+ headings,
3374
+ highlightedIndex,
3375
+ menuBuilder,
3376
+ onDataEdited,
3377
+ onMoveColumn,
3378
+ onMoveGroupColumn,
3379
+ onRemoveGroupColumn,
3380
+ onResizeColumn,
3381
+ onRowClick,
3382
+ onSortColumn,
3383
+ onToggleGroup,
3384
+ rowClassNameGenerator,
3385
+ scrollProps,
3386
+ tableAttributes,
3387
+ tableConfig,
3388
+ viewportMeasurements,
3389
+ ...tableProps
3390
+ } = useTable({
3391
+ allowDragDrop,
3392
+ availableColumns,
3393
+ config,
3394
+ containerRef,
3395
+ dataSource,
3396
+ disableFocus,
3397
+ headerHeight,
3398
+ highlightedIndex: highlightedIndexProp,
3399
+ id,
3400
+ navigationStyle,
3401
+ onAvailableColumnsChange,
3402
+ onConfigChange,
3403
+ onDragStart,
3404
+ onDrop,
3405
+ onFeatureInvocation,
3406
+ onHighlight,
3407
+ onRowClick: onRowClickProp,
3408
+ onSelect,
3409
+ onSelectionChange,
3410
+ renderBufferSize: Math.max(5, renderBufferSize),
3411
+ rowHeight,
3412
+ scrollingApiRef,
3413
+ selectionModel,
3414
+ size
3415
+ });
3416
+ const contentContainerClassName = (0, import_clsx9.default)(`${classBase8}-contentContainer`, {
3417
+ [`${classBase8}-colLines`]: tableAttributes.columnSeparators,
3418
+ [`${classBase8}-rowLines`]: tableAttributes.rowSeparators,
3419
+ [`${classBase8}-zebra`]: tableAttributes.zebraStripes
3420
+ });
3421
+ const cssVariables = {
3422
+ "--content-height": `${viewportMeasurements.contentHeight}px`,
3423
+ "--content-width": `${viewportMeasurements.contentWidth}px`,
3424
+ "--horizontal-scrollbar-height": `${viewportMeasurements.horizontalScrollbarHeight}px`,
3425
+ "--pinned-width-left": `${viewportMeasurements.pinnedWidthLeft}px`,
3426
+ "--pinned-width-right": `${viewportMeasurements.pinnedWidthRight}px`,
3427
+ "--header-height": `${headerHeight}px`,
3428
+ "--row-height-prop": `${rowHeight}px`,
3429
+ "--total-header-height": `${viewportMeasurements.totalHeaderHeight}px`,
3430
+ "--vertical-scrollbar-width": `${viewportMeasurements.verticalScrollbarWidth}px`,
3431
+ "--viewport-body-height": `${viewportMeasurements.viewportBodyHeight}px`
3432
+ };
3433
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3434
+ import_vuu_popups3.ContextMenuProvider,
3435
+ {
3436
+ menuActionHandler: handleContextMenuAction,
3437
+ menuBuilder,
3438
+ children: [
3439
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3440
+ "div",
3441
+ {
3442
+ className: `${classBase8}-scrollbarContainer`,
3443
+ ref: scrollProps.scrollbarContainerRef,
3444
+ style: cssVariables,
3445
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${classBase8}-scrollbarContent` })
3446
+ }
3447
+ ),
3448
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3449
+ "div",
3450
+ {
3451
+ className: contentContainerClassName,
3452
+ ref: scrollProps.contentContainerRef,
3453
+ style: cssVariables,
3454
+ children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3455
+ "div",
3456
+ {
3457
+ ...tableProps,
3458
+ className: `${classBase8}-table`,
3459
+ role: "table",
3460
+ tabIndex: disableFocus ? void 0 : -1,
3461
+ children: [
3462
+ showColumnHeaders ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3463
+ TableHeader,
3464
+ {
3465
+ columns: scrollProps.columnsWithinViewport,
3466
+ headings,
3467
+ onMoveColumn,
3468
+ onMoveGroupColumn,
3469
+ onRemoveGroupColumn,
3470
+ onResizeColumn,
3471
+ onSortColumn,
3472
+ tableConfig,
3473
+ tableId: id,
3474
+ virtualColSpan: scrollProps.virtualColSpan
3475
+ }
3476
+ ) : null,
3477
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("div", { className: `${classBase8}-body`, children: data.map((data2) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3478
+ Row2,
3479
+ {
3480
+ "aria-rowindex": data2[0] + 1,
3481
+ classNameGenerator: rowClassNameGenerator,
3482
+ columnMap,
3483
+ columns: scrollProps.columnsWithinViewport,
3484
+ highlighted: highlightedIndex === data2[IDX3],
3485
+ onClick: onRowClick,
3486
+ onDataEdited,
3487
+ row: data2,
3488
+ offset: getRowOffset(data2),
3489
+ onToggleGroup,
3490
+ virtualColSpan: scrollProps.virtualColSpan,
3491
+ zebraStripes: tableAttributes.zebraStripes
3492
+ },
3493
+ data2[RENDER_IDX]
3494
+ )) })
3495
+ ]
3496
+ }
3497
+ )
3498
+ }
3499
+ ),
3500
+ draggableRow
3501
+ ]
3502
+ }
3503
+ );
3504
+ };
3505
+ var Table = (0, import_react26.forwardRef)(function TableNext({
3506
+ Row: Row2,
3507
+ allowDragDrop,
3508
+ availableColumns,
3509
+ className: classNameProp,
3510
+ config,
3511
+ dataSource,
3512
+ disableFocus,
3513
+ highlightedIndex,
3514
+ id,
3515
+ navigationStyle,
3516
+ onAvailableColumnsChange,
3517
+ onConfigChange,
3518
+ onDragStart,
3519
+ onDrop,
3520
+ onFeatureInvocation,
3521
+ onHighlight,
3522
+ onRowClick,
3523
+ onSelect,
3524
+ onSelectionChange,
3525
+ renderBufferSize,
3526
+ rowHeight: rowHeightProp,
3527
+ scrollingApiRef,
3528
+ selectionModel,
3529
+ showColumnHeaders,
3530
+ headerHeight,
3531
+ style: styleProp,
3532
+ ...htmlAttributes
3533
+ }, forwardedRef) {
3534
+ const containerRef = (0, import_react26.useRef)(null);
3535
+ const [size, setSize] = (0, import_react26.useState)();
3536
+ const { rowHeight, rowRef } = useRowHeight({ rowHeight: rowHeightProp });
3537
+ if (config === void 0) {
3538
+ throw Error(
3539
+ "vuu Table requires config prop. Minimum config is list of Column Descriptors"
3540
+ );
3541
+ }
3542
+ if (dataSource === void 0) {
3543
+ throw Error("vuu Table requires dataSource prop");
3544
+ }
3545
+ console.log({ rowHeight });
3546
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
3547
+ import_vuu_ui_controls5.MeasuredContainer,
3548
+ {
3549
+ ...htmlAttributes,
3550
+ className: (0, import_clsx9.default)(classBase8, classNameProp),
3551
+ id,
3552
+ onResize: setSize,
3553
+ ref: (0, import_core2.useForkRef)(containerRef, forwardedRef),
3554
+ children: [
3555
+ /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(RowProxy, { ref: rowRef, height: rowHeightProp }),
3556
+ size && rowHeight ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
3557
+ TableCore,
3558
+ {
3559
+ Row: Row2,
3560
+ allowDragDrop,
3561
+ availableColumns,
3562
+ config,
3563
+ containerRef,
3564
+ dataSource,
3565
+ disableFocus,
3566
+ headerHeight,
3567
+ highlightedIndex,
3568
+ id,
3569
+ navigationStyle,
3570
+ onAvailableColumnsChange,
3571
+ onConfigChange,
3572
+ onDragStart,
3573
+ onDrop,
3574
+ onFeatureInvocation,
3575
+ onHighlight,
3576
+ onRowClick,
3577
+ onSelect,
3578
+ onSelectionChange,
3579
+ renderBufferSize,
3580
+ rowHeight,
3581
+ scrollingApiRef,
3582
+ selectionModel,
3583
+ showColumnHeaders,
3584
+ size
3585
+ }
3586
+ ) : null
3587
+ ]
3588
+ }
3589
+ );
3590
+ });
3591
+
3592
+ // src/cell-renderers/checkbox-cell/CheckboxCell.tsx
3593
+ var import_react27 = require("react");
3594
+ var import_vuu_ui_controls6 = require("@vuu-ui/vuu-ui-controls");
3595
+ var import_core3 = require("@salt-ds/core");
3596
+ var import_vuu_utils25 = require("@vuu-ui/vuu-utils");
3597
+ var import_jsx_runtime13 = require("react/jsx-runtime");
3598
+ var CheckboxCell = (0, import_react27.memo)(
3599
+ ({ column, columnMap, onCommit = import_vuu_ui_controls6.WarnCommit, row }) => {
3600
+ const dataIdx = columnMap[column.name];
3601
+ const isChecked = !!row[dataIdx];
3602
+ const handleCommit = (0, import_react27.useCallback)(
3603
+ (value) => async (evt) => {
3604
+ const res = await onCommit(value);
3605
+ if (res === true) {
3606
+ (0, import_vuu_utils25.dispatchCustomEvent)(evt.target, "vuu-commit");
3607
+ }
3608
+ return res;
3609
+ },
3610
+ [onCommit]
3611
+ );
3612
+ 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 });
3613
+ },
3614
+ import_vuu_utils25.dataColumnAndKeyUnchanged
3615
+ );
3616
+ CheckboxCell.displayName = "CheckboxCell";
3617
+ (0, import_vuu_utils25.registerComponent)("checkbox-cell", CheckboxCell, "cell-renderer", {
3618
+ serverDataType: "boolean"
3619
+ });
3620
+
3621
+ // src/cell-renderers/input-cell/InputCell.tsx
3622
+ var import_vuu_utils26 = require("@vuu-ui/vuu-utils");
3623
+ var import_core4 = require("@salt-ds/core");
3624
+ var import_vuu_ui_controls7 = require("@vuu-ui/vuu-ui-controls");
3625
+ var import_clsx10 = __toESM(require("clsx"));
3626
+ var import_jsx_runtime14 = require("react/jsx-runtime");
3627
+ var classBase9 = "vuuTableInputCell";
3628
+ var WarnCommit2 = () => {
3629
+ console.warn(
3630
+ "onCommit handler has not been provided to InputCell cell renderer"
3631
+ );
3632
+ return Promise.resolve(true);
3633
+ };
3634
+ var InputCell = ({
3635
+ column,
3636
+ columnMap,
3637
+ onCommit = WarnCommit2,
3638
+ row
3639
+ }) => {
3640
+ const dataIdx = columnMap[column.name];
3641
+ const dataValue = row[dataIdx];
3642
+ const { align = "left", clientSideEditValidationCheck } = column;
3643
+ const { warningMessage, ...editProps } = (0, import_vuu_ui_controls7.useEditableText)({
3644
+ initialValue: dataValue,
3645
+ onCommit,
3646
+ clientSideEditValidationCheck
3647
+ });
3648
+ const endAdornment = warningMessage && align === "left" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `${classBase9}-icon`, "data-icon": "error" }) : void 0;
3649
+ const startAdornment = warningMessage && align === "right" ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { className: `${classBase9}-icon`, "data-icon": "error" }) : void 0;
3650
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
3651
+ import_core4.Input,
3652
+ {
3653
+ ...editProps,
3654
+ className: (0, import_clsx10.default)(classBase9, {
3655
+ [`${classBase9}-error`]: warningMessage !== void 0
3656
+ }),
3657
+ endAdornment,
3658
+ startAdornment
3659
+ }
3660
+ );
3661
+ };
3662
+ (0, import_vuu_utils26.registerComponent)("input-cell", InputCell, "cell-renderer", {
3663
+ userCanAssign: false
3664
+ });
3665
+
3666
+ // src/cell-renderers/toggle-cell/ToggleCell.tsx
3667
+ var import_vuu_ui_controls8 = require("@vuu-ui/vuu-ui-controls");
3668
+ var import_vuu_utils27 = require("@vuu-ui/vuu-utils");
3669
+ var import_clsx11 = __toESM(require("clsx"));
3670
+ var import_react28 = require("react");
3671
+ var import_vuu_ui_controls9 = require("@vuu-ui/vuu-ui-controls");
3672
+ var import_jsx_runtime15 = require("react/jsx-runtime");
3673
+ var classBase10 = "vuuTableToggleCell";
3674
+ var getValueList = ({ name, type }) => {
3675
+ if ((0, import_vuu_utils27.isTypeDescriptor)(type) && (0, import_vuu_utils27.isValueListRenderer)(type.renderer)) {
3676
+ return type.renderer.values;
3677
+ } else {
3678
+ throw Error(
3679
+ `useLookupValues column ${name} has not been configured with a values list`
3680
+ );
3681
+ }
3682
+ };
3683
+ var ToggleCell = (0, import_react28.memo)(
3684
+ function ToggleCell2({
3685
+ column,
3686
+ columnMap,
3687
+ onCommit = import_vuu_ui_controls8.WarnCommit,
3688
+ row
3689
+ }) {
3690
+ const values = getValueList(column);
3691
+ const dataIdx = columnMap[column.name];
3692
+ const value = row[dataIdx];
3693
+ const handleCommit = (0, import_react28.useCallback)(
3694
+ (evt, value2) => {
3695
+ return onCommit(value2).then((response) => {
3696
+ if (response === true) {
3697
+ (0, import_vuu_utils27.dispatchCustomEvent)(evt.target, "vuu-commit");
3698
+ }
3699
+ return response;
3700
+ });
3701
+ },
3702
+ [onCommit]
3703
+ );
3704
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
3705
+ import_vuu_ui_controls9.CycleStateButton,
3706
+ {
3707
+ className: (0, import_clsx11.default)(classBase10, `${classBase10}-${column.name}`),
3708
+ onCommit: handleCommit,
3709
+ value,
3710
+ values,
3711
+ variant: "cta",
3712
+ children: value
3713
+ }
3714
+ );
3715
+ },
3716
+ import_vuu_utils27.dataColumnAndKeyUnchanged
3717
+ );
3718
+ (0, import_vuu_utils27.registerComponent)("toggle-cell", ToggleCell, "cell-renderer", {
3719
+ userCanAssign: false
3720
+ });
3721
+
3722
+ // src/useControlledTableNavigation.ts
3723
+ var import_vuu_ui_controls10 = require("@vuu-ui/vuu-ui-controls");
3724
+ var import_vuu_utils28 = require("@vuu-ui/vuu-utils");
3725
+ var import_react29 = require("react");
3726
+ var useControlledTableNavigation = (initialValue, rowCount) => {
3727
+ const tableRef = (0, import_react29.useRef)(null);
3728
+ const [highlightedIndexRef, setHighlightedIndex] = (0, import_vuu_ui_controls10.useStateRef)(initialValue);
3729
+ const handleKeyDown = (0, import_react29.useCallback)(
3730
+ (e) => {
3731
+ var _a;
3732
+ if (e.key === "ArrowDown") {
3733
+ setHighlightedIndex((index = -1) => Math.min(rowCount - 1, index + 1));
3734
+ } else if (e.key === "ArrowUp") {
3735
+ setHighlightedIndex((index = -1) => Math.max(0, index - 1));
3736
+ } else if (e.key === "Enter" || e.key === " ") {
3737
+ const { current: rowIdx } = highlightedIndexRef;
3738
+ const rowEl = (_a = tableRef.current) == null ? void 0 : _a.querySelector(
3739
+ `[aria-rowindex="${rowIdx}"]`
3740
+ );
3741
+ if (rowEl) {
3742
+ (0, import_vuu_utils28.dispatchMouseEvent)(rowEl, "click");
3743
+ }
3744
+ }
3745
+ },
3746
+ [highlightedIndexRef, rowCount, setHighlightedIndex]
3747
+ );
3748
+ const handleHighlight = (0, import_react29.useCallback)(
3749
+ (idx) => {
3750
+ setHighlightedIndex(idx);
3751
+ },
3752
+ [setHighlightedIndex]
3753
+ );
3754
+ return {
3755
+ highlightedIndexRef,
3756
+ onHighlight: handleHighlight,
3757
+ onKeyDown: handleKeyDown,
3758
+ tableRef
3759
+ };
3760
+ };
2
3761
  //# sourceMappingURL=index.js.map