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