@linzjs/step-ag-grid 29.3.2 → 29.3.3
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/step-ag-grid.cjs +30 -10
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +31 -11
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +36 -11
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -2,7 +2,7 @@ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
|
2
2
|
import { LuiMiniSpinner, LuiStatusSpinner, LuiIcon, LuiButtonGroup, LuiButton, LuiCheckboxInput } from '@linzjs/lui';
|
|
3
3
|
import { ModuleRegistry, AllCommunityModule } from 'ag-grid-community';
|
|
4
4
|
import { AgGridReact } from 'ag-grid-react';
|
|
5
|
-
import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, omit, sortBy,
|
|
5
|
+
import { negate, isEmpty, findIndex, defer, debounce as debounce$1, xorBy, last, difference, delay, omit, sortBy, partition, compact, pick, groupBy, fromPairs, toPairs, isEqual, pull, filter, sumBy, remove, flatten, castArray } from 'lodash-es';
|
|
6
6
|
import React, { useRef, useLayoutEffect, useEffect, createContext, useContext, useState, useMemo, memo, forwardRef, useCallback, useReducer, cloneElement, useImperativeHandle, Fragment as Fragment$1, useId } from 'react';
|
|
7
7
|
import { unstable_batchedUpdates, flushSync, createPortal } from 'react-dom';
|
|
8
8
|
|
|
@@ -2762,7 +2762,7 @@ ModuleRegistry.registerModules([AllCommunityModule]);
|
|
|
2762
2762
|
*/
|
|
2763
2763
|
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, maxInitialWidth, ...params }) => {
|
|
2764
2764
|
const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
|
|
2765
|
-
const { updatedDep, updatingCols } = useContext(GridUpdatingContext);
|
|
2765
|
+
const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
|
|
2766
2766
|
const gridDivRef = useRef(null);
|
|
2767
2767
|
const lastSelectedIds = useRef([]);
|
|
2768
2768
|
const [staleGrid, setStaleGrid] = useState(false);
|
|
@@ -2776,7 +2776,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2776
2776
|
const hasSetContentSize = useRef(false);
|
|
2777
2777
|
const hasSetContentSizeEmpty = useRef(false);
|
|
2778
2778
|
const needsAutoSize = useRef(true);
|
|
2779
|
-
const requiresInitialSizeToFitRef = useRef(
|
|
2779
|
+
const requiresInitialSizeToFitRef = useRef(false);
|
|
2780
2780
|
const autoSizeResultRef = useRef(null);
|
|
2781
2781
|
const prevRowsVisibleRef = useRef(false);
|
|
2782
2782
|
const setInitialContentSize = useCallback(() => {
|
|
@@ -2837,9 +2837,12 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2837
2837
|
console.error('Unknown value returned from hasGridRendered');
|
|
2838
2838
|
}
|
|
2839
2839
|
}
|
|
2840
|
+
else {
|
|
2841
|
+
sizeColumnsToFit();
|
|
2842
|
+
}
|
|
2840
2843
|
setAutoSized(true);
|
|
2841
2844
|
needsAutoSize.current = false;
|
|
2842
|
-
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns]);
|
|
2845
|
+
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
2843
2846
|
const lastOwnerDocumentRef = useRef();
|
|
2844
2847
|
const wasVisibleRef = useRef(false);
|
|
2845
2848
|
/**
|
|
@@ -2988,7 +2991,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2988
2991
|
* This will resize columns when we have at least one row.
|
|
2989
2992
|
*/
|
|
2990
2993
|
const previousRowDataLength = useRef(0);
|
|
2991
|
-
const
|
|
2994
|
+
const onRowDataUpdated = useCallback(() => {
|
|
2992
2995
|
const length = rowData?.length ?? 0;
|
|
2993
2996
|
if (previousRowDataLength.current !== length) {
|
|
2994
2997
|
// We need to autosize all cells again
|
|
@@ -3000,10 +3003,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3000
3003
|
return;
|
|
3001
3004
|
lastUpdatedDep.current = updatedDep;
|
|
3002
3005
|
// Don't update while there are spinners
|
|
3003
|
-
if (
|
|
3006
|
+
if (anyUpdating()) {
|
|
3004
3007
|
return;
|
|
3008
|
+
}
|
|
3005
3009
|
const skipHeader = sizeColumns === 'auto-skip-headers';
|
|
3006
|
-
if (hasSetContentSize.current) {
|
|
3010
|
+
if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
|
|
3007
3011
|
autoSizeColumns({
|
|
3008
3012
|
skipHeader,
|
|
3009
3013
|
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
@@ -3011,7 +3015,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3011
3015
|
});
|
|
3012
3016
|
}
|
|
3013
3017
|
colIdsEdited.current.clear();
|
|
3014
|
-
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep,
|
|
3018
|
+
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
|
|
3015
3019
|
/**
|
|
3016
3020
|
* Show/hide no rows overlay when model changes.
|
|
3017
3021
|
*/
|
|
@@ -3036,6 +3040,20 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3036
3040
|
void startCellEditing({ rowId: event.data.id, colId: event.column.getColId() });
|
|
3037
3041
|
}
|
|
3038
3042
|
}, [singleClickEdit, startCellEditing]);
|
|
3043
|
+
const onCellEditingStopped = useCallback((event) => {
|
|
3044
|
+
const api = event.api;
|
|
3045
|
+
// We need to redraw on fit as the updated row heights aren't visible
|
|
3046
|
+
if (sizeColumns === 'fit') {
|
|
3047
|
+
delay(() => {
|
|
3048
|
+
// Don't update if currently editing, that will stop the edit
|
|
3049
|
+
if (!anyUpdating() && document.querySelectorAll('.szh-menu--state-open').length === 0) {
|
|
3050
|
+
if (!api.isDestroyed()) {
|
|
3051
|
+
api.redrawRows();
|
|
3052
|
+
}
|
|
3053
|
+
}
|
|
3054
|
+
}, 500);
|
|
3055
|
+
}
|
|
3056
|
+
}, [anyUpdating, sizeColumns]);
|
|
3039
3057
|
/**
|
|
3040
3058
|
* If cell has an edit action invoke it (if editable)
|
|
3041
3059
|
*/
|
|
@@ -3136,7 +3154,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3136
3154
|
* Resize columns to fit if required on window/container resize
|
|
3137
3155
|
*/
|
|
3138
3156
|
const onGridResize = useCallback((event) => {
|
|
3139
|
-
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
3157
|
+
if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
|
|
3140
3158
|
return;
|
|
3141
3159
|
}
|
|
3142
3160
|
if (sizeColumns !== 'none') {
|
|
@@ -3328,9 +3346,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3328
3346
|
// This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
|
|
3329
3347
|
if (requiresInitialSizeToFitRef.current) {
|
|
3330
3348
|
requiresInitialSizeToFitRef.current = false;
|
|
3331
|
-
|
|
3349
|
+
delay(() => {
|
|
3350
|
+
sizeColumnsToFit();
|
|
3351
|
+
}, 200);
|
|
3332
3352
|
}
|
|
3333
|
-
}, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridResize, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated:
|
|
3353
|
+
}, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridResize, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataUpdated, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStopped: onCellEditingStopped, 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 }) })] }));
|
|
3334
3354
|
};
|
|
3335
3355
|
const quickFilterParser = (filterStr) => {
|
|
3336
3356
|
// filter is exact matches exactly groups separated by commas
|