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