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