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