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