@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/package.json
CHANGED
package/src/components/Grid.tsx
CHANGED
|
@@ -26,11 +26,11 @@ import {
|
|
|
26
26
|
} from 'ag-grid-community';
|
|
27
27
|
import { AgGridReact } from 'ag-grid-react';
|
|
28
28
|
import clsx from 'clsx';
|
|
29
|
-
import { defer, difference, isEmpty, last, omit, xorBy } from 'lodash-es';
|
|
29
|
+
import { defer, delay, difference, isEmpty, last, omit, xorBy } from 'lodash-es';
|
|
30
30
|
import { ReactElement, useCallback, useContext, useEffect, useMemo, useRef, useState } from 'react';
|
|
31
31
|
import { useInterval } from 'usehooks-ts';
|
|
32
32
|
|
|
33
|
-
import { AutoSizeColumnsResult, useGridContext } from '../contexts/GridContext';
|
|
33
|
+
import { AutoSizeColumnsResult, StartCellEditingProps, useGridContext } from '../contexts/GridContext';
|
|
34
34
|
import { GridUpdatingContext } from '../contexts/GridUpdatingContext';
|
|
35
35
|
import { fnOrVar, isNotEmpty } from '../utils/util';
|
|
36
36
|
import { clickInputWhenContainingCellClicked } from './clickInputWhenContainingCellClicked';
|
|
@@ -170,9 +170,19 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
170
170
|
getColDef,
|
|
171
171
|
showNoRowsOverlay,
|
|
172
172
|
prePopupOps,
|
|
173
|
-
startCellEditing,
|
|
173
|
+
startCellEditing: propStartCellEditing,
|
|
174
174
|
} = useGridContext<TData>();
|
|
175
|
-
|
|
175
|
+
// CellEditingStop event happens too much for one edit
|
|
176
|
+
const startedEditRef = useRef(false);
|
|
177
|
+
const startCellEditing = useCallback(
|
|
178
|
+
(props: StartCellEditingProps) => {
|
|
179
|
+
startedEditRef.current = true;
|
|
180
|
+
return propStartCellEditing(props);
|
|
181
|
+
},
|
|
182
|
+
[propStartCellEditing],
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
const { updatedDep, anyUpdating, updatingCols } = useContext(GridUpdatingContext);
|
|
176
186
|
|
|
177
187
|
const gridDivRef = useRef<HTMLDivElement>(null);
|
|
178
188
|
const lastSelectedIds = useRef<number[]>([]);
|
|
@@ -191,7 +201,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
191
201
|
const hasSetContentSizeEmpty = useRef(false);
|
|
192
202
|
const needsAutoSize = useRef(true);
|
|
193
203
|
|
|
194
|
-
const requiresInitialSizeToFitRef = useRef(
|
|
204
|
+
const requiresInitialSizeToFitRef = useRef(false);
|
|
195
205
|
const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
|
|
196
206
|
const prevRowsVisibleRef = useRef(false);
|
|
197
207
|
const setInitialContentSize = useCallback(() => {
|
|
@@ -253,11 +263,13 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
253
263
|
// It should be impossible to get here
|
|
254
264
|
console.error('Unknown value returned from hasGridRendered');
|
|
255
265
|
}
|
|
266
|
+
} else {
|
|
267
|
+
sizeColumnsToFit();
|
|
256
268
|
}
|
|
257
269
|
|
|
258
270
|
setAutoSized(true);
|
|
259
271
|
needsAutoSize.current = false;
|
|
260
|
-
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns]);
|
|
272
|
+
}, [autoSizeColumns, gridRenderState, maxInitialWidth, params, rowData, sizeColumns, sizeColumnsToFit]);
|
|
261
273
|
|
|
262
274
|
const lastOwnerDocumentRef = useRef<Document>();
|
|
263
275
|
const wasVisibleRef = useRef(false);
|
|
@@ -432,7 +444,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
432
444
|
*/
|
|
433
445
|
const previousRowDataLength = useRef(0);
|
|
434
446
|
|
|
435
|
-
const
|
|
447
|
+
const onRowDataUpdated = useCallback(() => {
|
|
436
448
|
const length = rowData?.length ?? 0;
|
|
437
449
|
if (previousRowDataLength.current !== length) {
|
|
438
450
|
// We need to autosize all cells again
|
|
@@ -445,10 +457,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
445
457
|
lastUpdatedDep.current = updatedDep;
|
|
446
458
|
|
|
447
459
|
// Don't update while there are spinners
|
|
448
|
-
if (
|
|
460
|
+
if (anyUpdating()) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
449
463
|
|
|
450
464
|
const skipHeader = sizeColumns === 'auto-skip-headers';
|
|
451
|
-
if (hasSetContentSize.current) {
|
|
465
|
+
if ((sizeColumns === 'auto' || sizeColumns === 'auto-skip-headers') && hasSetContentSize.current) {
|
|
452
466
|
autoSizeColumns({
|
|
453
467
|
skipHeader,
|
|
454
468
|
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
@@ -456,7 +470,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
456
470
|
});
|
|
457
471
|
}
|
|
458
472
|
colIdsEdited.current.clear();
|
|
459
|
-
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep,
|
|
473
|
+
}, [autoSizeColumns, rowData?.length, setInitialContentSize, sizeColumns, updatedDep, anyUpdating]);
|
|
460
474
|
|
|
461
475
|
/**
|
|
462
476
|
* Show/hide no rows overlay when model changes.
|
|
@@ -491,6 +505,28 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
491
505
|
[singleClickEdit, startCellEditing],
|
|
492
506
|
);
|
|
493
507
|
|
|
508
|
+
const onCellEditingStopped = useCallback(
|
|
509
|
+
(event: AgGridEvent<TData>) => {
|
|
510
|
+
if (!startedEditRef.current) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
startedEditRef.current = false;
|
|
514
|
+
const api = event.api;
|
|
515
|
+
// We need to redraw on fit as the updated row heights aren't visible
|
|
516
|
+
if (sizeColumns === 'fit') {
|
|
517
|
+
delay(() => {
|
|
518
|
+
// Don't update if currently editing, that will stop the edit
|
|
519
|
+
if (!anyUpdating() && document.querySelectorAll('.szh-menu--state-open').length === 0) {
|
|
520
|
+
if (!api.isDestroyed()) {
|
|
521
|
+
api.redrawRows();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}, 500);
|
|
525
|
+
}
|
|
526
|
+
},
|
|
527
|
+
[anyUpdating, sizeColumns],
|
|
528
|
+
);
|
|
529
|
+
|
|
494
530
|
/**
|
|
495
531
|
* If cell has an edit action invoke it (if editable)
|
|
496
532
|
*/
|
|
@@ -603,7 +639,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
603
639
|
*/
|
|
604
640
|
const onGridResize = useCallback(
|
|
605
641
|
(event: AgGridEvent<TData>) => {
|
|
606
|
-
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
642
|
+
if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
|
|
607
643
|
return;
|
|
608
644
|
}
|
|
609
645
|
if (sizeColumns !== 'none') {
|
|
@@ -863,7 +899,9 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
863
899
|
// This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
|
|
864
900
|
if (requiresInitialSizeToFitRef.current) {
|
|
865
901
|
requiresInitialSizeToFitRef.current = false;
|
|
866
|
-
|
|
902
|
+
delay(() => {
|
|
903
|
+
sizeColumnsToFit();
|
|
904
|
+
}, 200);
|
|
867
905
|
}
|
|
868
906
|
}}
|
|
869
907
|
rowHeight={rowHeight}
|
|
@@ -874,11 +912,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
874
912
|
suppressColumnVirtualisation={suppressColumnVirtualization}
|
|
875
913
|
suppressClickEdit={true}
|
|
876
914
|
onColumnVisible={setInitialContentSize}
|
|
877
|
-
onRowDataUpdated={
|
|
915
|
+
onRowDataUpdated={onRowDataUpdated}
|
|
878
916
|
onCellFocused={onCellFocused}
|
|
879
917
|
onCellKeyDown={onCellKeyPress}
|
|
880
918
|
onCellClicked={onCellClicked}
|
|
881
919
|
onCellDoubleClicked={onCellDoubleClick}
|
|
920
|
+
onCellEditingStopped={onCellEditingStopped}
|
|
882
921
|
domLayout={params.domLayout}
|
|
883
922
|
onColumnResized={onColumnResized}
|
|
884
923
|
defaultColDef={defaultColDef}
|