@linzjs/step-ag-grid 29.11.1 → 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 CHANGED
@@ -18,7 +18,7 @@
18
18
  - Custom form
19
19
  - Context menu
20
20
 
21
- _Please note this requires React>=18, ag-grid-community >=32.3.3, and SASS._
21
+ _Please note this requires React>=18, ag-grid-community >=34.2.0, and SASS._
22
22
 
23
23
  ## Install
24
24
 
@@ -1,6 +1,9 @@
1
- import { ProcessCellForExportParams } from 'ag-grid-community';
1
+ import { ColumnState, ProcessCellForExportParams } from 'ag-grid-community';
2
2
  import { PropsWithChildren, ReactElement } from 'react';
3
3
  import { GridBaseRow } from '../components';
4
+ export declare const colStateId: (colState: ColumnState) => string;
5
+ export declare const colStateFlexed: (colState: ColumnState) => boolean;
6
+ export declare const colStateNotFlexed: (colState: ColumnState) => boolean;
4
7
  /**
5
8
  * Context for AgGrid operations.
6
9
  * Make sure you wrap AgGrid in this.
@@ -2785,7 +2785,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2785
2785
  const hasSetContentSize = React.useRef(false);
2786
2786
  const hasSetContentSizeEmpty = React.useRef(false);
2787
2787
  const needsAutoSize = React.useRef(true);
2788
- const requiresInitialSizeToFitRef = React.useRef(false);
2789
2788
  const autoSizeResultRef = React.useRef(null);
2790
2789
  const prevRowsVisibleRef = React.useRef(false);
2791
2790
  const setInitialContentSize = React.useCallback(() => {
@@ -2828,7 +2827,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2828
2827
  // We don't do this callback if we have previously had row data, or have already called back for empty
2829
2828
  if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
2830
2829
  hasSetContentSizeEmpty.current = true;
2831
- requiresInitialSizeToFitRef.current = true;
2832
2830
  params.onContentSize?.(autoSizeResult);
2833
2831
  }
2834
2832
  }
@@ -2836,7 +2834,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2836
2834
  // we have rows now so callback grid size
2837
2835
  if (!hasSetContentSize.current) {
2838
2836
  hasSetContentSize.current = true;
2839
- requiresInitialSizeToFitRef.current = true;
2840
2837
  params.onContentSize?.(autoSizeResult);
2841
2838
  }
2842
2839
  }
@@ -2846,6 +2843,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2846
2843
  }
2847
2844
  }
2848
2845
  else {
2846
+ console.log('sizeColumnsToFit 3');
2849
2847
  sizeColumnsToFit();
2850
2848
  }
2851
2849
  setAutoSized(true);
@@ -3131,8 +3129,9 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3131
3129
  * When cell editing has completed the colId as needing auto-sizing
3132
3130
  */
3133
3131
  React.useEffect(() => {
3134
- if (lastUpdatedDep.current === updatedDep)
3132
+ if (lastUpdatedDep.current === updatedDep) {
3135
3133
  return;
3134
+ }
3136
3135
  lastUpdatedDep.current = updatedDep;
3137
3136
  const colIds = updatingCols();
3138
3137
  // Updating possibly completed
@@ -3171,26 +3170,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3171
3170
  }
3172
3171
  prevLoading.current = newLoading;
3173
3172
  }, [params.loading, rowData, showNoRowsOverlay]);
3174
- /**
3175
- * Resize columns to fit if required on window/container resize
3176
- */
3177
- const onGridResize = React.useCallback((event) => {
3178
- if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
3179
- return;
3180
- }
3181
- if (sizeColumns !== 'none') {
3182
- // Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
3183
- // Double click column resize handle to reset this behaviour
3184
- const columnLimits = [
3185
- ...userSizedColIds.current.entries().map(([c, w]) => ({
3186
- key: c,
3187
- minWidth: w,
3188
- maxWidth: w,
3189
- })),
3190
- ];
3191
- lodashEs.defer(() => event.api.sizeColumnsToFit({ columnLimits }));
3192
- }
3193
- }, [sizeColumns]);
3194
3173
  /**
3195
3174
  * Set of column I'd's that are prevented from auto-sizing as they are user set
3196
3175
  */
