@linzjs/step-ag-grid 29.2.4 → 29.3.0

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.
@@ -13,7 +13,6 @@ export interface ColDefT<TData extends GridBaseRow, ValueType = any> extends Col
13
13
  editable?: boolean | EditableCallback<TData, ValueType>;
14
14
  valueGetter?: string | ValueGetterFunc<TData, ValueType>;
15
15
  valueFormatter?: string | ValueFormatterFunc<TData, ValueType>;
16
- maxInitialWidth?: number;
17
16
  cellRenderer?: ((props: ICellRendererParams<TData, ValueType>) => ReactElement | string | false | null | undefined) | string;
18
17
  cellRendererParams?: {
19
18
  rightHoverElement?: ReactElement;
@@ -1,5 +1,7 @@
1
- import { PropsWithChildren } from 'react';
2
1
  export interface GridWrapperProps {
2
+ className?: string | undefined;
3
3
  maxHeight?: number | string;
4
4
  }
5
- export declare const GridWrapper: ({ children, maxHeight }: PropsWithChildren<GridWrapperProps>) => import("react/jsx-runtime").JSX.Element;
5
+ export declare const GridWrapper: import("react").ForwardRefExoticComponent<GridWrapperProps & {
6
+ children?: import("react").ReactNode | undefined;
7
+ } & import("react").RefAttributes<HTMLDivElement>>;
@@ -2779,6 +2779,8 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2779
2779
  const hasSetContentSizeEmpty = React.useRef(false);
2780
2780
  const needsAutoSize = React.useRef(true);
2781
2781
  const lastFullResize = React.useRef();
2782
+ const autoSizeResultRef = React.useRef(null);
2783
+ const prevRowsVisibleRef = React.useRef(false);
2782
2784
  const setInitialContentSize = React.useCallback(() => {
2783
2785
  if (!gridDivRef.current?.clientWidth || rowData == null) {
2784
2786
  // Don't resize grids if they are offscreen as it doesn't work.
@@ -2791,37 +2793,50 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2791
2793
  needsAutoSize.current = true;
2792
2794
  return;
2793
2795
  }
2794
- const skipHeader = sizeColumns === 'auto-skip-headers' && gridRendered === 'rows-visible';
2795
- if (sizeColumns === 'auto' || skipHeader) {
2796
- const result = autoSizeColumns({
2797
- skipHeader,
2798
- userSizedColIds: new Set(userSizedColIds.current.keys()),
2799
- includeFlex: true,
2800
- });
2801
- if (!result) {
2796
+ // 1. First we autosize to get the size of the columns on an infinite grid.
2797
+ if (sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') {
2798
+ // You can't skip headers until the grid has content
2799
+ const rowsVisible = gridRendered === 'rows-visible';
2800
+ const skipHeader = sizeColumns === 'auto-skip-headers' && rowsVisible;
2801
+ // If grid was empty and now has content we need to autosize
2802
+ if (rowsVisible !== prevRowsVisibleRef.current && rowsVisible) {
2803
+ prevRowsVisibleRef.current = rowsVisible;
2804
+ autoSizeResultRef.current = null;
2805
+ }
2806
+ const autoSizeResult = autoSizeResultRef.current ??
2807
+ autoSizeColumns({
2808
+ skipHeader,
2809
+ userSizedColIds: new Set(userSizedColIds.current.keys()),
2810
+ });
2811
+ // Auto-size failed retry later
2812
+ if (!autoSizeResult) {
2802
2813
  needsAutoSize.current = true;
2803
2814
  return;
2804
2815
  }
2805
- // Default max intial width is 256x initial visible column count, max of 80% window width
2806
- const maxWidth = maxInitialWidth ||
2807
- lodashEs.sum(params.columnDefs.map((c) => (!c.hide ? c.maxInitialWidth || 128 : 0)));
2808
- result.width = Math.min(result.width, maxWidth);
2816
+ autoSizeResultRef.current = autoSizeResult;
2817
+ // Calculate the auto-sized width, limit it to maxInitialWidth
2818
+ autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
2809
2819
  if (gridRendered === 'empty') {
2820
+ // If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
2821
+ // We don't do this callback if we have previously had row data, or have already called back for empty
2810
2822
  if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
2811
2823
  hasSetContentSizeEmpty.current = true;
2812
- params.onContentSize?.(result);
2824
+ params.onContentSize?.(autoSizeResult);
2813
2825
  }
2814
2826
  }
2815
2827
  else if (gridRendered === 'rows-visible') {
2828
+ // we have rows now so callback grid size
2816
2829
  if (!hasSetContentSize.current) {
2817
- if (lastFullResize.current === result.width) {
2830
+ // Only callback if grid size has settled
2831
+ if (lastFullResize.current === autoSizeResult.width) {
2818
2832
  hasSetContentSize.current = true;
2819
- params.onContentSize?.(result);
2833
+ params.onContentSize?.(autoSizeResult);
2820
2834
  }
2821
2835
  else {
2822
- needsAutoSize.current = true;
2836
+ // Need to retry callback when size has settelled
2837
+ lastFullResize.current = autoSizeResult.width;
2838
+ return;
2823
2839
  }
2824
- lastFullResize.current = result.width;
2825
2840
  }
2826
2841
  }
2827
2842
  else {
@@ -2829,6 +2844,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2829
2844
  console.error('Unknown value returned from hasGridRendered');
2830
2845
  }
2831
2846
  }
2847
+ // 2. Now we size columns to fit the grid width
2832
2848
  if (sizeColumns !== 'none') {
2833
2849
  sizeColumnsToFit();
2834
2850
  }
@@ -2986,6 +3002,8 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2986
3002
  const onRowDataChanged = React.useCallback(() => {
2987
3003
  const length = rowData?.length ?? 0;
2988
3004
  if (previousRowDataLength.current !== length) {
3005
+ // We need to autosize all cells again
3006
+ autoSizeResultRef.current = null;
2989
3007
  setInitialContentSize();
2990
3008
  previousRowDataLength.current = length;
2991
3009
  }
@@ -3128,12 +3146,15 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3128
3146
  /**
3129
3147
  * Resize columns to fit if required on window/container resize
3130
3148
  */
3131
- const onGridSizeChanged = React.useCallback((event) => {
3149
+ const onGridResize = React.useCallback((event) => {
3132
3150
  if (sizeColumns !== 'none') {
3151
+ // Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
3152
+ // Double click column resize handle to reset this behaviour
3133
3153
  const columnLimits = [
3134
3154
  ...userSizedColIds.current.entries().map(([c, w]) => ({
3135
3155
  key: c,
3136
3156
  minWidth: w,
3157
+ maxWidth: w,
3137
3158
  })),
3138
3159
  ];
3139
3160
  event.api.sizeColumnsToFit({ columnLimits });
@@ -3158,12 +3179,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3158
3179
  switch (e.source) {
3159
3180
  case 'uiColumnResized':
3160
3181
  userSizedColIds.current.set(colId, width);
3182
+ const colDef = e.column?.getColDef();
3183
+ if (!colDef?.flex) {
3184
+ onGridResize(e);
3185
+ }
3161
3186
  break;
3162
3187
  case 'autosizeColumns':
3163
3188
  userSizedColIds.current.delete(colId);
3189
+ onGridResize(e);
3164
3190
  break;
3165
3191
  }
3166
- }, []);
3192
+ }, [onGridResize]);
3167
3193
  const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
3168
3194
  const startDragYRef = React.useRef(null);
3169
3195
  const clearHighlightRowClasses = React.useCallback(() => {
@@ -3260,6 +3286,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3260
3286
  return (jsxRuntime.jsx(GridNoRowsOverlay, { loading: !rowData || params.loading === true, rowCount: rowCount, headerRowHeight: headerRowCount * rowHeight, filteredRowCount: event.api.getDisplayedRowCount(), noRowsOverlayText: params.noRowsOverlayText, noRowsMatchingOverlayText: params.noRowsMatchingOverlayText }));
3261
3287
  }, [columnDefs, params.loading, params.noRowsMatchingOverlayText, params.noRowsOverlayText, rowData, rowHeight]);
3262
3288
  const selectionColumnDef = React.useMemo(() => {
3289
+ // Note this has to be 1 for hidden otherwise ag-grid does crazy things whilst resizing
3263
3290
  const selectWidth = params.hideSelectColumn ? 0 : selectable && params.onRowDragEnd ? 76 : 48;
3264
3291
  return {
3265
3292
  suppressNavigable: params.hideSelectColumn,
@@ -3305,7 +3332,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3305
3332
  enableClickSelection: params.enableClickSelection ?? false,
3306
3333
  mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
3307
3334
  }
3308
- : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataChanged, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, selectionColumnDef: selectionColumnDef, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
3335
+ : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridResize, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataChanged, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: defaultColDef, columnDefs: columnDefsAdjusted, selectionColumnDef: selectionColumnDef, rowData: rowData, postSortRows: params.onRowDragEnd || !defaultPostSort ? undefined : postSortRows, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, quickFilterParser: quickFilterParser, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, noRowsOverlayComponent: noRowsOverlayComponent, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true, preventDefaultOnContextMenu: true, onCellContextMenu: gridContextMenu.cellContextMenu, rowDragText: params.rowDragText, onRowDragCancel: clearHighlightRowClasses, onRowDragMove: onRowDragMove, onRowDragEnd: onRowDragEnd, suppressCellFocus: params.suppressCellFocus, pinnedTopRowData: params.pinnedTopRowData, pinnedBottomRowData: params.pinnedBottomRowData, onRowClicked: params.onRowClicked, onRowDoubleClicked: params.onRowDoubleClicked, suppressStartEditOnTab: true }) })] }));
3309
3336
  };
3310
3337
  const quickFilterParser = (filterStr) => {
3311
3338
  // filter is exact matches exactly groups separated by commas
@@ -5140,7 +5167,9 @@ const GridPopoverTextInput = (colDef, params) => GridCell(colDef, {
5140
5167
  ...params,
5141
5168
  });
5142
5169
 
5143
- const GridWrapper = ({ children, maxHeight }) => (jsxRuntime.jsx("div", { className: 'Grid-wrapper', style: { maxHeight }, children: children }));
5170
+ const GridWrapper = React.forwardRef(function GridWrapperFr({ children, maxHeight, className }, ref) {
5171
+ return (jsxRuntime.jsx("div", { className: clsx('Grid-wrapper', className), style: { maxHeight }, ref: ref, children: children }));
5172
+ });
5144
5173
 
5145
5174
  const getColId = (colDef) => colDef.colId ?? '';
5146
5175
  const isFlexColumn = (colDef) => !!colDef.flex && !isGridCellFiller(colDef);