@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.
@@ -2783,7 +2783,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2783
2783
  const hasSetContentSize = useRef(false);
2784
2784
  const hasSetContentSizeEmpty = useRef(false);
2785
2785
  const needsAutoSize = useRef(true);
2786
- const requiresInitialSizeToFitRef = useRef(false);
2787
2786
  const autoSizeResultRef = useRef(null);
2788
2787
  const prevRowsVisibleRef = useRef(false);
2789
2788
  const setInitialContentSize = useCallback(() => {
@@ -2812,7 +2811,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2812
2811
  autoSizeColumns({
2813
2812
  skipHeader,
2814
2813
  userSizedColIds: new Set(userSizedColIds.current.keys()),
2815
- includeFlex: true,
2816
2814
  });
2817
2815
  // Auto-size failed retry later
2818
2816
  if (!autoSizeResult) {
@@ -2827,7 +2825,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2827
2825
  // We don't do this callback if we have previously had row data, or have already called back for empty
2828
2826
  if (!hasSetContentSizeEmpty.current && !hasSetContentSize.current) {
2829
2827
  hasSetContentSizeEmpty.current = true;
2830
- requiresInitialSizeToFitRef.current = true;
2831
2828
  params.onContentSize?.(autoSizeResult);
2832
2829
  }
2833
2830
  }
@@ -2835,7 +2832,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2835
2832
  // we have rows now so callback grid size
2836
2833
  if (!hasSetContentSize.current) {
2837
2834
  hasSetContentSize.current = true;
2838
- requiresInitialSizeToFitRef.current = true;
2839
2835
  params.onContentSize?.(autoSizeResult);
2840
2836
  }
2841
2837
  }
@@ -2845,6 +2841,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2845
2841
  }
2846
2842
  }
2847
2843
  else {
2844
+ console.log('sizeColumnsToFit 3');
2848
2845
  sizeColumnsToFit();
2849
2846
  }
2850
2847
  setAutoSized(true);
@@ -3130,8 +3127,9 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3130
3127
  * When cell editing has completed the colId as needing auto-sizing
3131
3128
  */
3132
3129
  useEffect(() => {
3133
- if (lastUpdatedDep.current === updatedDep)
3130
+ if (lastUpdatedDep.current === updatedDep) {
3134
3131
  return;
3132
+ }
3135
3133
  lastUpdatedDep.current = updatedDep;
3136
3134
  const colIds = updatingCols();
3137
3135
  // Updating possibly completed
@@ -3170,26 +3168,6 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3170
3168
  }
3171
3169
  prevLoading.current = newLoading;
3172
3170
  }, [params.loading, rowData, showNoRowsOverlay]);
3173
- /**
3174
- * Resize columns to fit if required on window/container resize
3175
- */
3176
- const onGridResize = useCallback((event) => {
3177
- if (sizeColumns === 'fit' || (!hasSetContentSizeEmpty.current && !hasSetContentSize.current)) {
3178
- return;
3179
- }
3180
- if (sizeColumns !== 'none') {
3181
- // Flex columns can expand to fit after resize, but they cannot shrink less than use resized value
3182
- // Double click column resize handle to reset this behaviour
3183
- const columnLimits = [
3184
- ...userSizedColIds.current.entries().map(([c, w]) => ({
3185
- key: c,
3186
- minWidth: w,
3187
- maxWidth: w,
3188
- })),
3189
- ];
3190
- defer(() => event.api.sizeColumnsToFit({ columnLimits }));
3191
- }
3192
- }, [sizeColumns]);
3193
3171
  /**
3194
3172
  * Set of column I'd's that are prevented from auto-sizing as they are user set
3195
3173
  */
@@ -3209,17 +3187,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3209
3187
  switch (e.source) {
3210
3188
  case 'uiColumnResized':
3211
3189
  userSizedColIds.current.set(colId, width);
3212
- const colDef = e.column?.getColDef();
3213
- if (!colDef?.flex) {
3190
+ /*const colDef = e.column?.getColDef();
3191
+ if (!colDef?.flex) {
3214
3192
  onGridResize(e);
3215
- }
3193
+ }*/
3216
3194
  break;
3217
3195
  case 'autosizeColumns':
3218
3196
  userSizedColIds.current.delete(colId);
3219
- onGridResize(e);
3197
+ //onGridResize(e);
3220
3198
  break;
3221
3199
  }
3222
- }, [onGridResize]);
3200
+ }, []);
3223
3201
  const gridContextMenu = useGridContextMenu({ contextMenu: params.contextMenu, contextMenuSelectRow });
