@linzjs/step-ag-grid 29.1.5 → 29.1.6

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.
@@ -88,4 +88,4 @@ export interface GridProps<TData extends GridBaseRow = GridBaseRow> {
88
88
  /**
89
89
  * Wrapper for AgGrid to add commonly used functionality.
90
90
  */
91
- export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ "data-testid": dataTestId, defaultPostSort, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, singleClickEdit, rowData, rowHeight, selectable, ...params }: GridProps<TData>) => ReactElement;
91
+ export declare const Grid: <TData extends GridBaseRow = GridBaseRow>({ "data-testid": dataTestId, defaultPostSort, rowSelection, suppressColumnVirtualization, theme, sizeColumns, selectColumnPinned, contextMenuSelectRow, singleClickEdit, rowData, rowHeight, selectable, onCellFocused: paramsOnCellFocused, ...params }: GridProps<TData>) => ReactElement;
@@ -11,6 +11,10 @@ export interface AutoSizeColumnsProps {
11
11
  export type AutoSizeColumnsResult = {
12
12
  width: number;
13
13
  } | null;
14
+ export interface StartCellEditingProps {
15
+ rowId: number;
16
+ colId: string;
17
+ }
14
18
  export interface GridContextType<TData extends GridBaseRow> {
15
19
  gridReady: boolean;
16
20
  gridRenderState: () => null | 'empty' | 'rows-visible';
@@ -37,10 +41,7 @@ export interface GridContextType<TData extends GridBaseRow> {
37
41
  getFirstRowId: () => number;
38
42
  autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult;
39
43
  sizeColumnsToFit: () => void;
40
- startCellEditing: ({ rowId, colId }: {
41
- rowId: number;
42
- colId: string;
43
- }) => Promise<void>;
44
+ startCellEditing: ({ rowId, colId }: StartCellEditingProps) => Promise<void>;
44
45
  resetFocusedCellAfterCellEditing: () => void;
45
46
  updatingCells: (props: {
46
47
  selectedRows: GridBaseRow[];
@@ -2762,7 +2762,7 @@ agGridCommunity.ModuleRegistry.registerModules([agGridCommunity.AllCommunityModu
2762
2762
  /**
2763
2763
  * Wrapper for AgGrid to add commonly used functionality.
2764
2764
  */
2765
- 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, ...params }) => {
2765
+ 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, ...params }) => {
2766
2766
  const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
2767
2767
  const { updatedDep, updatingCols } = React.useContext(GridUpdatingContext);
2768
2768
  const gridDivRef = React.useRef(null);
@@ -3158,7 +3158,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3158
3158
  }
3159
3159
  }, [clearHighlightRowClasses]);
3160
3160
  const onCellFocused = React.useCallback((event) => {
3161
- if (!params.onCellFocused || event.rowIndex == null) {
3161
+ if (!paramsOnCellFocused || event.rowIndex == null) {
3162
3162
  return;
3163
3163
  }
3164
3164
  const api = event.api;
@@ -3172,8 +3172,16 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3172
3172
  if (!colDef || typeof colDef === 'string') {
3173
3173
  return;
3174
3174
  }
3175
- params.onCellFocused({ colDef, data });
3176
- }, [params]);
3175
+ // Prevent repeated callbacks to cell focus when it focus didn't change
3176
+ const { sourceEvent } = event;
3177
+ if (sourceEvent) {
3178
+ if (window.__stepaggrid_lastfocuseventtarget === sourceEvent.target) {
3179
+ return;
3180
+ }
3181
+ window.__stepaggrid_lastfocuseventtarget = sourceEvent.target;
3182
+ }
3183
+ paramsOnCellFocused({ colDef, data });
3184
+ }, [paramsOnCellFocused]);
3177
3185
  const onRowDragEnd = React.useCallback((event) => {
3178
3186
  clearHighlightRowClasses();
3179
3187
  gridElementRef.current = undefined;
@@ -3256,7 +3264,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3256
3264
  enableClickSelection: params.enableClickSelection ?? false,
3257
3265
  mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
3258
3266
  }
3259
- : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataChanged, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, 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 }) })] }));
3267
+ : undefined, rowHeight: rowHeight, animateRows: params.animateRows ?? false, rowClassRules: params.rowClassRules, getRowId: getRowId, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: setInitialContentSize, onRowDataUpdated: onRowDataChanged, onCellFocused: onCellFocused, onCellKeyDown: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, 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 }) })] }));
3260
3268
  };
3261
3269
  const quickFilterParser = (filterStr) => {
3262
3270
  // filter is exact matches exactly groups separated by commas
@@ -3401,14 +3409,10 @@ const GridCell = (props, custom) => {
3401
3409
  resizable: true,
3402
3410
  valueSetter: custom?.editor ? blockValueSetter : undefined,
3403
3411
  editable: props.editable ?? !!custom?.editor,
3404
- ...(custom?.editor
3405
- ? {
3406
- cellClassRules: GridCellMultiSelectClassRules,
3407
- cellEditor: GenericCellEditorComponentWrapper(custom?.editor),
3408
- }
3409
- : {
3410
- cellEditor: CellEditorToBlockEditing,
3411
- }),
3412
+ ...(custom?.editor && {
3413
+ cellClassRules: GridCellMultiSelectClassRules,
3414
+ cellEditor: GenericCellEditorComponentWrapper(custom?.editor),
3415
+ }),
3412
3416
  suppressKeyboardEvent: suppressCellKeyboardEvents,
3413
3417
  ...(custom?.editorParams
3414
3418
  ? {
@@ -3435,19 +3439,6 @@ const GridCell = (props, custom) => {
3435
3439
  },
3436
3440
  };
3437
3441
  };
3438
- /**
3439
- * Ag-grid will start its own editor if editable is true and there is no cell editor
3440
- * like in the case of a cell that is editable because it triggers a modal.
3441
- * This will block that editor.
3442
- */
3443
- const CellEditorToBlockEditing = ({ stopEditing }) => {
3444
- React.useEffect(() => {
3445
- lodashEs.defer(() => {
3446
- stopEditing();
3447
- });
3448
- }, [stopEditing]);
3449
- return jsxRuntime.jsx(jsxRuntime.Fragment, {});
3450
- };
3451
3442
  const GenericCellEditorComponentWrapper = (editor) => {
3452
3443
  const obj = { editor };
3453
3444
  return React.forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
@@ -5541,12 +5532,9 @@ const GridContextProvider = (props) => {
5541
5532
  const preRow = gridApi.getFocusedCell();
5542
5533
  // If we don't do this ag-grid will do its own continuation of an edit on tab, we don't want that as
5543
5534
  // we are managing it ourselves
5544
- gridApi.stopEditing();
5545
- if (tabDirection === 1) {
5546
- gridApi.tabToNextCell();
5547
- }
5548
- else {
5549
- gridApi.tabToPreviousCell();
5535
+ const didTab = tabDirection === 1 ? gridApi.tabToNextCell() : gridApi.tabToPreviousCell();
5536
+ if (!didTab) {
5537
+ break;
5550
5538
  }
5551
5539
  if (gridApi.isDestroyed()) {
5552
5540
  return true;