@linzjs/step-ag-grid 29.11.0 → 29.11.2
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/README.md +1 -1
- package/dist/src/contexts/GridContext.d.ts +0 -1
- package/dist/src/contexts/GridContextProvider.d.ts +4 -1
- package/dist/step-ag-grid.cjs +47 -49
- package/dist/step-ag-grid.cjs.map +1 -1
- package/dist/step-ag-grid.esm.js +45 -50
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +18 -16
- package/src/components/Grid.tsx +25 -68
- package/src/contexts/GridContext.tsx +0 -1
- package/src/contexts/GridContextProvider.tsx +45 -16
- package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +7 -7
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@linzjs/step-ag-grid",
|
|
3
3
|
"repository": "github:linz/step-ag-grid.git",
|
|
4
4
|
"license": "MIT",
|
|
5
|
-
"version": "29.11.
|
|
5
|
+
"version": "29.11.2",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"aggrid",
|
|
8
8
|
"ag-grid",
|
|
@@ -28,8 +28,8 @@
|
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"@linzjs/lui": ">=21",
|
|
31
|
-
"ag-grid-community": "
|
|
32
|
-
"ag-grid-react": "
|
|
31
|
+
"ag-grid-community": "~34.2.0",
|
|
32
|
+
"ag-grid-react": "~34.2.0",
|
|
33
33
|
"lodash-es": ">=4",
|
|
34
34
|
"react": ">=18",
|
|
35
35
|
"react-dom": ">=18"
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"debounce-promise": "^3.1.2",
|
|
40
40
|
"matcher": "^5.0.0",
|
|
41
41
|
"react-transition-state": "^2.3.1",
|
|
42
|
-
"usehooks-ts": "^3.1.1"
|
|
42
|
+
"usehooks-ts": "^3.1.1",
|
|
43
|
+
"uuid": "^13.0.0"
|
|
43
44
|
},
|
|
44
45
|
"scripts": {
|
|
45
46
|
"build": "run-s clean lint css bundle",
|
|
@@ -76,14 +77,14 @@
|
|
|
76
77
|
]
|
|
77
78
|
},
|
|
78
79
|
"optionalDependencies": {
|
|
79
|
-
"@rollup/rollup-linux-x64-gnu": "^4.
|
|
80
|
-
"@swc/core-linux-x64-gnu": "^1.
|
|
80
|
+
"@rollup/rollup-linux-x64-gnu": "^4.53.2",
|
|
81
|
+
"@swc/core-linux-x64-gnu": "^1.15.1"
|
|
81
82
|
},
|
|
82
83
|
"devDependencies": {
|
|
83
|
-
"@chromatic-com/storybook": "^4.1.
|
|
84
|
+
"@chromatic-com/storybook": "^4.1.2",
|
|
84
85
|
"@linzjs/lui": "^23.14.2",
|
|
85
86
|
"@linzjs/style": "^5.4.0",
|
|
86
|
-
"@linzjs/windows": "^
|
|
87
|
+
"@linzjs/windows": "^8.1.0",
|
|
87
88
|
"@rollup/plugin-commonjs": "^28.0.8",
|
|
88
89
|
"@rollup/plugin-json": "^6.1.0",
|
|
89
90
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
@@ -101,13 +102,14 @@
|
|
|
101
102
|
"@types/node": "^22.17.0",
|
|
102
103
|
"@types/react": "^18.3.23",
|
|
103
104
|
"@types/react-dom": "^18.3.7",
|
|
105
|
+
"@types/uuid": "^11.0.0",
|
|
104
106
|
"@vitejs/plugin-react-swc": "^3.11.0",
|
|
105
107
|
"@vitest/ui": "^3.2.4",
|
|
106
|
-
"ag-grid-community": "
|
|
107
|
-
"ag-grid-react": "
|
|
108
|
+
"ag-grid-community": "34.2.0",
|
|
109
|
+
"ag-grid-react": "34.2.0",
|
|
108
110
|
"babel-preset-react-app": "^10.1.0",
|
|
109
111
|
"canvas": "^3.2.0",
|
|
110
|
-
"chromatic": "^13.3.
|
|
112
|
+
"chromatic": "^13.3.3",
|
|
111
113
|
"cross-env": "^10.1.0",
|
|
112
114
|
"css-loader": "^7.1.2",
|
|
113
115
|
"eslint-plugin-react": "^7.37.5",
|
|
@@ -122,20 +124,20 @@
|
|
|
122
124
|
"react": ">=18",
|
|
123
125
|
"react-app-polyfill": "^3.0.0",
|
|
124
126
|
"react-dom": "^18.3.1",
|
|
125
|
-
"rimraf": "^6.0
|
|
126
|
-
"rollup": "^4.
|
|
127
|
+
"rimraf": "^6.1.0",
|
|
128
|
+
"rollup": "^4.53.2",
|
|
127
129
|
"rollup-plugin-copy": "^3.5.0",
|
|
128
130
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
129
131
|
"rollup-plugin-postcss": "^4.0.2",
|
|
130
132
|
"rollup-plugin-typescript2": "^0.36.0",
|
|
131
|
-
"sass": "^1.
|
|
132
|
-
"sass-loader": "^16.0.
|
|
133
|
+
"sass": "^1.94.0",
|
|
134
|
+
"sass-loader": "^16.0.6",
|
|
133
135
|
"semantic-release": "^24.2.9",
|
|
134
136
|
"storybook": "^9.1.12",
|
|
135
137
|
"storybook-css-modules-preset": "^1.1.1",
|
|
136
138
|
"style-loader": "^4.0.0",
|
|
137
139
|
"typescript": "^5.9.3",
|
|
138
|
-
"vite": "^7.
|
|
140
|
+
"vite": "^7.2.2",
|
|
139
141
|
"vite-plugin-html": "^3.2.2",
|
|
140
142
|
"vite-tsconfig-paths": "^5.1.4",
|
|
141
143
|
"vitest": "^3.2.4"
|
package/src/components/Grid.tsx
CHANGED
|
@@ -14,7 +14,6 @@ import {
|
|
|
14
14
|
GetRowIdParams,
|
|
15
15
|
GridOptions,
|
|
16
16
|
GridReadyEvent,
|
|
17
|
-
IColumnLimit,
|
|
18
17
|
ModelUpdatedEvent,
|
|
19
18
|
ModuleRegistry,
|
|
20
19
|
RowClickedEvent,
|
|
@@ -203,7 +202,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
203
202
|
const hasSetContentSizeEmpty = useRef(false);
|
|
204
203
|
const needsAutoSize = useRef(true);
|
|
205
204
|
|
|
206
|
-
const requiresInitialSizeToFitRef = useRef(false);
|
|
207
205
|
const autoSizeResultRef = useRef<AutoSizeColumnsResult | null>(null);
|
|
208
206
|
const prevRowsVisibleRef = useRef(false);
|
|
209
207
|
const setInitialContentSize = useCallback(() => {
|
|
@@ -235,7 +233,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
235
233
|
autoSizeColumns({
|
|
236
234
|
skipHeader,
|
|
237
235
|
userSizedColIds: new Set(userSizedColIds.current.keys()),
|
|
238
|
-
includeFlex: true,
|
|
239
236
|
});
|
|
240
237
|
// Auto-size failed retry later
|
|
241
238
|
if (!autoSizeResult) {
|
|
@@ -251,14 +248,12 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
251
248
|
// We don't do this callback if we have previously had row data, or have already called back for empty
|
|
252
249
|
if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
|
|
253
250
|
hasSetContentSizeEmpty.current = true;
|
|
254
|
-
requiresInitialSizeToFitRef.current = true;
|
|
255
251
|
params.onContentSize?.(autoSizeResult);
|
|
256
252
|
}
|
|
257
253
|
} else if (gridRendered === 'rows-visible') {
|
|
258
254
|
// we have rows now so callback grid size
|
|
259
255
|
if (!hasSetContentSize.current) {
|
|
260
256
|
hasSetContentSize.current = true;
|
|
261
|
-
requiresInitialSizeToFitRef.current = true;
|
|
262
257
|
params.onContentSize?.(autoSizeResult);
|
|
263
258
|
}
|
|
264
259
|
} else {
|
|
@@ -266,6 +261,7 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
266
261
|
console.error('Unknown value returned from hasGridRendered');
|
|
267
262
|
}
|
|
268
263
|
} else {
|
|
264
|
+
console.log('sizeColumnsToFit 3');
|
|
269
265
|
sizeColumnsToFit();
|
|
270
266
|
}
|
|
271
267
|
|
|
@@ -608,9 +604,10 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
608
604
|
* When cell editing has completed the colId as needing auto-sizing
|
|
609
605
|
*/
|
|
610
606
|
useEffect(() => {
|
|
611
|
-
if (lastUpdatedDep.current === updatedDep)
|
|
607
|
+
if (lastUpdatedDep.current === updatedDep) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
612
610
|
lastUpdatedDep.current = updatedDep;
|
|
613
|
-
|
|
614
611
|
const colIds = updatingCols();
|
|
615
612
|
// Updating possibly completed
|
|
616
613
|
if (isEmpty(colIds)) {
|
|
@@ -649,32 +646,6 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
649
646
|
prevLoading.current = newLoading;
|
|
650
647
|
}, [params.loading, rowData, showNoRowsOverlay]);
|
|
651
648
|
|
|
652
|
-
/**
|
|
653
|
-
* Resize columns to fit if required on window/container resize
|
|
654
|
-
*/
|
|
655
|
-
const onGridResize = useCallback(
|
|
656
|
-
(event: AgGridEvent<TData>) => {
|
|
657
|
-
if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
|
|
658
|
-
return;
|
|
659
|
-
}
|
|
660
|
-
if (sizeColumns !== 'none') {
|
|
661
|
-
// Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
|
|
662
|
-
// Double click column resize handle to reset this behaviour
|
|
663
|
-
const columnLimits = [
|
|
664
|
-
...userSizedColIds.current.entries().map(
|
|
665
|
-
([c, w]): IColumnLimit => ({
|
|
666
|
-
key: c,
|
|
667
|
-
minWidth: w,
|
|
668
|
-
maxWidth: w,
|
|
669
|
-
}),
|
|
670
|
-
),
|
|
671
|
-
];
|
|
672
|
-
defer(() => event.api.sizeColumnsToFit({ columnLimits }));
|
|
673
|
-
}
|
|
674
|
-
},
|
|
675
|
-
[sizeColumns],
|
|
676
|
-
);
|
|
677
|
-
|
|
678
649
|
/**
|
|
679
650
|
* Set of column I'd's that are prevented from auto-sizing as they are user set
|
|
680
651
|
*/
|
|
@@ -683,33 +654,29 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
683
654
|
/**
|
|
684
655
|
* Lock/unlock column width on user edit/reset.
|
|
685
656
|
*/
|
|
686
|
-
const onColumnResized = useCallback(
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
userSizedColIds.current.set(colId, width);
|
|
700
|
-
const colDef = e.column?.getColDef();
|
|
657
|
+
const onColumnResized = useCallback((e: ColumnResizedEvent) => {
|
|
658
|
+
const colId = e.column?.getColId();
|
|
659
|
+
if (colId == null) {
|
|
660
|
+
return;
|
|
661
|
+
}
|
|
662
|
+
const width = e.column?.getActualWidth();
|
|
663
|
+
if (width == null) {
|
|
664
|
+
return;
|
|
665
|
+
}
|
|
666
|
+
switch (e.source) {
|
|
667
|
+
case 'uiColumnResized':
|
|
668
|
+
userSizedColIds.current.set(colId, width);
|
|
669
|
+
/*const colDef = e.column?.getColDef();
|
|
701
670
|
if (!colDef?.flex) {
|
|
702
671
|
onGridResize(e);
|
|
703
|
-
}
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
[onGridResize],
|
|
712
|
-
);
|
|
672
|
+
}*/
|
|
673
|
+
break;
|
|
674
|
+
case 'autosizeColumns':
|
|
675
|
+
userSizedColIds.current.delete(colId);
|
|
676
|
+
//onGridResize(e);
|
|
677
|
+
break;
|
|
678
|
+
}
|
|
679
|
+
}, []);
|
|
713
680
|
|
|
714
681
|
const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
|
|
715
682
|
|
|
@@ -910,20 +877,10 @@ export const Grid = <TData extends GridBaseRow = GridBaseRow>({
|
|
|
910
877
|
}
|
|
911
878
|
: undefined
|
|
912
879
|
}
|
|
913
|
-
onDisplayedColumnsChanged={() => {
|
|
914
|
-
// This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
|
|
915
|
-
if (requiresInitialSizeToFitRef.current) {
|
|
916
|
-
requiresInitialSizeToFitRef.current = false;
|
|
917
|
-
delay(() => {
|
|
918
|
-
sizeColumnsToFit();
|
|
919
|
-
}, 200);
|
|
920
|
-
}
|
|
921
|
-
}}
|
|
922
880
|
rowHeight={rowHeight}
|
|
923
881
|
animateRows={params.animateRows ?? false}
|
|
924
882
|
rowClassRules={params.rowClassRules}
|
|
925
883
|
getRowId={getRowId}
|
|
926
|
-
onGridSizeChanged={onGridResize}
|
|
927
884
|
suppressColumnVirtualisation={suppressColumnVirtualization}
|
|
928
885
|
suppressClickEdit={true}
|
|
929
886
|
onColumnVisible={setInitialContentSize}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
CellPosition,
|
|
3
3
|
ColDef,
|
|
4
|
+
ColumnState,
|
|
4
5
|
CsvExportParams,
|
|
5
6
|
GridApi,
|
|
6
7
|
IRowNode,
|
|
@@ -20,6 +21,10 @@ import { waitForCondition } from '../utils/waitForCondition';
|
|
|
20
21
|
import { AutoSizeColumnsProps, AutoSizeColumnsResult, GridContext, GridFilterExternal } from './GridContext';
|
|
21
22
|
import { GridUpdatingContext } from './GridUpdatingContext';
|
|
22
23
|
|
|
24
|
+
export const colStateId = (colState: ColumnState) => colState.colId;
|
|
25
|
+
export const colStateFlexed = (colState: ColumnState) => !!colState.flex;
|
|
26
|
+
export const colStateNotFlexed = (colState: ColumnState) => !colState.flex;
|
|
27
|
+
|
|
23
28
|
/**
|
|
24
29
|
* Context for AgGrid operations.
|
|
25
30
|
* Make sure you wrap AgGrid in this.
|
|
@@ -422,32 +427,56 @@ export const GridContextProvider = <TData extends GridBaseRow>(props: PropsWithC
|
|
|
422
427
|
|
|
423
428
|
/**
|
|
424
429
|
* Resize columns to fit container
|
|
430
|
+
*
|
|
431
|
+
* This is used to calculate the preferred size of columns.
|
|
432
|
+
* It sizes the flex columns first and then clears the calculated width.
|
|
433
|
+
* If you don't clear flex column widths ag-grid gets confused and does random sizing's.
|
|
434
|
+
* Then we size the flexed columns.
|
|
425
435
|
*/
|
|
426
436
|
const autoSizeColumns = useCallback(
|
|
427
|
-
({ skipHeader, colIds, userSizedColIds
|
|
437
|
+
({ skipHeader, colIds, userSizedColIds }: AutoSizeColumnsProps = {}): AutoSizeColumnsResult => {
|
|
428
438
|
if (!gridApi || !gridApi.getColumnState()) {
|
|
429
439
|
return null;
|
|
430
440
|
}
|
|
431
441
|
const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
(
|
|
442
|
+
|
|
443
|
+
const getVisibleColStates = () => {
|
|
444
|
+
const colStates = gridApi.getColumnState();
|
|
445
|
+
return colStates.filter((colState) => {
|
|
446
|
+
const colId = colState.colId;
|
|
447
|
+
return (isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
|
|
448
|
+
});
|
|
449
|
+
};
|
|
450
|
+
const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
|
|
451
|
+
const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
|
|
452
|
+
|
|
453
|
+
// If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
|
|
454
|
+
let flexColumns = getFlexColStates();
|
|
455
|
+
let width = 0;
|
|
456
|
+
if (!isEmpty(flexColumns)) {
|
|
457
|
+
gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
|
|
458
|
+
const flexColumnIds = flexColumns.map(colStateId);
|
|
459
|
+
flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
|
|
460
|
+
width += sumBy(
|
|
461
|
+
flexColumns.filter((col) => !col.hide),
|
|
462
|
+
'width',
|
|
438
463
|
);
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
464
|
+
gridApi.resetColumnState();
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
let nonFlexColumns = getNonFlexColStates();
|
|
468
|
+
if (!isEmpty(nonFlexColumns)) {
|
|
469
|
+
gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
|
|
470
|
+
const nonFlexColumnIds = nonFlexColumns.map(colStateId);
|
|
471
|
+
nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
|
|
472
|
+
width += sumBy(
|
|
473
|
+
nonFlexColumns.filter((col) => !col.hide),
|
|
474
|
+
'width',
|
|
444
475
|
);
|
|
445
476
|
}
|
|
477
|
+
|
|
446
478
|
return {
|
|
447
|
-
width
|
|
448
|
-
gridApi.getColumnState().filter((col) => !col.hide),
|
|
449
|
-
'width',
|
|
450
|
-
),
|
|
479
|
+
width,
|
|
451
480
|
};
|
|
452
481
|
},
|
|
453
482
|
[gridApi],
|
|
@@ -19,13 +19,11 @@ export default {
|
|
|
19
19
|
},
|
|
20
20
|
decorators: [
|
|
21
21
|
(Story) => (
|
|
22
|
-
<
|
|
23
|
-
<
|
|
24
|
-
<
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
</GridUpdatingContextProvider>
|
|
28
|
-
</div>
|
|
22
|
+
<GridUpdatingContextProvider>
|
|
23
|
+
<GridContextProvider>
|
|
24
|
+
<Story />
|
|
25
|
+
</GridContextProvider>
|
|
26
|
+
</GridUpdatingContextProvider>
|
|
29
27
|
),
|
|
30
28
|
],
|
|
31
29
|
} as Meta<typeof Grid>;
|
|
@@ -37,11 +35,13 @@ const GridPopoutEditGenericTemplate: StoryFn<typeof Grid<IFormTestRow>> = (props
|
|
|
37
35
|
GridCell({
|
|
38
36
|
field: 'id',
|
|
39
37
|
headerName: 'Id',
|
|
38
|
+
flex: 2,
|
|
40
39
|
}),
|
|
41
40
|
GridCell(
|
|
42
41
|
{
|
|
43
42
|
field: 'name',
|
|
44
43
|
headerName: 'Popout Generic Edit',
|
|
44
|
+
flex: 1,
|
|
45
45
|
},
|
|
46
46
|
{
|
|
47
47
|
multiEdit: true,
|