@linzjs/step-ag-grid 29.3.2 → 29.3.4
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 +41 -11
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +42 -12
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +52 -13
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
|
|
|
@@ -2761,8 +2761,14 @@ ModuleRegistry.registerModules([AllCommunityModule]);
|
|
|
2761
2761
|
* Wrapper for AgGrid to add commonly used functionality.
|
|
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
|
-
const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
|
|
2765
|
-
|
|
2764
|
+
const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing: propStartCellEditing, } = useGridContext();
|
|
2765
|
+
// CellEditingStop event happens too much for one edit
|
|
2766
|
+
const startedEditRef = useRef(false);
|
|
2767
|
+
const startCellEditing = useCallback((props) => {
|
|
2768
|
+
startedEditRef.current = true;
|
|
2769
|
+
return propStartCellEditing(props);
|
|
2770
|
+
}, [propStartCellEditing]);
|
|
2771
|
+
const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
|
|
2766
2772
|
const gridDivRef = useRef(null);
|
|
2767
2773
|
const lastSelectedIds = useRef([]);
|
|
2768
2774
|
const [staleGrid, setStaleGrid] = useState(false);
|
|
@@ -2776,7 +2782,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2776
2782
|
const hasSetContentSize = useRef(false);
|
|
2777
2783
|
const hasSetContentSizeEmpty = useRef(false);
|
|
2778
2784
|
const needsAutoSize = useRef(true);
|
|
2779
|
-
const requiresInitialSizeToFitRef = useRef(
|
|
2785
|
+
const requiresInitialSizeToFitRef = useRef(false);
|
|
2780
2786
|
const autoSizeResultRef = useRef(null);
|
|
2781
2787
|
const prevRowsVisibleRef = useRef(false);
|
|
2782
2788
|
const setInitialContentSize = useCallback(() => {
|
|
@@ -2837,9 +2843,12 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2837
2843
|
console.error('Unknown value returned from hasGridRendered');
|
|
2838
2844
|
}
|
|
2839
2845
|
}
|
|
2846
|
+
else {
|
|
2847
|
+
sizeColumnsToFit();
|
|
2848
|
+
}
|
|
2840
2849
|
setAutoSized(true);
|
|
2841
2850
|
needsAutoSize.current = false;
|
|
2842
|
-
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns]);
|
|
2851
|
+
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
2843
2852
|
const lastOwnerDocumentRef = useRef();
|
|
2844
2853
|
const wasVisibleRef = useRef(false);
|
|
2845
2854
|
/**
|
|
@@ -2988,7 +2997,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
2988
2997
|
* This will resize columns when we have at least one row.
|
|
2989
2998
|
*/
|
|
2990
2999
|
const previousRowDataLength = useRef(0);
|
|
2991
|
-
const
|
|
3000
|
+
const onRowDataUpdated = useCallback(() => {
|
|
2992
3001
|
const length = rowData?.length ?? 0;
|
|
2993
3002
|
if (previousRowDataLength.current !== length) {
|
|
2994
3003
|
// We need to autosize all cells again
|
|
@@ -3000,10 +3009,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3000
3009
|
return;
|
|
3001
3010
|
lastUpdatedDep.current = updatedDep;
|
|
3002
3011
|
// Don't update while there are spinners
|
|
3003
|
-
if (
|
|
3012
|
+
if (anyUpdating()) {
|
|
3004
3013
|
return;
|
|
3014
|
+
}
|
|
3005
3015
|
const skipHeader = sizeColumns === 'auto-skip-headers';
|
|
3006
|
-
if (hasSetContentSize.current) {
|
|
3016
|
+
if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
|
|
3007
3017
|
autoSizeColumns({
|
|
3008
3018
|
skipHeader,
|
|
3009
3019
|
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
@@ -3011,7 +3021,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3011
3021
|
});
|
|
3012
3022
|
}
|
|
3013
3023
|
colIdsEdited.current.clear();
|
|
3014
|
-
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep,
|
|
3024
|
+
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
|
|
3015
3025
|
/**
|
|
3016
3026
|
* Show/hide no rows overlay when model changes.
|
|
3017
3027
|
*/
|
|
@@ -3036,6 +3046,24 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3036
3046
|
void startCellEditing({ rowId: event.data.id, colId: event.column.getColId() });
|
|
3037
3047
|
}
|
|
3038
3048
|
}, [singleClickEdit, startCellEditing]);
|
|
3049
|
+
const onCellEditingStopped = useCallback((event) => {
|
|
3050
|
+
if (!startedEditRef.current) {
|
|
3051
|
+
return;
|
|
3052
|
+
}
|
|
3053
|
+
startedEditRef.current = false;
|
|
3054
|
+
const api = event.api;
|
|
3055
|
+
// We need to redraw on fit as the updated row heights aren't visible
|
|
3056
|
+
if (sizeColumns === 'fit') {
|
|
3057
|
+
delay(() => {
|
|
3058
|
+
// Don't update if currently editing, that will stop the edit
|
|
3059
|
+
if (!anyUpdating() && document.querySelectorAll('.szh-menu--state-open').length === 0) {
|
|
3060
|
+
if (!api.isDestroyed()) {
|
|
3061
|
+
api.redrawRows();
|
|
3062
|
+
}
|
|
3063
|
+
}
|
|
3064
|
+
}, 500);
|
|
3065
|
+
}
|
|
3066
|
+
}, [anyUpdating, sizeColumns]);
|
|
3039
3067
|
/**
|
|
3040
3068
|
* If cell has an edit action invoke it (if editable)
|
|
3041
3069
|
*/
|
|
@@ -3136,7 +3164,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3136
3164
|
* Resize columns to fit if required on window/container resize
|
|
3137
3165
|
*/
|
|
3138
3166
|
const onGridResize = useCallback((event) => {
|
|
3139
|
-
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
3167
|
+
if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
|
|
3140
3168
|
return;
|
|
3141
3169
|
}
|
|
3142
3170
|
if (sizeColumns !== 'none') {
|
|
@@ -3328,9 +3356,11 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
|
|
|
3328
3356
|
// This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
|
|
3329
3357
|
if (requiresInitialSizeToFitRef.current) {
|
|
3330
3358
|
requiresInitialSizeToFitRef.current = false;
|
|
3331
|
-
|
|
3359
|
+
delay(() => {
|
|
3360
|
+
sizeColumnsToFit();
|
|
3361
|
+
}, 200);
|
|
3332
3362
|
}
|
|
3333
|
-
}, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridResize, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated:
|
|
3363
|
+
}, 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
3364
|
};
|
|
3335
3365
|
const quickFilterParser = (filterStr) => {
|
|
3336
3366
|
// filter is exact matches exactly groups separated by commas
|