@@ -3210,17 +3189,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3210
3189
  switch (e.source) {
3211
3190
  case 'uiColumnResized':
3212
3191
  userSizedColIds.current.set(colId, width);
3213
- const colDef = e.column?.getColDef();
3214
- if (!colDef?.flex) {
3192
+ /*const colDef = e.column?.getColDef();
3193
+ if (!colDef?.flex) {
3215
3194
  onGridResize(e);
3216
- }
3195
+ }*/
3217
3196
  break;
3218
3197
  case 'autosizeColumns':
3219
3198
  userSizedColIds.current.delete(colId);
3220
- onGridResize(e);
3199
+ //onGridResize(e);
3221
3200
  break;
3222
3201
  }
3223
- }, [onGridResize]);
3202
+ }, []);
3224
3203
  const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
3225
3204
  const startDragYRef = React.useRef(null);
3226
3205
  const clearHighlightRowClasses = React.useCallback(() => {
@@ -3363,15 +3342,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3363
3342
  enableClickSelection: params.enableClickSelection ?? false,
3364
3343
  mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
3365
3344
  }
3366
- : undefined, onDisplayedColumnsChanged: () => {
3367
- // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
3368
- if (requiresInitialSizeToFitRef.current) {
3369
- requiresInitialSizeToFitRef.current = false;
3370
- lodashEs.delay(() => {
3371
- sizeColumnsToFit();
3372
- }, 200);
3373
- }
3374
- }, 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 }) })] }));
3345
+ : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, 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 }) })] }));
3375
3346
  };
3376
3347
  const quickFilterParser = (filterStr) => {
3377
3348
  // filter is exact matches exactly groups separated by commas
@@ -5347,6 +5318,7 @@ const waitForCondition = async (error, condition, timeoutMs) => {
5347
5318
 
5348
5319
  const colStateId = (colState) => colState.colId;
5349
5320
  const colStateFlexed = (colState) => !!colState.flex;
5321
+ const colStateNotFlexed = (colState) => !colState.flex;
5350
5322
  /**
5351
5323
  * Context for AgGrid operations.
5352
5324
  * Make sure you wrap AgGrid in this.
@@ -5639,22 +5611,34 @@ const GridContextProvider = (props) => {
5639
5611
  return null;
5640
5612
  }
5641
5613
  const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5642
- const colStates = gridApi.getColumnState();
5643
- const relevantCols = colStates?.filter((colState) => {
5644
- const colId = colState.colId;
5645
- return (lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5646
- });
5647
- const [flexColumns, nonFlexColumns] = lodashEs.partition(relevantCols, colStateFlexed);
5614
+ const getVisibleColStates = () => {
5615
+ const colStates = gridApi.getColumnState();
5616
+ return colStates.filter((colState) => {
5617
+ const colId = colState.colId;
5618
+ return (lodashEs.isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5619
+ });
5620
+ };
5621
+ const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
5622
+ const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
5648
5623
  // If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
5624
+ let flexColumns = getFlexColStates();
5625
+ let width = 0;
5649
5626
  if (!lodashEs.isEmpty(flexColumns)) {
5650
5627
  gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
5628
+ const flexColumnIds = flexColumns.map(colStateId);
5629
+ flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
5630
+ width += lodashEs.sumBy(flexColumns.filter((col) => !col.hide), 'width');
5651
5631
  gridApi.resetColumnState();
5652
5632
  }
5633
+ let nonFlexColumns = getNonFlexColStates();
5653
5634
  if (!lodashEs.isEmpty(nonFlexColumns)) {
5654
5635
  gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
5636
+ const nonFlexColumnIds = nonFlexColumns.map(colStateId);
5637
+ nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
5638
+ width += lodashEs.sumBy(nonFlexColumns.filter((col) => !col.hide), 'width');
5655
5639
  }
5656
5640
  return {
5657
- width: lodashEs.sumBy(gridApi.getColumnState().filter((col) => !col.hide), 'width'),
5641
+ width,
5658
5642
  };
5659
5643
  }, [gridApi]);
5660
5644
  /**
@@ -6219,6 +6203,9 @@ exports.bearingNumberParser = bearingNumberParser;
6219
6203
  exports.bearingRangeValidator = bearingRangeValidator;
6220
6204
  exports.bearingStringValidator = bearingStringValidator;
6221
6205
  exports.bearingValueFormatter = bearingValueFormatter;
6206
+ exports.colStateFlexed = colStateFlexed;
6207
+ exports.colStateId = colStateId;
6208
+ exports.colStateNotFlexed = colStateNotFlexed;
6222
6209
  exports.convertDDToDMS = convertDDToDMS;
6223
6210
  exports.createCheckboxMultiFilterParams = createCheckboxMultiFilterParams;
6224
6211
  exports.defaultValueFormatter = defaultValueFormatter;