@vuu-ui/vuu-table 0.8.12 → 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 (200) 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/vuu-table/src/{table-next/Row.d.ts → 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/vuu-table/src/{table-next/cell-renderers → 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/vuu-table/src/{table-next/column-header-pill → column-header-pill}/ColumnHeaderPill.d.ts +3 -3
  21. package/types/vuu-table/src/{table-next/column-header-pill → column-header-pill}/GroupColumnPill.d.ts +2 -2
  22. package/types/vuu-table/src/{table-next/column-header-pill → column-header-pill}/SortIndicator.d.ts +2 -2
  23. package/types/vuu-table/src/{table-next/column-menu → column-menu}/ColumnMenu.d.ts +2 -2
  24. package/types/vuu-table/src/{table-next/column-resizing → column-resizing}/useTableColumnResize.d.ts +2 -2
  25. package/types/vuu-table/src/{table-next/context-menu → context-menu}/index.d.ts +1 -1
  26. package/types/vuu-table/src/{table-next/context-menu/useTableContextMenu.d.ts → context-menu/useHandleTableContextMenu.d.ts} +3 -3
  27. package/types/vuu-table/src/header-cell/GroupHeaderCellNext.d.ts +10 -0
  28. package/types/vuu-table/src/{table-next/header-cell → header-cell}/HeaderCell.d.ts +2 -2
  29. package/types/vuu-table/src/{table-next/header-cell → header-cell}/index.d.ts +0 -1
  30. package/types/vuu-table/src/index.d.ts +9 -4
  31. package/types/vuu-table/src/{table-next/table-cell → table-cell}/TableCell.d.ts +1 -1
  32. package/types/vuu-table/src/{table-next/table-cell → table-cell}/TableGroupCell.d.ts +1 -1
  33. package/types/vuu-table/src/{table-next/table-config.d.ts → table-config.d.ts} +1 -1
  34. package/types/vuu-table/src/{table-next/table-dom-utils.d.ts → 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/vuu-table/src/{table-next/useDataSource.d.ts → useDataSource.d.ts} +5 -3
  41. package/types/vuu-table/src/{table-next/useKeyboardNavigation.d.ts → useKeyboardNavigation.d.ts} +9 -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/vuu-table/src/{table-next/useTableModel.d.ts → useTableModel.d.ts} +12 -14
  46. package/types/vuu-table/src/{table-next/useTableViewport.d.ts → useTableViewport.d.ts} +2 -2
  47. package/types/vuu-table/src/{table-next/useVirtualViewport.d.ts → 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/vuu-layout/src/Component.d.ts +0 -7
  52. package/types/vuu-layout/src/DraggableLayout.d.ts +0 -7
  53. package/types/vuu-layout/src/dock-layout/DockLayout.d.ts +0 -10
  54. package/types/vuu-layout/src/dock-layout/Drawer.d.ts +0 -18
  55. package/types/vuu-layout/src/dock-layout/index.d.ts +0 -2
  56. package/types/vuu-layout/src/drag-drop/BoxModel.d.ts +0 -143
  57. package/types/vuu-layout/src/drag-drop/DragState.d.ts +0 -46
  58. package/types/vuu-layout/src/drag-drop/Draggable.d.ts +0 -24
  59. package/types/vuu-layout/src/drag-drop/DropMenu.d.ts +0 -10
  60. package/types/vuu-layout/src/drag-drop/DropTarget.d.ts +0 -61
  61. package/types/vuu-layout/src/drag-drop/DropTargetRenderer.d.ts +0 -18
  62. package/types/vuu-layout/src/drag-drop/dragDropTypes.d.ts +0 -51
  63. package/types/vuu-layout/src/drag-drop/index.d.ts +0 -4
  64. package/types/vuu-layout/src/flexbox/Flexbox.d.ts +0 -5
  65. package/types/vuu-layout/src/flexbox/FlexboxLayout.d.ts +0 -6
  66. package/types/vuu-layout/src/flexbox/FluidGrid.d.ts +0 -7
  67. package/types/vuu-layout/src/flexbox/FluidGridLayout.d.ts +0 -6
  68. package/types/vuu-layout/src/flexbox/Splitter.d.ts +0 -13
  69. package/types/vuu-layout/src/flexbox/flexbox-utils.d.ts +0 -12
  70. package/types/vuu-layout/src/flexbox/flexboxTypes.d.ts +0 -51
  71. package/types/vuu-layout/src/flexbox/index.d.ts +0 -4
  72. package/types/vuu-layout/src/flexbox/useResponsiveSizing.d.ts +0 -10
  73. package/types/vuu-layout/src/flexbox/useSplitterResizing.d.ts +0 -2
  74. package/types/vuu-layout/src/index.d.ts +0 -22
  75. package/types/vuu-layout/src/layout-action.d.ts +0 -22
  76. package/types/vuu-layout/src/layout-header/Header.d.ts +0 -13
  77. package/types/vuu-layout/src/layout-header/index.d.ts +0 -1
  78. package/types/vuu-layout/src/layout-persistence/LayoutPersistenceManager.d.ts +0 -53
  79. package/types/vuu-layout/src/layout-persistence/LocalLayoutPersistenceManager.d.ts +0 -18
  80. package/types/vuu-layout/src/layout-persistence/data.d.ts +0 -3
  81. package/types/vuu-layout/src/layout-persistence/index.d.ts +0 -4
  82. package/types/vuu-layout/src/layout-persistence/useLayoutContextMenuItems.d.ts +0 -8
  83. package/types/vuu-layout/src/layout-provider/LayoutProvider.d.ts +0 -15
  84. package/types/vuu-layout/src/layout-provider/LayoutProviderContext.d.ts +0 -9
  85. package/types/vuu-layout/src/layout-provider/index.d.ts +0 -2
  86. package/types/vuu-layout/src/layout-provider/useLayoutDragDrop.d.ts +0 -4
  87. package/types/vuu-layout/src/layout-reducer/flexUtils.d.ts +0 -22
  88. package/types/vuu-layout/src/layout-reducer/index.d.ts +0 -4
  89. package/types/vuu-layout/src/layout-reducer/insert-layout-element.d.ts +0 -8
  90. package/types/vuu-layout/src/layout-reducer/layout-reducer.d.ts +0 -3
  91. package/types/vuu-layout/src/layout-reducer/layoutTypes.d.ts +0 -168
  92. package/types/vuu-layout/src/layout-reducer/layoutUtils.d.ts +0 -31
  93. package/types/vuu-layout/src/layout-reducer/move-layout-element.d.ts +0 -3
  94. package/types/vuu-layout/src/layout-reducer/remove-layout-element.d.ts +0 -3
  95. package/types/vuu-layout/src/layout-reducer/replace-layout-element.d.ts +0 -6
  96. package/types/vuu-layout/src/layout-reducer/resize-flex-children.d.ts +0 -4
  97. package/types/vuu-layout/src/layout-reducer/wrap-layout-element.d.ts +0 -9
  98. package/types/vuu-layout/src/layout-view/View.d.ts +0 -11
  99. package/types/vuu-layout/src/layout-view/ViewContext.d.ts +0 -30
  100. package/types/vuu-layout/src/layout-view/index.d.ts +0 -4
  101. package/types/vuu-layout/src/layout-view/useView.d.ts +0 -21
  102. package/types/vuu-layout/src/layout-view/useViewActionDispatcher.d.ts +0 -9
  103. package/types/vuu-layout/src/layout-view/useViewResize.d.ts +0 -7
  104. package/types/vuu-layout/src/layout-view/viewTypes.d.ts +0 -21
  105. package/types/vuu-layout/src/measured-container/MeasuredContainer.d.ts +0 -9
  106. package/types/vuu-layout/src/measured-container/index.d.ts +0 -2
  107. package/types/vuu-layout/src/measured-container/useMeasuredContainer.d.ts +0 -22
  108. package/types/vuu-layout/src/measured-container/useResizeObserver.d.ts +0 -15
  109. package/types/vuu-layout/src/overflow-container/OverflowContainer.d.ts +0 -17
  110. package/types/vuu-layout/src/overflow-container/index.d.ts +0 -2
  111. package/types/vuu-layout/src/overflow-container/overflow-utils.d.ts +0 -49
  112. package/types/vuu-layout/src/overflow-container/useOverflowContainer.d.ts +0 -20
  113. package/types/vuu-layout/src/palette/Palette.d.ts +0 -22
  114. package/types/vuu-layout/src/palette/index.d.ts +0 -1
  115. package/types/vuu-layout/src/placeholder/Placeholder.d.ts +0 -12
  116. package/types/vuu-layout/src/placeholder/index.d.ts +0 -1
  117. package/types/vuu-layout/src/registry/ComponentRegistry.d.ts +0 -13
  118. package/types/vuu-layout/src/registry/index.d.ts +0 -1
  119. package/types/vuu-layout/src/responsive/breakpoints.d.ts +0 -4
  120. package/types/vuu-layout/src/responsive/index.d.ts +0 -3
  121. package/types/vuu-layout/src/responsive/use-breakpoints.d.ts +0 -7
  122. package/types/vuu-layout/src/responsive/useResizeObserver.d.ts +0 -13
  123. package/types/vuu-layout/src/responsive/utils.d.ts +0 -6
  124. package/types/vuu-layout/src/stack/Stack.d.ts +0 -4
  125. package/types/vuu-layout/src/stack/StackLayout.d.ts +0 -7
  126. package/types/vuu-layout/src/stack/index.d.ts +0 -3
  127. package/types/vuu-layout/src/stack/stackTypes.d.ts +0 -21
  128. package/types/vuu-layout/src/toolbar/Toolbar.d.ts +0 -19
  129. package/types/vuu-layout/src/toolbar/index.d.ts +0 -1
  130. package/types/vuu-layout/src/toolbar/toolbar-dom-utils.d.ts +0 -3
  131. package/types/vuu-layout/src/toolbar/useKeyboardNavigation.d.ts +0 -32
  132. package/types/vuu-layout/src/toolbar/useSelection.d.ts +0 -22
  133. package/types/vuu-layout/src/toolbar/useToolbar.d.ts +0 -28
  134. package/types/vuu-layout/src/tools/config-wrapper/ConfigWrapper.d.ts +0 -2
  135. package/types/vuu-layout/src/tools/config-wrapper/index.d.ts +0 -1
  136. package/types/vuu-layout/src/tools/devtools-box/layout-configurator.d.ts +0 -31
  137. package/types/vuu-layout/src/tools/devtools-tree/layout-tree-viewer.d.ts +0 -5
  138. package/types/vuu-layout/src/tools/index.d.ts +0 -3
  139. package/types/vuu-layout/src/use-persistent-state.d.ts +0 -11
  140. package/types/vuu-layout/src/utils/index.d.ts +0 -6
  141. package/types/vuu-layout/src/utils/pathUtils.d.ts +0 -31
  142. package/types/vuu-layout/src/utils/propUtils.d.ts +0 -5
  143. package/types/vuu-layout/src/utils/react-utils.d.ts +0 -4
  144. package/types/vuu-layout/src/utils/refUtils.d.ts +0 -2
  145. package/types/vuu-layout/src/utils/styleUtils.d.ts +0 -3
  146. package/types/vuu-layout/src/utils/typeOf.d.ts +0 -4
  147. package/types/vuu-table/src/table/ColumnResizer.d.ts +0 -8
  148. package/types/vuu-table/src/table/DragVisualizer.d.ts +0 -8
  149. package/types/vuu-table/src/table/RowBasedTable.d.ts +0 -4
  150. package/types/vuu-table/src/table/SortIndicator.d.ts +0 -7
  151. package/types/vuu-table/src/table/Table.d.ts +0 -9
  152. package/types/vuu-table/src/table/TableCell.d.ts +0 -4
  153. package/types/vuu-table/src/table/TableGroupCell.d.ts +0 -4
  154. package/types/vuu-table/src/table/TableGroupHeaderCell.d.ts +0 -13
  155. package/types/vuu-table/src/table/TableHeaderCell.d.ts +0 -11
  156. package/types/vuu-table/src/table/TableRow.d.ts +0 -16
  157. package/types/vuu-table/src/table/cell-renderers/index.d.ts +0 -1
  158. package/types/vuu-table/src/table/cell-renderers/json-cell/JsonCell.d.ts +0 -1
  159. package/types/vuu-table/src/table/cell-renderers/json-cell/index.d.ts +0 -1
  160. package/types/vuu-table/src/table/context-menu/buildContextMenuDescriptors.d.ts +0 -4
  161. package/types/vuu-table/src/table/context-menu/index.d.ts +0 -2
  162. package/types/vuu-table/src/table/context-menu/useTableContextMenu.d.ts +0 -16
  163. package/types/vuu-table/src/table/dataTableTypes.d.ts +0 -109
  164. package/types/vuu-table/src/table/filter-indicator.d.ts +0 -13
  165. package/types/vuu-table/src/table/index.d.ts +0 -10
  166. package/types/vuu-table/src/table/keyUtils.d.ts +0 -19
  167. package/types/vuu-table/src/table/useDataSource.d.ts +0 -41
  168. package/types/vuu-table/src/table/useDraggableColumn.d.ts +0 -9
  169. package/types/vuu-table/src/table/useKeyboardNavigation.d.ts +0 -22
  170. package/types/vuu-table/src/table/useMeasuredContainer.d.ts +0 -30
  171. package/types/vuu-table/src/table/useMeasuredSize.d.ts +0 -26
  172. package/types/vuu-table/src/table/useResizeObserver.d.ts +0 -15
  173. package/types/vuu-table/src/table/useSelection.d.ts +0 -9
  174. package/types/vuu-table/src/table/useTable.d.ts +0 -62
  175. package/types/vuu-table/src/table/useTableColumnResize.d.ts +0 -17
  176. package/types/vuu-table/src/table/useTableModel.d.ts +0 -80
  177. package/types/vuu-table/src/table/useTableScroll.d.ts +0 -29
  178. package/types/vuu-table/src/table/useVirtualViewport.d.ts +0 -17
  179. package/types/vuu-table/src/table-next/TableNext.d.ts +0 -4
  180. package/types/vuu-table/src/table-next/cell-renderers/dropdown-cell/DropdownCell.d.ts +0 -4
  181. package/types/vuu-table/src/table-next/cell-renderers/index.d.ts +0 -2
  182. package/types/vuu-table/src/table-next/header-cell/GroupHeaderCell.d.ts +0 -9
  183. package/types/vuu-table/src/table-next/header-cell/GroupHeaderCellNext.d.ts +0 -9
  184. package/types/vuu-table/src/table-next/index.d.ts +0 -5
  185. package/types/vuu-table/src/table-next/useCell.d.ts +0 -6
  186. package/types/vuu-table/src/table-next/useCellEditing.d.ts +0 -7
  187. package/types/vuu-table/src/table-next/useTableContextMenu.d.ts +0 -8
  188. package/types/vuu-table/src/table-next/useTableNext.d.ts +0 -66
  189. /package/types/vuu-table/src/{table-next/cell-renderers → cell-renderers}/dropdown-cell/index.d.ts +0 -0
  190. /package/types/vuu-table/src/{table-next/cell-renderers → cell-renderers}/input-cell/index.d.ts +0 -0
  191. /package/types/vuu-table/src/{table-next/column-header-pill → column-header-pill}/index.d.ts +0 -0
  192. /package/types/vuu-table/src/{table-next/column-menu → column-menu}/index.d.ts +0 -0
  193. /package/types/vuu-table/src/{table-next/column-resizing → column-resizing}/ColumnResizer.d.ts +0 -0
  194. /package/types/vuu-table/src/{table-next/column-resizing → column-resizing}/index.d.ts +0 -0
  195. /package/types/vuu-table/src/{table-next/context-menu → context-menu}/buildContextMenuDescriptors.d.ts +0 -0
  196. /package/types/vuu-table/src/{table-next/moving-window.d.ts → moving-window.d.ts} +0 -0
  197. /package/types/vuu-table/src/{table-next/table-cell → table-cell}/index.d.ts +0 -0
  198. /package/types/vuu-table/src/{table-next/useInitialValue.d.ts → useInitialValue.d.ts} +0 -0
  199. /package/types/vuu-table/src/{table-next/useResizeObserver.d.ts → useResizeObserver.d.ts} +0 -0
  200. /package/types/vuu-table/src/{table-next/useTableScroll.d.ts → useTableScroll.d.ts} +0 -0
package/esm/index.js CHANGED
@@ -1,2 +1,3512 @@
1
- import{useCallback as bt,useRef as pr}from"react";import{jsx as fr}from"react/jsx-runtime";var uo=()=>{},dr="vuuColumnResizer",_e=({onDrag:e,onDragEnd:t=uo,onDragStart:o=uo})=>{let n=pr(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 fr("div",{className:dr,"data-align":"end",onMouseDown:s})};import{isNumericColumn as Cr}from"@vuu-ui/vuu-utils";var Je=e=>(t,o)=>{let n=[];if(e===void 0)return n;if(t==="header"||t==="column-menu")n.push(...br(o,e)),n.push(...vr(o,e)),n.push(...gr(o,e)),n.push(...hr(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 br(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 gr(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(Cr(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 hr(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 vr(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 yr}from"@vuu-ui/vuu-utils";import{addGroupColumn as mo,addSortColumn as po,AggregationType as Tr,setAggregations as ge,setSortColumn as fo}from"@vuu-ui/vuu-utils";var wr=(e,t)=>{if(e.filterStruct&&t){let[o,n]=yr(t,e.filterStruct);return{filter:n,filterStruct:o}}else return e},{Average:Dr,Count:Mr,Distinct:Rr,High:xr,Low:Pr,Sum:Hr}=Tr,Xe=({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=fo(e.sort,l,"A"),!0;case"sort-dsc":return e.sort=fo(e.sort,l,"D"),!0;case"sort-add-asc":return e.sort=po(e.sort,l,"A"),!0;case"sort-add-dsc":return e.sort=po(e.sort,l,"D"),!0;case"group":return e.groupBy=mo(e.groupBy,l),!0;case"group-add":return e.groupBy=mo(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=wr(e.filter,l),!0;case"remove-filters":return e.filter={filter:""},!0;case"agg-avg":return e.aggregations=ge(e.aggregations,l,Dr),!0;case"agg-high":return e.aggregations=ge(e.aggregations,l,xr),!0;case"agg-low":return e.aggregations=ge(e.aggregations,l,Pr),!0;case"agg-count":return e.aggregations=ge(e.aggregations,l,Mr),!0;case"agg-distinct":return e.aggregations=ge(e.aggregations,l,Rr),!0;case"agg-sum":return e.aggregations=ge(e.aggregations,l,Hr),!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 ei}from"@vuu-ui/vuu-popups";import{Button as ti,useIdMemo as oi}from"@salt-ds/core";import{buildColumnMap as pl,getColumnStyle as dl,isGroupColumn as fl,metadataKeys as Cl,notHidden as bl,visibleColumnAtIndex as gl}from"@vuu-ui/vuu-utils";import{useCallback as ko,useMemo as No}from"react";import{isGroupColumn as ho,isJsonColumn as Wr,isJsonGroup as Br,metadataKeys as Ur,notHidden as _r,RowSelected as Jr}from"@vuu-ui/vuu-utils";import Xr from"classnames";import{memo as Qr,useCallback as vo}from"react";import{getColumnStyle as Er,metadataKeys as Sr}from"@vuu-ui/vuu-utils";import{EditableLabel as Ar}from"@vuu-ui/vuu-ui-controls";import Lr from"classnames";import{memo as Kr,useCallback as kr,useRef as Nr,useState as Co}from"react";import{jsx as Qe}from"react/jsx-runtime";var{KEY:bo}=Sr,Tt=Kr(({className:e,column:t,columnMap:o,onClick:n,row:r})=>{let l=Nr(null),{align:s,CellRenderer:i,key:a,pin:c,editable:u,resizing:p,valueFormatter:m}=t,[C,h]=Co(!1),v=m(r[a]),[T,x]=Co(v),g=()=>{var H;(H=l.current)==null||H.focus()},f=H=>{H.key==="Enter"&&h(!0)},M=kr(H=>{n==null||n(H,t)},[t,n]),D=()=>{h(!0)},w=(H="",y="",R=!0,S=!1)=>{var E;h(!1),S?x(H):y!==H&&x(y),R===!1&&((E=l.current)==null||E.focus())},d=Lr(e,{vuuAlignRight:s==="right",vuuPinFloating:c==="floating",vuuPinLeft:c==="left",vuuPinRight:c==="right","vuuTableCell-resizing":p})||void 0,b=Er(t);return u?Qe("div",{className:d,"data-editable":!0,role:"cell",style:b,onKeyDown:f,children:Qe(Ar,{editing:C,value:T,onChange:x,onMouseDownCapture:g,onEnterEditMode:D,onExitEditMode:w,onKeyDown:f,ref:l,tabIndex:0},"title")}):Qe("div",{className:d,role:"cell",style:b,onClick:M,children:i?Qe(i,{column:t,columnMap:o,row:r}):v})},zr);Tt.displayName="TableCell";function zr(e,t){return e.column===t.column&&e.onClick===t.onClick&&e.row[bo]===t.row[bo]&&e.row[e.column.key]===t.row[t.column.key]}import{getColumnStyle as Ir,getGroupValueAndOffset as Vr,metadataKeys as $r}from"@vuu-ui/vuu-utils";import{useCallback as Fr}from"react";import{jsx as wt,jsxs as Gr}from"react/jsx-runtime";var{IS_LEAF:Or}=$r,go=({column:e,onClick:t,row:o})=>{let{columns:n}=e,[r,l]=Vr(n,o),s=Fr(u=>{t==null||t(u,e)},[e,t]),i=Ir(e),a=o[Or],c=Array(l).fill(0).map((u,p)=>wt("span",{className:"vuuTableGroupCell-spacer"},p));return Gr("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 To,jsxs as tl}from"react/jsx-runtime";var{IDX:Yr,IS_EXPANDED:Zr,SELECTED:jr}=Ur,{True:yo,First:qr,Last:el}=Jr,he="vuuTableRow",wo=Qr(function({columnMap:t,columns:o,offset:n,onClick:r,onToggleGroup:l,virtualColSpan:s=0,row:i}){let{[Yr]:a,[Zr]:c,[jr]:u}=i,p=Xr(he,{[`${he}-even`]:a%2===0,[`${he}-expanded`]:c,[`${he}-selected`]:u&yo,[`${he}-selectedStart`]:u&qr,[`${he}-selectedEnd`]:u&el}),m=vo(h=>{let v=h.shiftKey,T=h.ctrlKey||h.metaKey;r==null||r(i,v,T)},[r,i]),C=vo((h,v)=>{(ho(v)||Br(v,i))&&(h.stopPropagation(),l==null||l(i,v))},[l,i]);return tl("div",{"aria-selected":u&yo?!0:void 0,"aria-rowindex":a,className:p,onClick:m,role:"row",style:{transform:`translate3d(0px, ${n}px, 0px)`},children:[s>0?To("div",{role:"cell",style:{width:s}}):null,o.filter(_r).map(h=>{let v=ho(h),T=Wr(h);return To(v?go:Tt,{column:h,columnMap:t,onClick:v||T?C:void 0,row:i},h.name)})]})});import Ro from"classnames";import{useRef as ol}from"react";import{useCallback as Dt,useRef as Do}from"react";var Ye=({column:e,onResize:t,rootRef:o})=>{let n=Do(0),r=Do(!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:p}=o.current.getBoundingClientRect(),m=Math.round(p)+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 ce,jsxs as Po}from"react/jsx-runtime";var oe="vuuTable-groupHeaderCell",Mo=({column:e,onClick:t,...o})=>ce("span",{...o,className:`${oe}-close`,"data-icon":"close-circle",onClick:()=>t==null?void 0:t(e)}),nl=e=>{let{children:t,column:o,className:n}=e;return Po("div",{className:Ro(`${oe}-col`,n),role:"columnheader",children:[ce("span",{className:`${oe}-label`,children:o.name}),t]})},xo=({column:e,className:t,onRemoveColumn:o,onResize:n,...r})=>{let l=ol(null),{isResizing:s,...i}=Ye({column:e,onResize:n,rootRef:l}),a=Ro(oe,t,{vuuPinLeft:e.pin==="left",[`${oe}-right`]:e.align==="right",[`${oe}-resizing`]:e.resizing,[`${oe}-pending`]:e.groupConfirmed===!1}),{columns:c}=e;return ce("div",{className:a,ref:l,...r,children:Po("div",{className:`${oe}-inner`,children:[c.map(u=>ce(nl,{column:u,children:c.length>1?ce(Mo,{column:u,onClick:o}):null},u.key)),ce(Mo,{"data-align":"end",onClick:o}),e.resizeable!==!1?ce(_e,{...i}):null]})})};import cl from"classnames";import{useCallback as Mt,useRef as Lo}from"react";import Ho from"classnames";import{jsx as Ze,jsxs as rl}from"react/jsx-runtime";var Eo="vuuSortIndicator",So=({sorted:e})=>{if(!e)return null;let t=typeof e=="number"?e<0?"dsc":"asc":e==="A"?"asc":"dsc";return typeof e=="number"?rl("div",{className:Ho(Eo,"multi-col",t),children:[Ze("span",{"data-icon":`sorted-${t}`}),Ze("span",{className:"vuuSortPosition",children:Math.abs(e)})]}):Ze("div",{className:Ho(Eo,"single-col"),children:Ze("span",{"data-icon":`sorted-${t}`})})};import{useContextMenu as ul}from"@vuu-ui/vuu-popups";import{useContextMenu as ll}from"@vuu-ui/vuu-popups";import sl from"classnames";import{useCallback as il}from"react";import{jsx as al}from"react/jsx-runtime";var Ao=({column:e,filter:t})=>{let[o]=ll(),n=il(r=>{r.stopPropagation(),o(r,"filter",{column:e,filter:t})},[e,t,o]);return e.filter?al("div",{className:sl("vuuFilterIndicator"),"data-icon":"filter",onClick:n}):null};import{jsx as Ee,jsxs as ml}from"react/jsx-runtime";var He="vuuTable-headerCell",Ko=({column:e,className:t,onClick:o,onDragStart:n,onResize:r,...l})=>{let s=Lo(null),{isResizing:i,...a}=Ye({column:e,onResize:r,rootRef:s}),[c]=ul(),u=Lo(null),p=T=>{c(T,"header",{column:e})},m=Mt(T=>!i&&(o==null?void 0:o(T)),[i,o]),C=Mt(T=>{u.current=window.setTimeout(()=>{n==null||n(T),u.current=null},500)},[n]),h=Mt(()=>{u.current!==null&&(window.clearTimeout(u.current),u.current=null)},[]),v=cl(He,t,{vuuPinFloating:e.pin==="floating",vuuPinLeft:e.pin==="left",vuuPinRight:e.pin==="right",vuuEndPin:e.endPin,[`${He}-resizing`]:e.resizing,[`${He}-right`]:e.align==="right"});return Ee("div",{className:v,...l,onClick:m,onContextMenu:p,onMouseDown:C,onMouseUp:h,ref:s,children:ml("div",{className:`${He}-inner`,children:[Ee(Ao,{column:e}),Ee("div",{className:`${He}-label`,children:e.label}),Ee(So,{sorted:e.sorted}),e.resizeable!==!1?Ee(_e,{...a}):null]})})};import{jsx as ue,jsxs as zo}from"react/jsx-runtime";var Rt="vuuTable",{RENDER_IDX:hl}=Cl,Io=({columns:e,columnsWithinViewport:t,data:o,getRowOffset:n,headings:r,onColumnResize:l,onHeaderCellDragStart:s,onContextMenu:i,onRemoveColumnFromGroupBy:a,onRowClick:c,onSort:u,onToggleGroup:p,tableId:m,virtualColSpan:C=0,rowCount:h})=>{let v=ko(f=>{s==null||s(f)},[s]),T=No(()=>e.filter(bl),[e]),x=No(()=>pl(e),[e]),g=ko(f=>{var H;let D=f.target.closest(".vuuTable-headerCell"),w=parseInt((H=D==null?void 0:D.dataset.idx)!=null?H:"-1"),d=gl(e,w),b=f.shiftKey;d&&u(d,b)},[e,u]);return zo("div",{"aria-rowcount":h,className:`${Rt}-table`,role:"table",children:[zo("div",{className:`${Rt}-headers`,role:"rowGroup",children:[r.map((f,M)=>ue("div",{className:"vuuTable-heading",children:f.map(({label:D,width:w},d)=>ue("div",{className:"vuuTable-headingCell",style:{width:w},children:D},d))},M)),ue("div",{role:"row",children:T.map((f,M)=>{let D=dl(f);return fl(f)?ue(xo,{column:f,"data-idx":M,onRemoveColumn:a,onResize:l,role:"columnHeader",style:D},M):ue(Ko,{column:f,"data-idx":M,id:`${m}-${M}`,onClick:g,onDragStart:v,onResize:l,role:"columnHeader",style:D},M)})})]}),ue("div",{className:`${Rt}-body`,onContextMenu:i,role:"rowGroup",children:o==null?void 0:o.map(f=>ue(wo,{columnMap:x,columns:t,offset:n(f),onClick:c,virtualColSpan:C,onToggleGroup:p,row:f},f[hl]))})]})};import{useContextMenu as Bs}from"@vuu-ui/vuu-popups";import{applySort as Us,buildColumnMap as _s,isJsonGroup as Js,metadataKeys as Xs,moveItemDeprecated as Qs}from"@vuu-ui/vuu-utils";import{useCallback as J,useEffect as Cn,useMemo as Ys,useRef as $t,useState as Zs}from"react";import{isVuuFeatureAction as vl,isVuuFeatureInvocation as yl}from"@vuu-ui/vuu-data-react";import{getFullRange as xt,metadataKeys as Tl,WindowRange as wl}from"@vuu-ui/vuu-utils";import{useCallback as ve,useEffect as je,useMemo as Dl,useRef as Se,useState as Ml}from"react";var{SELECTED:Ae}=Tl;function Vo({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]=Ml(null),u=Se(!0),p=Se(!1),m=Se({from:0,to:0}),C=Se(null),h=Se([]),v=Dl(()=>new Pt(xt(s)),[]),T=ve(w=>{for(let d of w)v.add(d);h.current=v.data,p.current=!0},[v]),x=ve(w=>{w.type==="subscribed"?l==null||l(w):w.type==="viewport-update"?(typeof w.size=="number"&&(r==null||r(w.size),v.setRowCount(w.size)),w.rows?T(w.rows):typeof w.size=="number"&&(h.current=v.data,p.current=!0)):vl(w)?o==null||o(w):yl(w)?n==null||n(w):console.log(`useDataSource unexpected message ${w.type}`)},[v,o,n,r,l,T]);je(()=>()=>{C.current&&(cancelAnimationFrame(C.current),C.current=null),u.current=!1},[]);let g=ve(()=>{u.current&&(p.current&&(c({}),p.current=!1),C.current=requestAnimationFrame(g))},[c]);je(()=>{C.current=requestAnimationFrame(g)},[g]);let f=ve(w=>{let{from:d}=e.range,b={from:d,to:d+w},H=xt(b,i);v.setRange(H),e.range=m.current=H,e.emit("range",b)},[e,v,i]),M=ve(w=>{let d=xt(w,i);v.setRange(d),e.range=m.current=d,e.emit("range",w)},[e,v,i]),D=ve(()=>v.getSelectedRows(),[v]);return je(()=>{e==null||e.subscribe({range:m.current},x)},[e,x,t]),je(()=>{console.log(`adjust range as rowCount chnaged ${a}`),f(a)},[f,a]),{data:h.current,getSelectedRows:D,range:m.current,setRange:M,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 wl(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[Ae],s=(n=this.data[r-1])==null?void 0:n[Ae];s===0&&l?this.data[r-1][Ae]=2:s===2&&!l&&(this.data[r-1][Ae]=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[Ae]!==0)}};import{useDragDropNext as Rl}from"@vuu-ui/vuu-ui-controls";import{useCallback as $o,useRef as Fo}from"react";var Oo=({onDrop:e})=>{let t=Fo(),o=Fo(null),n=$o(()=>{console.log("handleDropSettle"),t.current=void 0,o.current=null},[]),{draggable:r,draggedItemIndex:l,onMouseDown:s}=Rl({allowDragDrop:!0,draggableClassName:"vuuTable-headerCell",orientation:"horizontal",containerRef:o,itemQuery:".vuuTable-headerCell",onDrop:e,onDropSettle:n}),i=$o(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:C="-1"}}=m;t.current={clientX:c,clientY:u,idx:C},s==null||s(a)},[s]);return{draggable:r,draggedItemIndex:l,onHeaderCellDragStart:i}};import{withinRange as Ll}from"@vuu-ui/vuu-utils";import{useCallback as ee,useEffect as Kl,useLayoutEffect as kl,useMemo as Nl,useRef as zt}from"react";function xl(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 Pl=new Set(["Enter","Delete"," "]),Hl=new Set(["Tab"]),El=new Set(["ArrowRight","ArrowLeft"]),Go=new Set([Lt,Kt,kt,Nt,Et,St,At,Ht]),Sl=new Set(["F1","F2","F3","F4","F5","F6","F7","F8","F9","F10","F11","F12"]),rp=xl(Pl,Go,El,Sl,Hl);var Al=["Home","End","PageUp","PageDown"],Wo=e=>Al.includes(e),Bo=e=>Go.has(e);var Uo=e=>`.vuuTable-headers .vuuTable-headerCell:nth-child(${e+1})`,zl=(e,t)=>`.vuuTable-body > [aria-rowindex='${e}'] > [role='cell']:nth-child(${t+1})`,Il=[-1,-1];function Vl(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 _o=({columnCount:e=0,containerRef:t,disableHighlightOnFocus:o,data:n,requestScroll:r,rowCount:l=0,viewportRange:s})=>{var H;let{from:i,to:a}=s,c=zt([-1,-1]),u=zt(),p=zt([-1,0]),m=ee(([y,R])=>{var E;let S=y===-1?Uo(R):zl(y,R);return(E=t.current)==null?void 0:E.querySelector(S)},[t]),C=y=>y==null?void 0:y.closest("[role='columnHeader'],[role='cell']"),h=y=>{var R,S;if(y.role==="columnHeader")return[-1,parseInt((R=y.dataset.idx)!=null?R:"-1",10)];{let E=y.closest("[role='row']");if(E){let L=parseInt((S=E.ariaRowIndex)!=null?S:"-1",10),F=Array.from(E.childNodes).indexOf(y);return[L,F]}}return Il},v=ee(y=>{var R;if(t.current){let S=m(y);S?(S!==u.current&&((R=u.current)==null||R.setAttribute("tabindex",""),u.current=S,S.setAttribute("tabindex","0")),S.focus()):Ll(y[0],s)||(u.current=void 0,r==null||r({type:"scroll-page",direction:"up"}))}},[t,m,r,s]),T=ee((y,R,S=!1)=>{let E=[y,R];p.current=E,v(E),S&&(c.current=E)},[v]),x=ee(()=>{var y;(y=u.current)==null||y.setAttribute("tabindex",""),u.current=void 0},[]),g=ee(async(y,R)=>{switch(y){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 R},[r]),f=ee(()=>{var y;if(o!==!0&&(y=t.current)!=null&&y.contains(document.activeElement)){let R=C(document.activeElement);R&&(c.current=h(R))}},[o,t]),M=ee(async y=>{let[R,S]=Wo(y)?await g(y,p.current):Vl(y,p.current,e,l),[E,L]=p.current;(R!==E||S!==L)&&T(R,S,!0)},[e,g,l,T]),D=ee(y=>{n.length>0&&Bo(y.key)&&(y.preventDefault(),y.stopPropagation(),M(y.key))},[n,M]),w=ee(y=>{let R=y.target,S=C(R);if(S){let[E,L]=h(S);T(E,L)}},[T]),d=Nl(()=>({onClick:w,onFocus:f,onKeyDown:D}),[w,f,D]);kl(()=>{let{current:y}=p,R=y[0]>=i&&y[0]<=a;u.current&&!R?x():!u.current&&R&&v(y)},[v,i,a,x]);let b=((H=t.current)==null?void 0:H.firstChild)!=null;return Kl(()=>{var y;if(b&&u.current===void 0){let R=(y=t.current)==null?void 0:y.querySelector(Uo(0));R&&(R.setAttribute("tabindex","0"),u.current=R)}},[t,b]),d};import{isValidNumber as ne}from"@vuu-ui/vuu-utils";import{useCallback as Ol,useMemo as Gl,useRef as Wl,useState as Bl}from"react";import{useCallback as $l,useEffect as Jo,useRef as Fl}from"react";var me=new Map,Qo=(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}},Xo=new ResizeObserver(e=>{for(let t of e){let{target:o,borderBoxSize:n,contentBoxSize:r}=t,l=me.get(o);if(l){let[{blockSize:s,inlineSize:i}]=n,[{blockSize:a,inlineSize:c}]=r,{onResize:u,measurements:p}=l,m=!1;for(let[C,h]of Object.entries(p)){let v=Qo(o,{height:s,width:i,contentHeight:a,contentWidth:c},C);v!==h&&(m=!0,p[C]=v)}m&&u&&u(p)}}});function Yo(e,t,o,n=!1){let r=Fl(t),l=$l(s=>{let{width:i,height:a}=s.getBoundingClientRect(),{clientWidth:c,clientHeight:u}=s;return r.current.reduce((p,m)=>(p[m]=Qo(s,{width:i,height:a,contentHeight:u,contentWidth:c},m),p),{})},[]);Jo(()=>{let s=e.current;async function i(){me.set(s,{measurements:{}}),await document.fonts.ready;let a=me.get(s);if(a){let c=l(s);a.measurements=c,Xo.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(me.has(s))throw Error("useResizeObserver attemping to observe same element twice");i()}return()=>{s&&me.has(s)&&(Xo.unobserve(s),me.delete(s))}},[l,e]),Jo(()=>{let s=e.current,i=me.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 Ul=["clientHeight","clientWidth"],Zo=e=>Number.isFinite(e),_l={height:"100%",width:"100%"},Jl=(e,t)=>ne(e)&&ne(t)?{height:`${e}px`,width:`${t}px`}:_l,Xl=(e,t)=>{if(ne(e)&&ne(t))return{height:e,width:t}},jo=({defaultHeight:e=0,defaultWidth:t=0,height:o,width:n})=>{let r=Wl(null),[l,s]=Bl({css:Jl(o,n),inner:Xl(o,n),outer:{height:o!=null?o:"100%",width:n!=null?n:"100%"}});Gl(()=>{s(a=>{let{inner:c,outer:u}=a;if(ne(o)&&ne(n)&&c&&u){let{height:p,width:m}=c,{height:C,width:h}=u;if(C!==o||h!==n){let v=ne(C)?C-p:0,T=ne(h)?h-m:0;return{...a,outer:{height:o,width:n},inner:{height:o-v,width:n-T}}}}return a})},[o,n]);let i=Ol(({clientWidth:a,clientHeight:c})=>{s(u=>{let{css:p,inner:m,outer:C}=u;return Zo(c)&&Zo(a)&&(a!==(m==null?void 0:m.width)||c!==(m==null?void 0:m.height))?{css:p,outer:C,inner:{width:Math.floor(a)||t,height:Math.floor(c)||e}}:u})},[e,t]);return Yo(r,Ul,i,!0),{containerRef:r,cssSize:l.css,outerSize:l.outer,innerSize:l.inner}};import{deselectItem as Ql,isRowSelected as Yl,metadataKeys as Zl,selectItem as jl}from"@vuu-ui/vuu-utils";import{useCallback as ql,useRef as qo}from"react";var{IDX:es}=Zl,ts=[],qe=({selectionModel:e,onSelect:t,onSelectionChange:o})=>{let n=qo(-1),r=qo(ts);return ql((s,i,a)=>{let{[es]:c}=s,{current:u}=n,{current:p}=r,C=(Yl(s)?Ql:jl)(e,p,c,i,a,u);r.current=C,n.current=c,t==null||t(s),o==null||o(C)},[t,o,e])};import{applyFilterToColumns as os,applyGroupByToColumns as ns,applySortToColumns as rs,findColumn as ls,getCellRenderer as ss,getColumnName as is,getTableHeadings as as,getValueFormatter as cs,isFilteredColumn as us,isGroupColumn as ms,isPinned as ps,isTypeDescriptor as ds,metadataKeys as fs,updateColumn as en,sortPinnedColumns as tn,stripFilterFromColumns as Cs,moveItemDeprecated as bs,getDefaultAlignment as on,isCalculatedColumn as gs,getCalculatedColumnName as hs}from"@vuu-ui/vuu-utils";import{useReducer as vs}from"react";var ys=100,nn=fs.count,Ts=({serverDataType:e})=>e===void 0,ws=e=>{var t;if(ds(e.type))return ss((t=e.type)==null?void 0:t.renderer)},rn=(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"},Sp=e=>e.type==="columnSettings",Ap=e=>e.type==="tableSettings",Ds=(e,t)=>{switch(t.type){case"init":return sn(t);case"moveColumn":return xs(e,t);case"resizeColumn":return Es(e,t);case"setTableSchema":return Ss(e,t);case"hideColumns":return Ps(e,t);case"showColumns":return Hs(e,t);case"pinColumn":return As(e,t);case"updateColumnProp":return ye(e,t);case"tableConfig":return an(e,t);default:return console.log(`unhandled action ${t.type}`),e}},ln=(e,t)=>{let[o,n]=vs(Ds,{tableConfig:e,dataSourceConfig:t},sn);return{columns:o.columns,dispatchColumnAction:n,headings:o.headings}};function sn({dataSourceConfig:e,tableConfig:t}){let o=t.columns.map(It(t)),n=o.some(ps)?tn(o):o,r={columns:n,headings:as(n)};if(e){let{columns:l,...s}=e;return an(r,{type:"tableConfig",...s})}else return r}var Ms=e=>gs(e.name)?hs(e):e.name,Rs=(e,t)=>t==="uppercase"?e.toUpperCase():t==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,It=e=>(t,o)=>{let n=rn(t,e.tableSchema),{columnDefaultWidth:r=ys,columnFormatHeader:l}=e,{align:s=on(n),key:i,name:a,label:c=Ms(t),width:u=r,...p}=t,m={...p,align:s,CellRenderer:ws(t),label:Rs(c,l),key:i!=null?i:o+nn,name:a,originalIdx:o,serverDataType:n,valueFormatter:cs(t),width:u};return ms(m)&&(m.columns=m.columns.map(C=>It(e)(C,C.key))),m};function xs(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:bs(r,t,n)};return e}function Ps(e,{columns:t}){return t.some(o=>o.hidden!==!0)?t.reduce((o,n)=>n.hidden!==!0?ye(o,{type:"updateColumnProp",column:n,hidden:!0}):o,e):e}function Hs(e,{columns:t}){return t.some(o=>o.hidden)?t.reduce((o,n)=>n.hidden?ye(o,{type:"updateColumnProp",column:n,hidden:!1}):o,e):e}function Es(e,{column:t,phase:o,width:n}){let r="updateColumnProp",l=o!=="end";switch(o){case"begin":return ye(e,{type:r,column:t,resizing:l});case"end":return ye(e,{type:r,column:t,resizing:l,width:n});case"resize":return ye(e,{type:r,column:t,width:n});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${o}`)}}function Ss(e,{tableSchema:t}){let{columns:o}=e;if(o.some(Ts)){let n=o.map(r=>{var s;let l=rn(r,t);return{...r,align:(s=r.align)!=null?s:on(l),serverDataType:l}});return{...e,columns:n,tableSchema:t}}else return{...e,tableSchema:t}}function As(e,t){let{columns:o}=e,{column:n,pin:r}=t;return o=en(o,n.name,{pin:r}),o=tn(o),console.log({withPins:o}),{...e,columns:o}}function ye(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=en(o,r.name,c),{...e,columns:o}}function an(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((p,m)=>{let C=is(p),h=m+nn,v=ls(u.columns,C);return v?v.key===h?v:{...v,key:h}:It(e)({name:p},m)})}),i&&(u={...e,columns:ns(u.columns,r,o)}),c&&(u={...e,columns:rs(u.columns,l)}),a?u={...e,columns:os(u.columns,n)}:u.columns.some(us)&&(u={...e,columns:Cs(u.columns)}),u}import{useCallback as re,useRef as Le}from"react";var cn=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]},Ls=e=>{let{clientHeight:t,clientWidth:o,scrollHeight:n,scrollWidth:r}=e;return[r-o,n-t]},un=({onAttach:e,onDetach:t})=>{let o=Le(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])},mn=({onHorizontalScroll:e,onVerticalScroll:t,viewport:o})=>{let n=Le(!1),r=Le({scrollTop:0,scrollLeft:0}),l=Le(null),s=Le(null),{maxScrollContainerScrollHorizontal:i,maxScrollContainerScrollVertical:a}=o,c=re(()=>{let{current:g}=s,{current:f}=l,{current:M}=n;if(M)n.current=!1;else if(g&&f){let[D,w]=cn(f),[d,b]=Ls(g),H=Math.round(D*d),y=Math.round(w*b);console.log(`pctScrollTop ${w}, maxScrollTop ${b} rootScrollTop ${y}`),g.scrollTo({left:H,top:y,behavior:"auto"})}},[]),u=re(()=>{let{current:g}=s,{current:f}=l,{current:M}=r;if(g&&f){let{scrollLeft:D,scrollTop:w}=g,[d,b]=cn(g);n.current=!0,f.scrollLeft=Math.round(d*i),f.scrollTop=Math.round(b*a),M.scrollTop!==w&&(M.scrollTop=w,t==null||t(w,b)),M.scrollLeft!==D&&(M.scrollLeft=D,e==null||e(D))}},[i,a,e,t]),p=re(g=>{l.current=g,g.addEventListener("scroll",c,{passive:!0})},[c]),m=re(g=>{l.current=null,g.removeEventListener("scroll",c)},[c]),C=re(g=>{s.current=g,g.addEventListener("scroll",u,{passive:!0})},[u]),h=re(g=>{s.current=null,g.removeEventListener("scroll",u)},[u]),v=un({onAttach:C,onDetach:h}),T=un({onAttach:p,onDetach:m}),x=re(g=>{let{current:f}=s;if(f){if(n.current=!1,g.type==="scroll-page"){let{clientHeight:M,scrollLeft:D,scrollTop:w}=f,{direction:d}=g,b=d==="down"?M:-M,H=Math.min(Math.max(0,w+b),a);f.scrollTo({top:H,left:D,behavior:"auto"})}else if(g.type==="scroll-end"){let{direction:M}=g,D=M==="end"?a:0;f.scrollTo({top:D,left:f.scrollLeft,behavior:"auto"})}}},[a]);return{scrollbarContainerRef:T,contentContainerRef:v,requestScroll:x}};import{useCallback as Ks,useMemo as et,useRef as ks}from"react";import{actualRowPositioning as Ns,virtualRowPositioning as zs}from"@vuu-ui/vuu-utils";var Is=15e5,Vs={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},$s=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}},tt=({columns:e,headerHeight:t,headings:o,rowCount:n,rowHeight:r,size:l})=>{let s=ks(0),a=Math.min(n,Is)*r,u=n*r-a,{pinnedWidthLeft:p,pinnedWidthRight:m,unpinnedWidth:C}=et(()=>$s(e),[e]),[h,v]=et(()=>Ns(r),[r]),[T,x]=et(()=>u?zs(r,u,s):[h,v],[v,h,u,r]),g=Ks(f=>{s.current=f},[]);return et(()=>{var f;if(l){let M=o.length,D=15,w=p+C+m,d=w>l.width?D:0,b=t*(1+M),H=a-(((f=l==null?void 0:l.height)!=null?f:0)-d)+b,y=w-l.width+p,R=(l.height-t)/r,S=Number.isInteger(R)?R+1:Math.ceil(R),E=l.height-b,L=a>E?D:0;return{contentHeight:a,getRowAtPosition:x,getRowOffset:T,horizontalScrollbarHeight:d,maxScrollContainerScrollHorizontal:y,maxScrollContainerScrollVertical:H,pinnedWidthLeft:p,pinnedWidthRight:m,rowCount:S,contentWidth:w,setPctScrollTop:g,totalHeaderHeight:b,verticalScrollbarWidth:L,viewportBodyHeight:E}}else return Vs},[l,o.length,p,C,m,a,t,r,x,T,g])};import{getColumnsInViewport as pn,itemsChanged as Fs}from"@vuu-ui/vuu-utils";import{useCallback as dn,useEffect as Os,useMemo as Gs,useRef as Vt,useState as Ws}from"react";var fn=({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,p]=Gs(()=>pn(e,c.current,c.current+a),[a,e]),m=Vt(p);Os(()=>{h(u)},[u]);let[C,h]=Ws(u),v=dn(x=>{c.current=x;let[g,f]=pn(e,x,x+a);Fs(C,g)&&(m.current=f,h(g))},[a,e,C]),T=dn(x=>{let g=t(x);g!==r.current&&(r.current=g,console.log("setRange from handleVerticalScroll"),o({from:g,to:g+l}))},[t,o,l]);return{columnsWithinViewport:C,onHorizontalScroll:v,onVerticalScroll:T,virtualColSpan:m.current}};var js=[],{KEY:qs,IS_EXPANDED:bn,IS_LEAF:gn}=Xs,hn=({config:e,dataSource:t,headerHeight:o,onConfigChange:n,onFeatureEnabled:r,onFeatureInvocation:l,onSelectionChange:s,renderBufferSize:i=0,rowHeight:a,selectionModel:c,...u})=>{var We,Be;let[p,m]=Zs(t.size),C=$t(!1),h=$t();if(h.current=t,t===void 0)throw Error("no data source provided to Vuu Table");let v=jo(u),T=J(A=>{m(A)},[]),{columns:x,dispatchColumnAction:g,headings:f}=ln(e,t.config),{getRowAtPosition:M,getRowOffset:D,setPctScrollTop:w,...d}=tt({columns:x,headerHeight:o,headings:f,rowCount:p,rowHeight:a,size:v.innerSize}),b=J(({tableSchema:A})=>{A?(C.current=!0,g({type:"setTableSchema",tableSchema:A})):console.log("usbscription message with no schema")},[g]),H=J(A=>{t.select(A),s==null||s(A)},[t,s]),y=qe({onSelectionChange:H,selectionModel:c}),{data:R,getSelectedRows:S,range:E,setRange:L}=Vo({dataSource:t,onFeatureEnabled:r,onFeatureInvocation:l,onSubscribed:b,onSizeChange:T,renderBufferSize:i,viewportRowCount:d.rowCount}),F=$t();F.current=R;let ae=J(A=>{C.current=!0,console.log("onPersistentColumnOperation, dispatchColumnAction",{action:A}),g(A)},[g]),De=Xe({dataSource:t,onPersistentColumnOperation:ae}),Ve=J((A,N=!1,$)=>{t&&(t.sort=Us(t.sort,A,N,$))},[t]),$e=J((A,N,$)=>{let z=x.find(U=>U.name===N);if(z)A==="end"&&(C.current=!0),g({type:"resizeColumn",phase:A,column:z,width:$});else throw Error(`useDataTable.handleColumnResize, column ${N} not found`)},[x,g]),B=J((A,N)=>{let $=Js(N,A),z=A[qs];if(A[bn]){if(t.closeTreeNode(z,!0),$){let U=x.indexOf(N);t.getRowsAtDepth(U+1).some(_=>_[bn]||_[gn])||g({type:"hideColumns",columns:x.slice(U+2)})}}else if(t.openTreeNode(z),$){let U=t.getChildRows(z),Q=x.indexOf(N)+1,_=[x[Q]];U.some(Z=>Z[gn])&&_.push(x[Q+1]),_.some(Z=>Z.hidden)&&g({type:"showColumns",columns:_})}},[x,t,g]),{onVerticalScroll:Ce,onHorizontalScroll:be,columnsWithinViewport:X,virtualColSpan:O}=fn({columns:x,getRowAtPosition:M,setRange:L,viewportMeasurements:d}),Me=J((A,N)=>{w(N),Ce(A)},[Ce,w]),{requestScroll:Re,...xe}=mn({onHorizontalScroll:be,onVerticalScroll:Me,viewport:d,viewportHeight:((Be=(We=v.innerSize)==null?void 0:We.height)!=null?Be:0)-o}),V=_o({columnCount:x.length,containerRef:v.containerRef,data:R,requestScroll:Re,rowCount:t==null?void 0:t.size,viewportRange:E}),Y=J(A=>{A?t&&t.groupBy.includes(A.name)&&(t.groupBy=t.groupBy.filter(N=>N!==A.name)):t.groupBy=[]},[t]),Fe=J((A,N)=>{let $=t.columns[A],z=Qs(t.columns,$,N);z!==t.columns&&(t.columns=z,g({type:"tableConfig",columns:z}))},[t,g]),at=Oo({onDrop:Fe});Cn(()=>{h.current&&(C.current=!0,g({type:"init",tableConfig:e,dataSourceConfig:h.current.config}))},[e,g]),Cn(()=>{t.on("config",(A,N)=>{C.current=!0,g({type:"tableConfig",...A,confirmed:N})})},[t,g]),Ys(()=>{C.current&&(n==null||n({...e,columns:x}),C.current=!1)},[x,e,n]);let[Oe]=Bs(),Ge=J(A=>{var _;let{current:N}=F,{current:$}=h,z=A.target,U=z==null?void 0:z.closest("div[role='cell']"),Q=z==null?void 0:z.closest(".vuuTableRow");if(U&&Q&&N&&$){let{columns:Z,selectedRowsCount:ct}=$,ut=_s(Z),mt=parseInt((_=Q.ariaRowIndex)!=null?_:"-1"),pt=Array.from(Q.childNodes).indexOf(U),dt=N.find(([ft])=>ft===mt),Ue=Z[pt];Oe(A,"grid",{columnMap:ut,columnName:Ue,row:dt,selectedRows:ct===0?js:S(),viewport:t==null?void 0:t.viewport})}},[t==null?void 0:t.viewport,S,Oe]);return{columns:x,columnsWithinViewport:X,containerMeasurements:v,containerProps:V,data:R,dispatchColumnAction:g,getRowOffset:D,handleContextMenuAction:De,headings:f,onColumnResize:$e,onContextMenu:Ge,onRemoveColumnFromGroupBy:Y,onRowClick:y,onSort:Ve,onToggleGroup:B,virtualColSpan:O,scrollProps:xe,rowCount:p,viewportMeasurements:d,...at}};import ni from"classnames";import{isDataLoading as ri}from"@vuu-ui/vuu-utils";import{jsx as Ke,jsxs as vn}from"react/jsx-runtime";var pe="vuuTable",Td=({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:p,onShowConfigEditor:m,renderBufferSize:C=0,rowHeight:h=20,selectionModel:v="extended",style:T,width:x,...g})=>{let f=oi(s),{containerMeasurements:{containerRef:M,innerSize:D,outerSize:w},containerProps:d,dispatchColumnAction:b,draggable:H,draggedItemIndex:y,handleContextMenuAction:R,scrollProps:S,viewportMeasurements:E,...L}=hn({config:o,dataSource:n,renderBufferSize:C,headerHeight:r,height:l,onConfigChange:i,onFeatureEnabled:a,onFeatureInvocation:c,onSelectionChange:p,rowHeight:h,selectionModel:v,width:x});console.log({tableProps:L});let F={...w,"--content-height":`${E.contentHeight}px`,"--horizontal-scrollbar-height":`${E.horizontalScrollbarHeight}px`,"--content-width":`${E.contentWidth}px`,"--pinned-width-left":`${E.pinnedWidthLeft}px`,"--pinned-width-right":`${E.pinnedWidthRight}px`,"--header-height":`${r}px`,"--row-height":`${h}px`,"--table-height":`${D==null?void 0:D.height}px`,"--table-width":`${D==null?void 0:D.width}px`,"--total-header-height":`${E.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${E.verticalScrollbarWidth}px`,"--viewport-body-height":`${E.viewportBodyHeight}px`},ae=ni(pe,t,{[`${pe}-zebra`]:o.zebraStripes,[`${pe}-loading`]:ri(L.columns)});return Ke(ei,{menuActionHandler:R,menuBuilder:Je(n),children:vn("div",{...g,...d,className:ae,id:f,ref:M,style:F,tabIndex:-1,children:[D?Ke("div",{className:`${pe}-scrollbarContainer`,ref:S.scrollbarContainerRef,children:Ke("div",{className:`${pe}-scrollbarContent`})}):null,D?vn("div",{className:`${pe}-contentContainer`,ref:S.contentContainerRef,children:[Ke(Io,{...L,headerHeight:r,tableId:f}),H]}):null,e&&D?Ke(ti,{className:`${pe}-settings`,"data-icon":"settings",onClick:m,variant:"secondary"}):null]})})};import li from"classnames";import{isJsonAttribute as si,metadataKeys as ii,registerComponent as ai}from"@vuu-ui/vuu-utils";import{jsx as Ft,jsxs as di}from"react/jsx-runtime";var ke="vuuJsonCell",{IS_EXPANDED:ci,KEY:ui}=ii,mi=e=>{let t=e.lastIndexOf("|");return t===-1?"":e.slice(t+1)},pi=({column:e,row:t})=>{let{key:o}=e,n=t[o],r=!1;si(n)&&(n=n.slice(0,-1),r=!0);let l=mi(t[ui]),s=li({[`${ke}-name`]:l===n,[`${ke}-value`]:l!==n,[`${ke}-group`]:r});if(r){let i=t[ci]?"minus-box":"plus-box";return di("span",{className:s,children:[Ft("span",{className:`${ke}-value`,children:n}),Ft("span",{className:`${ke}-toggle`,"data-icon":i})]})}else return n?Ft("span",{className:s,children:n}):null};console.log("register JsonCell");ai("json",pi,"cell-renderer",{description:"JSON formatter",label:"JSON formatter",serverDataType:"json"});import Nf from"classnames";import{useRef as If}from"react";import{useCallback as Ot,useRef as fi}from"react";import{jsx as bi}from"react/jsx-runtime";var yn=()=>{},Ci="vuuColumnResizerNext",Ne=({onDrag:e,onDragEnd:t=yn,onDragStart:o=yn})=>{let n=fi(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 bi("div",{className:Ci,onMouseDown:s})};import{useCallback as Gt,useRef as gi,useState as hi}from"react";var ze=({column:e,onResize:t,rootRef:o})=>{let n=gi(0),[r,l]=hi(!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,p)=>{if(o.current&&t){let{width:m}=o.current.getBoundingClientRect(),C=Math.round(m)+p;C!==n.current&&C>0&&(t("resize",s,C),n.current=C)}},[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 vi}from"@vuu-ui/vuu-utils";import yi from"classnames";import{useMemo as Ti}from"react";var te=(e,t,o)=>Ti(()=>{let n=yi(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=vi(e);return{className:n,style:r}},[e,t,o]);import wi from"classnames";import{useCallback as Di}from"react";import{jsx as Mi,jsxs as Ri}from"react/jsx-runtime";var Tn="vuuColumnHeaderPill",de=({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=Di(i=>{i.preventDefault(),i.stopPropagation(),n==null||n(o)},[o,n]);return Ri("div",{...l,className:wi(Tn,t),children:[e,r?Mi("span",{className:`${Tn}-removeButton`,role:"button","data-icon":"cross",onClick:s}):null]})};import{jsx as Wt,jsxs as xi}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 xi(de,{...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 wn,jsxs as Pi}from"react/jsx-runtime";var Dn=({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 Pi(de,{column:e,children:[wn("span",{"data-icon":t}),typeof e.sorted=="number"?wn("span",{className:"vuuSortPosition",children:Math.abs(e.sorted)}):null]})};import{jsx as Bf,jsxs as Uf}from"react/jsx-runtime";import{createElement as Wf}from"react";import Hi from"classnames";import{useCallback as Ei,useRef as Si,useState as Ai}from"react";import{OverflowContainer as Li,useLayoutEffectSkipFirst as Ki}from"@vuu-ui/vuu-layout";import{jsx as _t,jsxs as zi}from"react/jsx-runtime";import{createElement as Ni}from"react";var Ut="vuuTableNextGroupHeaderCell",ki=(e,t)=>e===t?e:t,ot=({column:e,className:t,onRemoveColumn:o,onResize:n,...r})=>{let l=Si(null),{isResizing:s,...i}=ze({column:e,onResize:n,rootRef:l}),[a,c]=Ai(e.columns),{className:u,style:p}=te(e,Ut,!0),m=a.length>1?{removable:!0,onRemove:o}:void 0,C=Ei((h,v)=>{c(T=>{let x=T.slice(),[g]=x.splice(h,1);return v===-1?x.concat(g):(x.splice(v,0,g),x)})},[]);return Ki(()=>{c(h=>ki(h,e.columns))},[e.columns]),zi("div",{...r,className:Hi(u,"vuuTableNextHeaderCell",t,{[`${Ut}-pending`]:e.groupConfirmed===!1}),ref:l,role:"columnheader",style:p,children:[_t(Li,{allowDragDrop:!0,className:`${Ut}-inner`,height:24,onMoveItem:C,overflowPosition:"start",children:a.map(h=>Ni(Bt,{...m,column:h,key:h.key}))}),_t(de,{column:e,removable:!0,onRemove:o}),e.resizeable!==!1?_t(Ne,{...i}):null]})};import{useCallback as Wi,useRef as Bi}from"react";import{useContextMenu as Ii}from"@vuu-ui/vuu-popups";import Vi from"classnames";import{useCallback as Mn,useRef as $i,useState as Fi}from"react";import{jsx as Gi}from"react/jsx-runtime";var Oi=e=>{if(e){let{bottom:t,left:o}=e.getBoundingClientRect();return{x:o,y:t+6}}},Rn=({className:e,column:t,...o})=>{let n=$i(null),[r,l]=Fi(!1),[s]=Ii(),i=Mn(()=>{l(!1)},[]),a=Mn(c=>{l(!0),s(c,"column-menu",{column:t,ContextMenuProps:{onClose:i,position:Oi(n.current)}})},[t,i,s]);return Gi("span",{...o,className:Vi("vuuTable-columnMenu",e,{"vuuTable-columnMenu-open":r}),"data-icon":"more-vert",onClick:a,ref:n})};import Ui from"classnames";import{jsx as nt,jsxs as _i}from"react/jsx-runtime";var Jt="vuuTableNextHeaderCell",xn=({className:e,column:t,onClick:o,onResize:n,...r})=>{var v;let l=Bi(null),{isResizing:s,...i}=ze({column:t,onResize:n,rootRef:l}),a=Wi(T=>{console.log(`click isResizing ${s}`),!s&&(o==null||o(T))},[s,o]),{className:c,style:u}=te(t,Jt,!0),p=nt(Rn,{column:t}),m=nt("div",{className:`${Jt}-label`,children:(v=t.label)!=null?v:t.name}),C=nt(Dn,{column:t}),h=t.align==="right"?[C,m,p]:[p,m,C];return _i("div",{...r,className:Ui(c,e,{[`${Jt}-resizing`]:s}),onClick:a,ref:l,role:"columnheader",style:u,children:[...h,t.resizeable!==!1?nt(Ne,{...i}):null]})};import{ContextMenuProvider as Sc}from"@vuu-ui/vuu-popups";import{isGroupColumn as Ac,metadataKeys as Lc,notHidden as Kc}from"@vuu-ui/vuu-utils";import sr from"classnames";import{forwardRef as kc,useRef as Nc}from"react";import{isGroupColumn as An,isJsonColumn as oa,isJsonGroup as na,metadataKeys as ra,notHidden as la,RowSelected as sa}from"@vuu-ui/vuu-utils";import ia from"classnames";import{memo as aa,useCallback as Ln}from"react";import{metadataKeys as Ji}from"@vuu-ui/vuu-utils";import{useCallback as Pn}from"react";import{jsx as Hn}from"react/jsx-runtime";var{IDX:Xi}=Ji,Qi="vuuTableNextCell",En=({column:e,columnMap:t,onClick:o,onDataEdited:n,row:r})=>{let{className:l,style:s}=te(e,Qi),{CellRenderer:i,name:a,valueFormatter:c}=e,u=t[a],p=Pn(C=>(n==null||n(r[Xi],a,C),!0),[a,n,r]),m=Pn(C=>{o==null||o(C,e)},[e,o]);return Hn("div",{className:l,onClick:o?m:void 0,role:"cell",style:s,children:i?Hn(i,{column:e,columnMap:t,onCommit:p,row:r}):c(r[u])})};import{getGroupValueAndOffset as Yi,metadataKeys as Zi}from"@vuu-ui/vuu-utils";import{useCallback as ji}from"react";import qi from"classnames";import{jsx as Qt,jsxs as ta}from"react/jsx-runtime";var{IS_LEAF:ea}=Zi,Xt="vuuTableNextGroupCell",Sn=({column:e,onClick:t,row:o})=>{let{columns:n}=e,[r,l]=Yi(n,o),{className:s,style:i}=te(e,Xt),a=ji(p=>{t==null||t(p,e)},[e,t]),c=o[ea],u=Array(l).fill(0).map((p,m)=>Qt("span",{className:`${Xt}-spacer`},m));return ta("div",{className:qi(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 pa}from"react";var{IDX:ca,IS_EXPANDED:ua,SELECTED:ma}=ra,le="vuuTableNextRow",Zt=aa(({className:e,columnMap:t,columns:o,row:n,offset:r,onClick:l,onDataEdited:s,onToggleGroup:i,zebraStripes:a=!1,...c})=>{let{[ca]:u,[ua]:p,[ma]:m}=n,C=Ln(M=>{let D=M.shiftKey,w=M.ctrlKey||M.metaKey;l==null||l(n,D,w)},[l,n]),{True:h,First:v,Last:T}=sa,x=ia(le,e,{[`${le}-even`]:a&&u%2===0,[`${le}-expanded`]:p,[`${le}-selected`]:m&h,[`${le}-selectedStart`]:m&v,[`${le}-selectedEnd`]:m&T}),g={transform:`translate3d(0px, ${r}px, 0px)`},f=Ln((M,D)=>{(An(D)||na(D,n))&&(M.stopPropagation(),i==null||i(n,D))},[i,n]);return pa("div",{...c,"aria-rowindex":n[0],key:`row-${n[0]}`,role:"row",className:x,onClick:C,style:g},Yt("span",{className:`${le}-selectionDecorator vuuStickyLeft`}),o.filter(la).map(M=>{let D=An(M),w=oa(M);return Yt(D?Sn:En,{column:M,columnMap:t,onClick:D||w?f:void 0,onDataEdited:s,row:n},M.key)}),Yt("span",{className:`${le}-selectionDecorator vuuStickyRight`}))});Zt.displayName="Row";import{useLayoutEffectSkipFirst as hc}from"@vuu-ui/vuu-layout";import{useTableAndColumnSettings as vc}from"@vuu-ui/vuu-table-extras";import{useDragDropNext as yc}from"@vuu-ui/vuu-ui-controls";import{useCallback as se,useEffect as fa,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})`,Kn=(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 da(r)&&r.querySelector("button")||r},da=e=>e.classList.contains("vuuTableNextCell-editable"),kn=e=>e.querySelector(".vuuTableInputCell")!==null;var Nn=new Set(["Home","End","PageUp","PageDown","ArrowDown","ArrowUp"]),to=new Set(Nn);to.add("ArrowLeft");to.add("ArrowRight");var ba=(e,t)=>{switch(t){case"cell":return to.has(e);case"row":return Nn.has(e);default:return!1}},ga=["Home","End","PageUp","PageDown"],ha=e=>ga.includes(e),va=[-1,-1],ya=[void 0,void 0],Ta=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]:ya;throw Error("Whats going on, cell not found")}else throw Error("Whats going on, scrollbar container not found")};function wa(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 zn=({columnCount:e=0,containerRef:t,disableHighlightOnFocus:o,navigationStyle:n,requestScroll:r,rowCount:l=0,viewportRowCount:s})=>{var w;let i=eo([-1,-1]),a=eo(),c=eo([-1,0]),u=d=>d==null?void 0:d.closest("[role='columnHeader'],[role='cell']"),p=d=>{var b,H;if(d.role==="columnHeader")return[-1,parseInt((b=d.dataset.idx)!=null?b:"-1",10)];{let y=d.closest("[role='row']");if(y){let R=parseInt((H=y.ariaRowIndex)!=null?H:"-1",10),S=Array.from(y.childNodes).indexOf(d);return[R,S]}}return va},m=se(d=>{var b;if(t.current){let H=Kn(t,d);if(H){H!==a.current&&((b=a.current)==null||b.removeAttribute("tabindex"),a.current=H,H.setAttribute("tabindex","0"));let[y,R]=Ta(H);y&&R&&(r==null||r({type:"scroll-distance",distance:R,direction:y})),H.focus()}}},[t,r]),C=se((d,b,H=!1)=>{let y=[d,b];c.current=y,m(y),H&&(i.current=y)},[m]),h=se((d,[b,H])=>new Promise(y=>{let R=b;switch(d){case"PageDown":R=Math.min(l-1,b+s),r==null||r({type:"scroll-page",direction:"down"});break;case"PageUp":R=Math.max(0,b-s),r==null||r({type:"scroll-page",direction:"up"});break;case"Home":R=0,r==null||r({type:"scroll-end",direction:"home"});break;case"End":R=l-1,r==null||r({type:"scroll-end",direction:"end"});break}setTimeout(()=>{y([R,H])},90)}),[r,l,s]),v=se(()=>{var d;if(o!==!0&&(d=t.current)!=null&&d.contains(document.activeElement)){let b=u(document.activeElement);b&&(i.current=p(b))}},[o,t]),T=se(async d=>{let[b,H]=ha(d)?await h(d,c.current):wa(d,c.current,e,l);console.log(`nextRowIdx ${b} nextColIdx ${H}`);let[y,R]=c.current;(b!==y||H!==R)&&C(b,H,!0)},[e,h,l,C]),x=se(d=>{l>0&&ba(d.key,n)&&(d.preventDefault(),d.stopPropagation(),T(d.key))},[l,n,T]),g=se(d=>{let b=d.target,H=u(b);if(H){let[y,R]=p(H);C(y,R)}},[C]),f=se(()=>{T("ArrowDown")},[T]),M=Ca(()=>({navigate:f,onClick:g,onFocus:v,onKeyDown:x}),[g,v,x,f]),D=((w=t.current)==null?void 0:w.firstChild)!=null;return fa(()=>{if(D&&a.current===void 0){let{current:d}=t,b=(d==null?void 0:d.querySelector(jt(0)))||(d==null?void 0:d.querySelector(qt(0,0)));b&&(b.setAttribute("tabindex","0"),a.current=b)}},[t,D]),M};import{applySort as Tc,buildColumnMap as wc,isGroupColumn as Dc,isJsonGroup as Mc,isValidNumber as tr,metadataKeys as Rc,updateColumn as xc,visibleColumnAtIndex as Pc}from"@vuu-ui/vuu-utils";import{useCallback as I,useEffect as or,useMemo as so,useState as io}from"react";var oo=(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 xa,isVuuFeatureInvocation as Pa}from"@vuu-ui/vuu-data-react/src";import{getFullRange as no,NULL_RANGE as In}from"@vuu-ui/vuu-utils";import{useCallback as ro,useEffect as Vn,useMemo as Ha,useRef as lt,useState as Ea}from"react";import{metadataKeys as Da,WindowRange as Ma}from"@vuu-ui/vuu-utils";var{SELECTED:Ra}=Da,rt=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 Ma(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[Ra]!==0)}};var $n=({dataSource:e,onFeatureEnabled:t,onFeatureInvocation:o,onSizeChange:n,onSubscribed:r,range:l=In,renderBufferSize:s=0})=>{let[,i]=Ea(null),a=lt([]),c=lt(!0),u=lt(!1),p=lt(In),m=Ha(()=>new rt(no(l,s)),[]),C=ro(T=>{for(let x of T)m.add(x);a.current=m.data,c.current&&i({})},[m]),h=ro(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?C(T.rows):typeof T.size=="number"&&(a.current=m.data,u.current=!0)):xa(T)?t==null||t(T):Pa(T)?o==null||o(T):console.log(`useDataSource unexpected message ${T.type}`)},[m,t,o,n,r,C]);Vn(()=>()=>{c.current=!0,c.current=!1},[]),Vn(()=>{e==null||e.subscribe({range:no(l,s)},h)},[e,h,l,s]);let v=ro(T=>{let x=no(T,s);m.setRange(x),e.range=p.current=x,e.emit("range",T)},[e,m,s]);return{data:a.current,range:p.current,setRange:v}};import{useMemo as Sa,useRef as Aa}from"react";var Fn=e=>{let t=Aa(e);return Sa(()=>t.current,[])};import{buildColumnMap as La}from"@vuu-ui/vuu-utils";import{useCallback as Ka}from"react";import{useContextMenu as ka}from"@vuu-ui/vuu-popups";var On=({columns:e,data:t})=>{let[o]=ka();return Ka(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=La(e),u=parseInt((a=i.ariaRowIndex)!=null?a:"-1"),p=Array.from(i.childNodes).indexOf(s),m=t.find(([h])=>h===u),C=e[p];o(r,"grid",{columnMap:c,columnName:C,row:m})}},[e,t,o])};import{isCharacterKey as Na}from"@vuu-ui/vuu-utils";import{useCallback as st}from"react";var Gn=({navigate:e})=>{let t=st(()=>{e()},[e]),o=st(l=>{let s=l.target,i=s.querySelector("input");i&&(i.focus(),i.select()),s.addEventListener("vuu-commit",t,!0)},[t]),n=st(l=>{let s=l.target,i=s.querySelector("input");i&&(i.focus(),i.select()),s.addEventListener("vuu-commit",t,!0)},[t]);return{onKeyDown:st(l=>{kn(l.target)&&(Na(l.key)?o(l):l.key==="Enter"&&n(l))},[o,n])}};import{applyFilterToColumns as za,applyGroupByToColumns as Ia,applySortToColumns as Va,getCellRenderer as $a,getColumnLabel as Fa,getTableHeadings as Oa,getValueFormatter as Ga,hasValidationRules as Wa,isFilteredColumn as Ba,isGroupColumn as Ua,isPinned as _a,isTypeDescriptor as Ja,logger as Xa,metadataKeys as Qa,moveItem as Ya,sortPinnedColumns as Wn,stripFilterFromColumns as Za,subscribedOnly as ja}from"@vuu-ui/vuu-utils";import{buildValidationChecker as qa}from"@vuu-ui/vuu-ui-controls";import{useReducer as ec}from"react";var{info:lo}=Xa("useTableModel"),tc=100,oc=Qa.count,nc=({serverDataType:e})=>e===void 0,rc=e=>{var t;if(Ja(e.type))return $a((t=e.type)==null?void 0:t.renderer)},lc=(e,t)=>{var n;let o=t.columns.find(({name:r})=>r===e.name);return o?o.serverDataType:(n=e.serverDataType)!=null?n:"string"},sc=["int","long","double"],Bn=e=>e===void 0?void 0:sc.includes(e)?"right":"left",Un=e=>e.type==="columnSettings",_n=e=>e.type==="tableSettings",ic=(e,t)=>{switch(lo==null||lo(`TableModelReducer ${t.type}`),t.type){case"init":return Xn(t);case"moveColumn":return cc(e,t);case"resizeColumn":return pc(e,t);case"setTableSchema":return dc(e,t);case"hideColumns":return uc(e,t);case"showColumns":return mc(e,t);case"pinColumn":return fc(e,t);case"updateColumnProp":return we(e,t);case"tableConfig":return Yn(e,t);default:return console.log(`unhandled action ${t.type}`),e}},Jn=(e,t)=>{let[o,n]=ec(ic,{tableConfig:e,dataSourceConfig:t},Xn),{columns:r,headings:l,tableConfig:s,...i}=o;return{columns:r,dispatchColumnAction:n,headings:l,tableAttributes:i,tableConfig:s}};function Xn({dataSourceConfig:e,tableConfig:t}){let{columns:o,...n}=t,r=o.filter(ja(e==null?void 0:e.columns)).map(Qn(n)),l=r.some(_a)?Wn(r):r,s={columns:l,headings:Oa(l),tableConfig:t,...n};if(e){let{columns:i,...a}=e;s=Yn(s,{type:"tableConfig",...a})}return s}var ac=(e,t)=>t==="uppercase"?e.toUpperCase():t==="capitalize"?e[0].toUpperCase()+e.slice(1).toLowerCase():e,Qn=e=>(t,o)=>{let{columnDefaultWidth:n=tc,columnFormatHeader:r}=e,{align:l=Bn(t.serverDataType),key:s,name:i,label:a=Fa(t),width:c=n,...u}=t,p={...u,align:l,CellRenderer:rc(t),clientSideEditValidationCheck:Wa(t.type)?qa(t.type.renderer.rules):void 0,label:ac(a,r),key:s!=null?s:o+oc,name:i,originalIdx:o,valueFormatter:Ga(t),width:c};return Ua(p)&&(p.columns=p.columns.map(m=>Qn(e)(m,m.key))),p};function cc(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:Ya(r,l,n)}}return e}function uc(e,{columns:t}){return t.some(o=>o.hidden!==!0)?t.reduce((o,n)=>n.hidden!==!0?we(o,{type:"updateColumnProp",column:n,hidden:!0}):o,e):e}function mc(e,{columns:t}){return t.some(o=>o.hidden)?t.reduce((o,n)=>n.hidden?we(o,{type:"updateColumnProp",column:n,hidden:!1}):o,e):e}function pc(e,{column:t,phase:o,width:n}){let r="updateColumnProp",l=o!=="end";switch(o){case"begin":return we(e,{type:r,column:t,resizing:l});case"end":return we(e,{type:r,column:t,resizing:l,width:n});case"resize":return we(e,{type:r,column:t,width:n});default:throw Error(`useTableModel.resizeColumn, invalid resizePhase ${o}`)}}function dc(e,{tableSchema:t}){let{columns:o}=e;if(o.some(nc)){let n=o.map(r=>{var s;let l=lc(r,t);return{...r,align:(s=r.align)!=null?s:Bn(l),serverDataType:l}});return{...e,columns:n}}else return e}function fc(e,t){let{columns:o}=e,{column:n,pin:r}=t,l=o.find(s=>s.name===n.name);return l?(o=Te(o,{...l,pin:r}),o=Wn(o),{...e,columns:o}):e}function we(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=Te(o,{...c,align:n})),typeof s=="string"&&(o=Te(o,{...c,label:s})),typeof i=="boolean"&&(o=Te(o,{...c,resizing:i})),typeof l=="boolean"&&(o=Te(o,{...c,hidden:l})),typeof a=="number"&&(o=Te(o,{...c,width:a}))),{...e,columns:o}}function Yn(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:Ia(a.columns,n,t)}),i&&(a={...e,columns:Va(a.columns,r)}),s?a={...e,columns:za(a.columns,o)}:a.columns.some(Ba)&&(a={...e,columns:Za(a.columns)}),a}function Te(e,t){return e.map(o=>o.name===t.name?t:o)}import{useCallback as ie,useRef as Ie}from"react";var Zn=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]},jn=({onAttach:e,onDetach:t})=>{let o=Ie(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])},qn=({maxScrollLeft:e,maxScrollTop:t,onHorizontalScroll:o,onVerticalScroll:n,rowHeight:r,viewportRowCount:l})=>{let s=Ie(!1),i=Ie({scrollTop:0,scrollLeft:0}),a=Ie(null),c=Ie(null),u=ie(()=>{let{current:f}=c,{current:M}=a,{current:D}=s;if(D)s.current=!1;else if(f&&M){let[w,d]=Zn(M),b=Math.round(w*e),H=Math.round(d*t);f.scrollTo({left:b,top:H,behavior:"auto"})}},[e,t]),p=ie(()=>{let{current:f}=c,{current:M}=a,{current:D}=i;if(f&&M){let{scrollLeft:w,scrollTop:d}=f,[b,H]=Zn(f);s.current=!0,M.scrollLeft=Math.round(b*e),M.scrollTop=Math.round(H*t),D.scrollTop!==d&&(D.scrollTop=d,n==null||n(d,H)),D.scrollLeft!==w&&(D.scrollLeft=w,o==null||o(w))}},[e,t,o,n]),m=ie(f=>{a.current=f,f.addEventListener("scroll",u,{passive:!0})},[u]),C=ie(f=>{a.current=null,f.removeEventListener("scroll",u)},[u]),h=ie(f=>{c.current=f,f.addEventListener("scroll",p,{passive:!0})},[p]),v=ie(f=>{c.current=null,f.removeEventListener("scroll",p)},[p]),T=jn({onAttach:h,onDetach:v}),x=jn({onAttach:m,onDetach:C}),g=ie(f=>{let{current:M}=c;if(M){let{scrollLeft:D,scrollTop:w}=M;if(s.current=!1,f.type==="scroll-distance"){let d=D,b=w;f.direction==="up"||f.direction==="down"?b=Math.min(Math.max(0,w+f.distance),t):d=Math.min(Math.max(0,D+f.distance),e),M.scrollTo({top:b,left:d,behavior:"auto"})}else if(f.type==="scroll-page"){let{direction:d}=f,b=l*(d==="down"?r:-r),H=Math.min(Math.max(0,w+b),t);M.scrollTo({top:H,left:D,behavior:"auto"})}else if(f.type==="scroll-end"){let{direction:d}=f,b=d==="end"?t:0;M.scrollTo({top:b,left:M.scrollLeft,behavior:"auto"})}}},[e,t,r,l]);return{scrollbarContainerRef:x,contentContainerRef:T,requestScroll:g}};import{useCallback as Cc,useEffect as bc,useRef as gc}from"react";var er=({columns:e,getRowAtPosition:t,setRange:o,viewportMeasurements:n})=>{let r=gc(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 bc(()=>{let{current:a}=r,c={from:a,to:a+s};o(c)},[o,s]),{onVerticalScroll:i}};var{KEY:Hc,IS_EXPANDED:nr,IS_LEAF:rr}=Rc,Ec=(e,t)=>({...e,columns:e.columns.concat(t)}),lr=({availableColumns:e,config:t,containerRef:o,dataSource:n,headerHeight:r=25,navigationStyle:l="cell",onAvailableColumnsChange:s,onConfigChange:i,onFeatureEnabled:a,onFeatureInvocation:c,onRowClick:u,onSelect:p,onSelectionChange:m,renderBufferSize:C=0,rowHeight:h=20,selectionModel:v})=>{let[T,x]=io(n.size);if(n===void 0)throw Error("no data source provided to Vuu Table");let[g,f]=io(),M=I(P=>{f(P)},[]),D=so(()=>Je(n),[n]),w=I(P=>{x(P)},[]),{columns:d,dispatchColumnAction:b,headings:H,tableAttributes:y,tableConfig:R}=Jn(t,n.config);hc(()=>{b({type:"init",dataSourceConfig:n.config,tableConfig:R})},[R,n.config,b]);let[S,E]=io(),[L,F]=so(()=>{let P=(K,k)=>{let G=xc(d,K,{width:k});E(G)};return[S!=null?S:d,P]},[d,S]),ae=so(()=>wc(n.columns),[n.columns]),{getRowAtPosition:De,getRowOffset:Ve,setPctScrollTop:$e,...B}=tt({columns:L,headerHeight:r,headings:H,rowCount:T,rowHeight:h,size:g}),Ce=Fn({from:0,to:B.rowCount}),be=I(({tableSchema:P})=>{P||console.log("usbscription message with no schema")},[]),{data:X,range:O,setRange:Me}=$n({dataSource:n,onFeatureEnabled:a,onFeatureInvocation:c,renderBufferSize:C,onSizeChange:w,onSubscribed:be,range:Ce}),Re=I(P=>{b({type:"init",tableConfig:P,dataSourceConfig:n.config}),i==null||i(P)},[n.config,b,i]),xe=I(P=>{n.config={...n.config,...P}},[n]),V=I(P=>{n.columns=n.columns.concat(P.name);let K=Ec(R,P);b({type:"init",tableConfig:K,dataSourceConfig:n.config}),console.log("dispatch onConfigChange",{newTableConfig:K}),i==null||i(K)},[n,b,i,R]);or(()=>{n.on("config",(P,K)=>{b({type:"tableConfig",...P,confirmed:K})})},[n,b]);let{showColumnSettingsPanel:Y,showTableSettingsPanel:Fe}=vc({availableColumns:e!=null?e:R.columns.map(({name:P,serverDataType:K="string"})=>({name:P,serverDataType:K})),onAvailableColumnsChange:s,onConfigChange:Re,onCreateCalculatedColumn:V,onDataSourceConfigChange:xe,tableConfig:R}),at=I(P=>{Un(P)?Y(P):_n(P)?Fe():b(P)},[b,Y,Fe]),Oe=Xe({dataSource:n,onPersistentColumnOperation:at}),Ge=I((P,K=!1,k)=>{n&&(n.sort=Tc(n.sort,P,K,k))},[n]),We=I((P,K,k)=>{let G=L.find(j=>j.name===K);if(G)P==="resize"?tr(k)&&F(K,k):P==="end"?tr(k)&&(b({type:"resizeColumn",phase:P,column:G,width:k}),i==null||i(oo(R,{type:"col-size",column:G,width:k}))):(E(void 0),b({type:"resizeColumn",phase:P,column:G,width:k}));else throw Error(`useDataTable.handleColumnResize, column ${K} not found`)},[L,R,b,i,F]),Be=I((P,K)=>{let k=Mc(K,P),G=P[Hc];if(P[nr]){if(n.closeTreeNode(G,!0),k){let j=L.indexOf(K);n.getRowsAtDepth(j+1).some(q=>q[nr]||q[rr])||b({type:"hideColumns",columns:L.slice(j+2)})}}else if(n.openTreeNode(G),k){let j=n.getChildRows(G),Pe=L.indexOf(K)+1,q=[L[Pe]];j.some(Ct=>Ct[rr])&&q.push(L[Pe+1]),q.some(Ct=>Ct.hidden)&&b({type:"showColumns",columns:q})}},[L,n,b]),{onVerticalScroll:A}=er({columns:L,getRowAtPosition:De,setRange:Me,viewportMeasurements:B}),N=I(P=>{A(P)},[A]),{requestScroll:$,...z}=qn({maxScrollLeft:B.maxScrollContainerScrollHorizontal,maxScrollTop:B.maxScrollContainerScrollVertical,rowHeight:h,onVerticalScroll:N,viewportRowCount:B.rowCount}),{navigate:U,onKeyDown:Q,..._}=zn({columnCount:L.filter(P=>P.hidden!==!0).length,containerRef:o,navigationStyle:l,requestScroll:$,rowCount:n==null?void 0:n.size,viewportRange:O,viewportRowCount:B.rowCount}),{onKeyDown:Z}=Gn({navigate:U}),ct=I(P=>{Q(P),P.defaultPrevented||Z(P)},[Q,Z]),ut=On({columns:L,data:X}),mt=I(P=>{var q;let k=P.target.closest(".vuuTableNextHeaderCell"),G=parseInt((q=k==null?void 0:k.dataset.index)!=null?q:"-1"),j=Pc(L,G),Pe=P.shiftKey;j&&Ge(j,Pe)},[L,Ge]),pt=I(P=>{Dc(P)?n.groupBy=[]:n&&n.groupBy.includes(P.name)&&(n.groupBy=n.groupBy.filter(K=>K!==P.name))},[n]),dt=I(P=>{n.select(P),m==null||m(P)},[n,m]),Ue=qe({onSelect:p,onSelectionChange:dt,selectionModel:v}),ft=I((P,K,k)=>{Ue(P,K,k),u==null||u(P)},[u,Ue]);or(()=>{n.on("config",(P,K)=>{b({type:"tableConfig",...P,confirmed:K})})},[n,b]);let ar=I((P,K)=>{let k=L[P];b({type:"moveColumn",column:k,moveTo:K})},[L,b]),cr=I((P,K,k)=>n.applyEdit(P,K,k),[n]),{onMouseDown:ur,...mr}=yc({allowDragDrop:!0,containerRef:o,draggableClassName:"vuuTableNext",onDrop:ar,orientation:"horizontal",itemQuery:".vuuTableNextHeaderCell"});return{..._,onKeyDown:ct,columnMap:ae,columns:L,data:X,handleContextMenuAction:Oe,headerProps:{onClick:mt,onMouseDown:ur,onResize:We},menuBuilder:D,onContextMenu:ut,onDataEdited:cr,onRemoveGroupColumn:pt,onResize:M,onRowClick:ft,onToggleGroup:Be,scrollProps:z,tableAttributes:y,viewportMeasurements:B,dragDropHook:mr}};import{MeasuredContainer as zc,useId as Ic}from"@vuu-ui/vuu-layout";import{useForkRef as Vc}from"@salt-ds/core";import{jsx as fe,jsxs as ao}from"react/jsx-runtime";import{createElement as ir}from"react";var W="vuuTableNext",{IDX:$c,RENDER_IDX:Fc}=Lc,Oc=kc(function({Row:t=Zt,availableColumns:o,className:n,config:r,dataSource:l,id:s,navigationStyle:i="cell",onAvailableColumnsChange:a,onConfigChange:c,onFeatureEnabled:u,onFeatureInvocation:p,onRowClick:m,onSelect:C,onSelectionChange:h,onShowConfigEditor:v,renderBufferSize:T=0,rowHeight:x=20,selectionModel:g="extended",showColumnHeaders:f=!0,headerHeight:M=f?25:0,style:D,...w},d){let b=Ic(s),H=Nc(null),{columnMap:y,columns:R,data:S,dragDropHook:E,handleContextMenuAction:L,headerProps:F,onDataEdited:ae,onRemoveGroupColumn:De,onResize:Ve,onRowClick:$e,onToggleGroup:B,menuBuilder:Ce,scrollProps:be,tableAttributes:X,viewportMeasurements:O,...Me}=lr({availableColumns:o,config:r,containerRef:H,dataSource:l,headerHeight:M,navigationStyle:i,onAvailableColumnsChange:a,onConfigChange:c,onFeatureEnabled:u,onFeatureInvocation:p,onRowClick:m,onSelect:C,onSelectionChange:h,renderBufferSize:T,rowHeight:x,selectionModel:g}),Re=()=>({...D,"--content-height":`${O.contentHeight}px`,"--horizontal-scrollbar-height":`${O.horizontalScrollbarHeight}px`,"--content-width":`${O.contentWidth}px`,"--pinned-width-left":`${O.pinnedWidthLeft}px`,"--pinned-width-right":`${O.pinnedWidthRight}px`,"--header-height":`${M}px`,"--row-height":`${x}px`,"--total-header-height":`${O.totalHeaderHeight}px`,"--vertical-scrollbar-width":`${O.verticalScrollbarWidth}px`,"--viewport-body-height":`${O.viewportBodyHeight}px`}),xe=sr(W,n,{[`${W}-colLines`]:X.columnSeparators,[`${W}-rowLines`]:X.rowSeparators,[`${W}-highlight`]:X.showHighlightedRow,[`${W}-zebra`]:X.zebraStripes});return fe(Sc,{menuActionHandler:L,menuBuilder:Ce,children:ao(zc,{...w,className:xe,onResize:Ve,ref:Vc(H,d),style:Re(),children:[fe("div",{className:`${W}-scrollbarContainer`,ref:be.scrollbarContainerRef,children:fe("div",{className:`${W}-scrollbarContent`})}),fe("div",{className:`${W}-contentContainer`,ref:be.contentContainerRef,children:ao("div",{...Me,className:`${W}-table`,tabIndex:-1,children:[f?fe("div",{className:`${W}-col-headings`,children:ao("div",{className:`${W}-col-headers`,role:"row",children:[R.filter(Kc).map((V,Y)=>Ac(V)?ir(ot,{...F,column:V,"data-index":Y,key:V.name,onRemoveColumn:De}):ir(xn,{...F,className:sr({"vuuDraggable-dragAway":Y===E.draggedItemIndex}),column:V,"data-index":Y,id:`${b}-col-${Y}`,key:V.name})),E.draggable]})}):null,fe("div",{className:`${W}-body`,children:S.map(V=>fe(t,{columnMap:y,columns:R,onClick:$e,onDataEdited:ae,row:V,offset:x*V[$c]+M,onToggleGroup:B,zebraStripes:X.zebraStripes},V[Fc]))})]})})]})})});import{Dropdown as Gc}from"@vuu-ui/vuu-ui-controls";import{isColumnTypeRenderer as Wc,isTypeDescriptor as Bc,registerComponent as Uc}from"@vuu-ui/vuu-utils";import{useCallback as _c,useState as Jc}from"react";import{jsx as Zc}from"react/jsx-runtime";var Xc="vuuTableDropdownCell",Qc=["Enter"," "],Yc=({column:e,columnMap:t,row:o})=>{var a,c,u;let n=Bc(e.type)&&Wc((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]=Jc(o[r]),i=_c((p,m)=>{m&&s(m)},[]);return Zc(Gc,{className:Xc,onSelectionChange:i,openKeys:Qc,selected:l,source:n,width:e.width-17})};Uc("dropdown-cell",Yc,"cell-renderer",{});import{registerComponent as jc}from"@vuu-ui/vuu-utils";import{Input as qc}from"@salt-ds/core";import{useEditableText as eu}from"@vuu-ui/vuu-ui-controls";import tu from"classnames";import{jsx as co}from"react/jsx-runtime";var it="vuuTableInputCell",ou=()=>(console.warn("onCommit handler has not been provided to InputCell cell renderer"),!0),nu=({column:e,columnMap:t,onCommit:o=ou,row:n})=>{let r=t[e.name],{align:l="left",clientSideEditValidationCheck:s,valueFormatter:i}=e,{warningMessage:a,...c}=eu({initialValue:i(n[r]),onCommit:o,clientSideEditValidationCheck:s}),u=a&&l==="left"?co("span",{className:`${it}-icon`,"data-icon":"error"}):void 0,p=a&&l==="right"?co("span",{className:`${it}-icon`,"data-icon":"error"}):void 0;return co(qc,{...c,className:tu(it,{[`${it}-error`]:a!==void 0}),endAdornment:u,startAdornment:p})};jc("input-cell",nu,"cell-renderer",{});export{_e as ColumnResizer,ot as GroupHeaderCellNext,Td as Table,Oc as TableNext,Je as buildContextMenuDescriptors,Sp as isShowColumnSettings,Ap as isShowTableSettings,oo as updateTableConfig,jo as useMeasuredContainer,qe as useSelection,Ye as useTableColumnResize,Xe as useTableContextMenu,ln as useTableModel,tt 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