@linzjs/step-ag-grid 29.1.6 → 29.2.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/Grid.d.ts +2 -1
- package/dist/step-ag-grid.cjs +56 -18
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +56 -18
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +2 -1
- package/src/components/Grid.tsx +66 -17
- package/src/contexts/GridContextProvider.tsx +3 -1
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingAgGrid.stories.tsx +28 -0
- package/src/stories/grid/gridAutosize/ShowPanelResizingAgGrid/ShowPanelResizingStepAgGrid.tsx +169 -0
|
@@ -84,8 +84,9 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
|
|
|
84
84
|
pinnedBottomRowData?: GridOptions['pinnedBottomRowData'];
|
|
85
85
|
onRowClicked?: (event: RowClickedEvent) => void;
|
|
86
86
|
onRowDoubleClicked?: (event: RowDoubleClickedEvent) => void;
|
|
87
|
+
allowResizeInStorybook?: boolean;
|
|
87
88
|
}
|
|
88
89
|
/**
|
|
89
90
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
90
91
|
*/
|
|
91
|
-
export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ "data-testid": dataTestId, defaultPostSort, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, singleClickEdit, rowData, rowHeight, selectable, onCellFocused: paramsOnCellFocused, ...params }: GridProps<TData>) => ReactElement;
|
|
92
|
+
export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ "data-testid": dataTestId, defaultPostSort, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, singleClickEdit, rowData, rowHeight, selectable, allowResizeInStorybook, onCellFocused: paramsOnCellFocused, ...params }: GridProps<TData>) => ReactElement;
|
package/dist/step-ag-grid.cjs
CHANGED
|
@@ -2762,7 +2762,7 @@ agGridCommunity.ModuleRegistry.registerModules([agGridCommunity.AllCommunityModu
|
|
|
2762
2762
|
/**
|
|
2763
2763
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
2764
2764
|
*/
|
|
2765
|
-
const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection = 'multiple', suppressColumnVirtualization = true, theme = 'ag-theme-step-default', sizeColumns = 'auto', selectColumnPinned = 'left', contextMenuSelectRow = false, singleClickEdit = false, rowData, rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40, selectable, onCellFocused: paramsOnCellFocused, ...params }) => {
|
|
2765
|
+
const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection = 'multiple', suppressColumnVirtualization = true, theme = 'ag-theme-step-default', sizeColumns = 'auto', selectColumnPinned = 'left', contextMenuSelectRow = false, singleClickEdit = false, rowData, rowHeight = theme === 'ag-theme-step-default' ? 40 : theme === 'ag-theme-step-compact' ? 36 : 40, selectable, allowResizeInStorybook, onCellFocused: paramsOnCellFocused, ...params }) => {
|
|
2766
2766
|
const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
|
|
2767
2767
|
const { updatedDep, updatingCols } = React.useContext(GridUpdatingContext);
|
|
2768
2768
|
const gridDivRef = React.useRef(null);
|
|
@@ -2793,7 +2793,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2793
2793
|
}
|
|
2794
2794
|
const skipHeader = sizeColumns === 'auto-skip-headers' && gridRendered === 'rows-visible';
|
|
2795
2795
|
if (sizeColumns === 'auto' || skipHeader) {
|
|
2796
|
-
const result = autoSizeColumns({
|
|
2796
|
+
const result = autoSizeColumns({
|
|
2797
|
+
skipHeader,
|
|
2798
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
2799
|
+
includeFlex: true,
|
|
2800
|
+
});
|
|
2797
2801
|
if (!result) {
|
|
2798
2802
|
needsAutoSize.current = true;
|
|
2799
2803
|
return;
|
|
@@ -2828,10 +2832,27 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2828
2832
|
needsAutoSize.current = false;
|
|
2829
2833
|
}, [autoSizeColumns, gridRenderState, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
2830
2834
|
const lastOwnerDocumentRef = React.useRef();
|
|
2835
|
+
const wasVisibleRef = React.useRef(false);
|
|
2831
2836
|
/**
|
|
2832
2837
|
* Auto-size windows that had deferred auto-size
|
|
2838
|
+
* Reset focus if panel went from invisible to visible.
|
|
2833
2839
|
*/
|
|
2834
2840
|
useInterval(() => {
|
|
2841
|
+
// If grid has become visible after previously being hidden, then refocus the last focused cell.
|
|
2842
|
+
const visible = !!gridDivRef.current?.checkVisibility();
|
|
2843
|
+
if (visible && !wasVisibleRef.current) {
|
|
2844
|
+
wasVisibleRef.current = true;
|
|
2845
|
+
const el = window.__stepaggrid_lastfocuseventtarget;
|
|
2846
|
+
if (el) {
|
|
2847
|
+
// Setting this to null will cause a new refocus event
|
|
2848
|
+
window.__stepaggrid_lastfocuseventtarget = null;
|
|
2849
|
+
// Check element is still part of document
|
|
2850
|
+
if (el.checkVisibility()) {
|
|
2851
|
+
el.focus();
|
|
2852
|
+
}
|
|
2853
|
+
}
|
|
2854
|
+
}
|
|
2855
|
+
wasVisibleRef.current = visible;
|
|
2835
2856
|
// Check if window has been popped out and needs resize
|
|
2836
2857
|
const currentDocument = gridDivRef.current?.ownerDocument;
|
|
2837
2858
|
if (currentDocument !== lastOwnerDocumentRef.current) {
|
|
@@ -2972,7 +2993,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2972
2993
|
return;
|
|
2973
2994
|
const skipHeader = sizeColumns === 'auto-skip-headers';
|
|
2974
2995
|
if (hasSetContentSize.current) {
|
|
2975
|
-
autoSizeColumns({
|
|
2996
|
+
autoSizeColumns({
|
|
2997
|
+
skipHeader,
|
|
2998
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
2999
|
+
colIds: colIdsEdited.current,
|
|
3000
|
+
});
|
|
2976
3001
|
}
|
|
2977
3002
|
colIdsEdited.current.clear();
|
|
2978
3003
|
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
|
|
@@ -3070,7 +3095,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3070
3095
|
if (hasSetContentSize.current) {
|
|
3071
3096
|
autoSizeColumns({
|
|
3072
3097
|
skipHeader,
|
|
3073
|
-
userSizedColIds: userSizedColIds.current,
|
|
3098
|
+
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
3074
3099
|
colIds: colIdsEdited.current,
|
|
3075
3100
|
});
|
|
3076
3101
|
}
|
|
@@ -3099,25 +3124,36 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3099
3124
|
/**
|
|
3100
3125
|
* Resize columns to fit if required on window/container resize
|
|
3101
3126
|
*/
|
|
3102
|
-
const onGridSizeChanged = React.useCallback(() => {
|
|
3103
|
-
if (sizeColumns !== 'none') {
|
|
3104
|
-
|
|
3127
|
+
const onGridSizeChanged = React.useCallback((event) => {
|
|
3128
|
+
if (sizeColumns !== 'none' && (!window.__STORYBOOK_PREVIEW__ || allowResizeInStorybook)) {
|
|
3129
|
+
const columnLimits = [
|
|
3130
|
+
...userSizedColIds.current.entries().map(([c, w]) => ({
|
|
3131
|
+
key: c,
|
|
3132
|
+
minWidth: w,
|
|
3133
|
+
})),
|
|
3134
|
+
];
|
|
3135
|
+
event.api.sizeColumnsToFit({ columnLimits });
|
|
3105
3136
|
}
|
|
3106
|
-
}, [
|
|
3137
|
+
}, [allowResizeInStorybook, sizeColumns]);
|
|
3107
3138
|
/**
|
|
3108
3139
|
* Set of column I'd's that are prevented from auto-sizing as they are user set
|
|
3109
3140
|
*/
|
|
3110
|
-
const userSizedColIds = React.useRef(new
|
|
3141
|
+
const userSizedColIds = React.useRef(new Map());
|
|
3111
3142
|
/**
|
|
3112
3143
|
* Lock/unlock column width on user edit/reset.
|
|
3113
3144
|
*/
|
|
3114
3145
|
const onColumnResized = React.useCallback((e) => {
|
|
3115
3146
|
const colId = e.column?.getColId();
|
|
3116
|
-
if (colId == null)
|
|
3147
|
+
if (colId == null) {
|
|
3148
|
+
return;
|
|
3149
|
+
}
|
|
3150
|
+
const width = e.column?.getActualWidth();
|
|
3151
|
+
if (width == null) {
|
|
3117
3152
|
return;
|
|
3153
|
+
}
|
|
3118
3154
|
switch (e.source) {
|
|
3119
|
-
case '
|
|
3120
|
-
userSizedColIds.current.
|
|
3155
|
+
case 'uiColumnResized':
|
|
3156
|
+
userSizedColIds.current.set(colId, width);
|
|
3121
3157
|
break;
|
|
3122
3158
|
case 'autosizeColumns':
|
|
3123
3159
|
userSizedColIds.current.delete(colId);
|
|
@@ -3158,7 +3194,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3158
3194
|
}
|
|
3159
3195
|
}, [clearHighlightRowClasses]);
|
|
3160
3196
|
const onCellFocused = React.useCallback((event) => {
|
|
3161
|
-
if (
|
|
3197
|
+
if (event.rowIndex == null) {
|
|
3162
3198
|
return;
|
|
3163
3199
|
}
|
|
3164
3200
|
const api = event.api;
|
|
@@ -3172,15 +3208,16 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3172
3208
|
if (!colDef || typeof colDef === 'string') {
|
|
3173
3209
|
return;
|
|
3174
3210
|
}
|
|
3175
|
-
// Prevent repeated callbacks to cell focus when
|
|
3211
|
+
// Prevent repeated callbacks to cell focus when focus didn't change
|
|
3176
3212
|
const { sourceEvent } = event;
|
|
3177
3213
|
if (sourceEvent) {
|
|
3178
|
-
|
|
3214
|
+
const cell = sourceEvent.target?.closest?.('.ag-cell') ?? null;
|
|
3215
|
+
if (window.__stepaggrid_lastfocuseventtarget === cell) {
|
|
3179
3216
|
return;
|
|
3180
3217
|
}
|
|
3181
|
-
window.__stepaggrid_lastfocuseventtarget =
|
|
3218
|
+
window.__stepaggrid_lastfocuseventtarget = cell;
|
|
3182
3219
|
}
|
|
3183
|
-
paramsOnCellFocused({ colDef, data });
|
|
3220
|
+
paramsOnCellFocused?.({ colDef, data });
|
|
3184
3221
|
}, [paramsOnCellFocused]);
|
|
3185
3222
|
const onRowDragEnd = React.useCallback((event) => {
|
|
3186
3223
|
clearHighlightRowClasses();
|
|
@@ -5399,8 +5436,9 @@ const GridContextProvider = (props) => {
|
|
|
5399
5436
|
* Resize columns to fit container
|
|
5400
5437
|
*/
|
|
5401
5438
|
const autoSizeColumns = React.useCallback(({ skipHeader, colIds, userSizedColIds, includeFlex } = {}) => {
|
|
5402
|
-
if (!gridApi || !gridApi.getColumnState())
|
|
5439
|
+
if (!gridApi || !gridApi.getColumnState()) {
|
|
5403
5440
|
return null;
|
|
5441
|
+
}
|
|
5404
5442
|
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
|
|
5405
5443
|
const colsToResize = gridApi.getColumnState()?.filter?.((colState) => {
|
|
5406
5444
|
const colId = colState.colId;
|