3224
3202
  const startDragYRef = useRef(null);
3225
3203
  const clearHighlightRowClasses = useCallback(() => {
@@ -3362,15 +3340,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3362
3340
  enableClickSelection: params.enableClickSelection ?? false,
3363
3341
  mode: rowSelection === 'single' ? 'singleRow' : 'multiRow',
3364
3342
  }
3365
- : undefined, onDisplayedColumnsChanged: () => {
3366
- // This happens after an autosize event, if we don't wait for it size columns to fit doesn't work
3367
- if (requiresInitialSizeToFitRef.current) {
3368
- requiresInitialSizeToFitRef.current = false;
3369
- delay(() => {
3370
- sizeColumnsToFit();
3371
- }, 200);
3372
- }
3373
- }, 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 }) })] }));
3343
+ : 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 }) })] }));
3374
3344
  };
3375
3345
  const quickFilterParser = (filterStr) => {
3376
3346
  // filter is exact matches exactly groups separated by commas
@@ -5344,6 +5314,9 @@ const waitForCondition = async (error, condition, timeoutMs) => {
5344
5314
  return false;
5345
5315
  };
5346
5316
 
5317
+ const colStateId = (colState) => colState.colId;
5318
+ const colStateFlexed = (colState) => !!colState.flex;
5319
+ const colStateNotFlexed = (colState) => !colState.flex;
5347
5320
  /**
5348
5321
  * Context for AgGrid operations.
5349
5322
  * Make sure you wrap AgGrid in this.
@@ -5625,23 +5598,45 @@ const GridContextProvider = (props) => {
5625
5598
  }, [gridApiOp]);
5626
5599
  /**
5627
5600
  * Resize columns to fit container
5601
+ *
5602
+ * This is used to calculate the preferred size of columns.
5603
+ * It sizes the flex columns first and then clears the calculated width.
5604
+ * If you don't clear flex column widths ag-grid gets confused and does random sizing's.
5605
+ * Then we size the flexed columns.
5628
5606
  */
5629
- const autoSizeColumns = useCallback(({ skipHeader, colIds, userSizedColIds, includeFlex } = {}) => {
5607
+ const autoSizeColumns = useCallback(({ skipHeader, colIds, userSizedColIds } = {}) => {
5630
5608
  if (!gridApi || !gridApi.getColumnState()) {
5631
5609
  return null;
5632
5610
  }
5633
5611
  const colIdsSet = colIds instanceof Set ? colIds : new Set(colIds);
5634
- const colsToResize = gridApi.getColumnState()?.filter?.((colState) => {
5635
- const colId = colState.colId;
5636
- return ((isEmpty(colIdsSet) || colIdsSet.has(colId)) &&
5637
- !userSizedColIds?.has(colId) &&
5638
- (includeFlex || !colState.flex));
5639
- });
5640
- if (!isEmpty(colsToResize)) {
5641
- gridApi.autoSizeColumns(colsToResize.map((colState) => colState.colId), skipHeader);
5612
+ const getVisibleColStates = () => {
5613
+ const colStates = gridApi.getColumnState();
5614
+ return colStates.filter((colState) => {
5615
+ const colId = colState.colId;
5616
+ return (isEmpty(colIdsSet) || colIdsSet.has(colId)) && !userSizedColIds?.has(colId);
5617
+ });
5618
+ };
5619
+ const getFlexColStates = () => getVisibleColStates().filter(colStateFlexed);
5620
+ const getNonFlexColStates = () => getVisibleColStates().filter(colStateNotFlexed);
5621
+ // If we don't reset the flex columns auto size it causes issues with random resizing of flex columns
5622
+ let flexColumns = getFlexColStates();
5623
+ let width = 0;
5624
+ if (!isEmpty(flexColumns)) {
5625
+ gridApi.autoSizeColumns(flexColumns.map(colStateId), skipHeader);
5626
+ const flexColumnIds = flexColumns.map(colStateId);
5627
+ flexColumns = getVisibleColStates().filter((colState) => flexColumnIds.includes(colState.colId));
5628
+ width += sumBy(flexColumns.filter((col) => !col.hide), 'width');
5629
+ gridApi.resetColumnState();
5630
+ }
5631
+ let nonFlexColumns = getNonFlexColStates();
5632
+ if (!isEmpty(nonFlexColumns)) {
5633
+ gridApi.autoSizeColumns(nonFlexColumns.map(colStateId), skipHeader);
5634
+ const nonFlexColumnIds = nonFlexColumns.map(colStateId);
5635
+ nonFlexColumns = getVisibleColStates().filter((colState) => nonFlexColumnIds.includes(colState.colId));
5636
+ width += sumBy(nonFlexColumns.filter((col) => !col.hide), 'width');
5642
5637
  }
5643
5638
  return {
5644
- width: sumBy(gridApi.getColumnState().filter((col) => !col.hide), 'width'),
5639
+ width,
5645
5640
  };
5646
5641
  }, [gridApi]);
5647
5642
  /**
@@ -6126,5 +6121,5 @@ const useDeferredPromise = () => {
6126
6121
  };
6127
6122
  };
6128
6123
 
6129
- export { ActionButton, CancelPromise, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
6124
+ export { ActionButton, CancelPromise, ComponentLoadingWrapper, ControlledMenu, Editor, FocusableItem, FormError, GenericCellEditorComponentWrapper, Grid, GridButton, GridCell, GridCellFiller, GridCellFillerColId, GridCellMultiEditor, GridCellMultiSelectClassRules, GridCellRenderer, GridContext, GridContextProvider, GridEditBoolean, GridFilterButtons, GridFilterColumnsMultiSelect, GridFilterColumnsToggle, GridFilterDownloadCsvButton, GridFilterHeaderIconButton, GridFilterQuick, GridFilters, GridFormDropDown, GridFormEditBearing, GridFormMessage, GridFormMultiSelect, GridFormMultiSelectGrid, GridFormPopoverMenu, GridFormSubComponentTextArea, GridFormSubComponentTextInput, GridFormTextArea, GridFormTextInput, GridIcon, GridLoadableCell, GridNoRowsOverlay, GridNoRowsOverlayFr, GridPopoutEditMultiSelect, GridPopoutEditMultiSelectGrid, GridPopoverContext, GridPopoverContextProvider, GridPopoverEditBearing, GridPopoverEditBearingCorrection, GridPopoverEditBearingCorrectionEditorParams, GridPopoverEditBearingEditorParams, GridPopoverEditDropDown, GridPopoverMenu, GridPopoverMessage, GridPopoverTextArea, GridPopoverTextInput, GridRenderPopoutMenuCell, GridSubComponentContext, GridUpdatingContext, GridUpdatingContextProvider, GridWrapper, Menu, MenuButton, MenuDivider, MenuGroup, MenuHeader, MenuHeaderItem, MenuHeaderString, MenuItem, MenuRadioGroup, MenuSeparator, MenuSeparatorString, PopoutMenuSeparator, SubMenu, TextAreaInput, TextInputFormatted, TextInputValidator, bearingCorrectionRangeValidator, bearingCorrectionValueFormatter, bearingNumberParser, bearingRangeValidator, bearingStringValidator, bearingValueFormatter, colStateFlexed, colStateId, colStateNotFlexed, convertDDToDMS, createCheckboxMultiFilterParams, defaultValueFormatter, downloadCsvUseValueFormattersProcessCellCallback, findParentWithClass, fnOrVar, generateFilterGetter, hasParentClass, isFloat, isGridCellFiller, isNotEmpty, primitiveToSelectOption, sanitiseFileName, stringByteLengthIsInvalid, suppressCellKeyboardEvents, textMatch, useDeferredPromise, useGridContext, useGridContextMenu, useGridFilter, useGridPopoverContext, useGridPopoverHook, useMenuState, usePostSortRowsHook, wait, waitForCondition };
6130
6125
  //# sourceMappingURL=step-ag-grid.esm.js.map