@linzjs/step-ag-grid 29.2.4 → 29.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/components/GridCell.d.ts +0 -1
- package/dist/src/components/GridWrapper.d.ts +4 -2
- package/dist/step-ag-grid.cjs +60 -30
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +61 -31
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -2
- package/src/components/Grid.tsx +83 -52
- package/src/components/GridCell.tsx +0 -1
- package/src/components/GridWrapper.tsx +13 -6
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingAgGrid.stories.tsx +1 -1
|
@@ -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:
|
|
5
|
+
export declare const GridWrapper: import("react").ForwardRefExoticComponent<GridWrapperProps & {
|
|
6
|
+
children?: import("react").ReactNode | undefined;
|
|
7
|
+
} & import("react").RefAttributes<HTMLDivElement>>;
|
package/dist/step-ag-grid.cjs
CHANGED
|
@@ -2778,7 +2778,9 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2778
2778
|
const hasSetContentSize = React.useRef(false);
|
|
2779
2779
|
const hasSetContentSizeEmpty = React.useRef(false);
|
|
2780
2780
|
const needsAutoSize = React.useRef(true);
|
|
2781
|
-
const
|
|
2781
|
+
const requiresInitialSizeToFitRef = React.useRef(true);
|
|
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,46 +2793,60 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2791
2793
|
needsAutoSize.current = true;
|
|
2792
2794
|
return;
|
|
2793
2795
|
}
|
|
2794
|
-
|
|
2795
|
-
if (sizeColumns === 'auto' ||
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
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
|
+
includeFlex: true,
|
|
2811
|
+
});
|
|
2812
|
+
// Auto-size failed retry later
|
|
2813
|
+
if (!autoSizeResult) {
|
|
2802
2814
|
needsAutoSize.current = true;
|
|
2803
2815
|
return;
|
|
2804
2816
|
}
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
result.width = Math.min(result.width, maxWidth);
|
|
2817
|
+
autoSizeResultRef.current = autoSizeResult;
|
|
2818
|
+
// Calculate the auto-sized width, limit it to maxInitialWidth
|
|
2819
|
+
autoSizeResult.width = maxInitialWidth ? Math.min(autoSizeResult.width, maxInitialWidth) : autoSizeResult.width;
|
|
2809
2820
|
if (gridRendered === 'empty') {
|
|
2821
|
+
// If the grid is empty we still do an onContentSize callback, we will do another callback when grid has data
|
|
2822
|
+
// We don't do this callback if we have previously had row data, or have already called back for empty
|
|
2810
2823
|
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
2811
2824
|
hasSetContentSizeEmpty.current = true;
|
|
2812
|
-
|
|
2825
|
+
requiresInitialSizeToFitRef.current = true;
|
|
2826
|
+
params.onContentSize?.(autoSizeResult);
|
|
2813
2827
|
}
|
|
2814
2828
|
}
|
|
2815
2829
|
else if (gridRendered === 'rows-visible') {
|
|
2830
|
+
// we have rows now so callback grid size
|
|
2816
2831
|
if (!hasSetContentSize.current) {
|
|
2817
|
-
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
}
|
|
2821
|
-
else {
|
|
2822
|
-
needsAutoSize.current = true;
|
|
2823
|
-
}
|
|
2824
|
-
lastFullResize.current = result.width;
|
|
2832
|
+
hasSetContentSize.current = true;
|
|
2833
|
+
requiresInitialSizeToFitRef.current = true;
|
|
2834
|
+
params.onContentSize?.(autoSizeResult);
|
|
2825
2835
|
}
|
|
2826
2836
|
}
|
|
2827
2837
|
else {
|
|
2828
2838
|
// It should be impossible to get here
|
|
2829
2839
|
console.error('Unknown value returned from hasGridRendered');
|
|
2830
2840
|
}
|
|
2831
|
-
|
|
2832
|
-
|
|
2833
|
-
|
|
2841
|
+
// If there's no contentSize callback there'll be on onGridResize callback
|
|
2842
|
+
// which is required to run sizeColumnsToFit.
|
|
2843
|
+
// There's also the possibility that the panel was already the right size so didn't trigger onGridResize.
|
|
2844
|
+
lodashEs.delay(() => {
|
|
2845
|
+
if (requiresInitialSizeToFitRef.current) {
|
|
2846
|
+
requiresInitialSizeToFitRef.current = false;
|
|
2847
|
+
sizeColumnsToFit();
|
|
2848
|
+
}
|
|
2849
|
+
}, 50);
|
|
2834
2850
|
}
|
|
2835
2851
|
setAutoSized(true);
|
|
2836
2852
|
needsAutoSize.current = false;
|
|
@@ -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,15 +3146,19 @@ 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
|
|
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
|
+
requiresInitialSizeToFitRef.current = false;
|
|
3161
|
+
lodashEs.defer(() => event.api.sizeColumnsToFit({ columnLimits }));
|
|
3140
3162
|
}
|
|
3141
3163
|
}, [sizeColumns]);
|
|
3142
3164
|
/**
|
|
@@ -3158,12 +3180,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3158
3180
|
switch (e.source) {
|
|
3159
3181
|
case 'uiColumnResized':
|
|
3160
3182
|
userSizedColIds.current.set(colId, width);
|
|
3183
|
+
const colDef = e.column?.getColDef();
|
|
3184
|
+
if (!colDef?.flex) {
|
|
3185
|
+
onGridResize(e);
|
|
3186
|
+
}
|
|
3161
3187
|
break;
|
|
3162
3188
|
case 'autosizeColumns':
|
|
3163
3189
|
userSizedColIds.current.delete(colId);
|
|
3190
|
+
onGridResize(e);
|
|
3164
3191
|
break;
|
|
3165
3192
|
}
|
|
3166
|
-
}, []);
|
|
3193
|
+
}, [onGridResize]);
|
|
3167
3194
|
const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
|
|
3168
3195
|
const startDragYRef = React.useRef(null);
|
|
3169
3196
|
const clearHighlightRowClasses = React.useCallback(() => {
|
|
@@ -3260,6 +3287,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3260
3287
|
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
3288
|
}, [columnDefs, params.loading, params.noRowsMatchingOverlayText, params.noRowsOverlayText, rowData, rowHeight]);
|
|
3262
3289
|
const selectionColumnDef = React.useMemo(() => {
|
|
3290
|
+
// Note this has to be 1 for hidden otherwise ag-grid does crazy things whilst resizing
|
|
3263
3291
|
const selectWidth = params.hideSelectColumn ? 0 : selectable && params.onRowDragEnd ? 76 : 48;
|
|
3264
3292
|
return {
|
|
3265
3293
|
suppressNavigable: params.hideSelectColumn,
|
|
@@ -3305,7 +3333,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3305
3333
|
enableClickSelection: params.enableClickSelection ?? false,
|
|
3306
3334
|
mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
|
|
3307
3335
|
}
|
|
3308
|
-
: undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged:
|
|
3336
|
+
: 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
3337
|
};
|
|
3310
3338
|
const quickFilterParser = (filterStr) => {
|
|
3311
3339
|
// filter is exact matches exactly groups separated by commas
|
|
@@ -5140,7 +5168,9 @@ const GridPopoverTextInput = (colDef, params) => GridCell(colDef, {
|
|
|
5140
5168
|
...params,
|
|
5141
5169
|
});
|
|
5142
5170
|
|
|
5143
|
-
const GridWrapper = ({ children, maxHeight
|
|
5171
|
+
const GridWrapper = React.forwardRef(function GridWrapperFr({ children, maxHeight, className }, ref) {
|
|
5172
|
+
return (jsxRuntime.jsx("div", { className: clsx('Grid-wrapper', className), style: { maxHeight }, ref: ref, children: children }));
|
|
5173
|
+
});
|
|
5144
5174
|
|
|
5145
5175
|
const getColId = (colDef) => colDef.colId ?? '';
|
|
5146
5176
|
const isFlexColumn = (colDef) => !!colDef.flex && !isGridCellFiller(colDef);
|