@linzjs/step-ag-grid 29.1.5 → 29.2.0

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);
@@ -2828,10 +2828,27 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2828
2828
  needsAutoSize.current = false;
2829
2829
  }, [autoSizeColumns, gridRenderState, params, rowData, sizeColumns, sizeColumnsToFit]);
2830
2830
  const lastOwnerDocumentRef = React.useRef();
2831
+ const wasVisibleRef = React.useRef(false);
2831
2832
  /**
2832
2833
  * Auto-size windows that had deferred auto-size
2834
+ * Reset focus if panel went from invisible to visible.
2833
2835
  */
2834
2836
  useInterval(() => {
2837
+ // If grid has become visible after previously being hidden, then refocus the last focused cell.
2838
+ const visible = !!gridDivRef.current?.checkVisibility();
2839
+ if (visible && !wasVisibleRef.current) {
2840
+ wasVisibleRef.current = true;
2841
+ const el = window.__stepaggrid_lastfocuseventtarget;
2842
+ if (el) {
2843
+ // Setting this to null will cause a new refocus event
2844
+ window.__stepaggrid_lastfocuseventtarget = null;
2845
+ // Check element is still part of document
2846
+ if (el.checkVisibility()) {
2847
+ el.focus();
2848
+ }
2849
+ }
2850
+ }
2851
+ wasVisibleRef.current = visible;
2835
2852
  // Check if window has been popped out and needs resize
2836
2853
  const currentDocument = gridDivRef.current?.ownerDocument;
2837
2854
  if (currentDocument !== lastOwnerDocumentRef.current) {
@@ -3158,7 +3175,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3158
3175
  }
3159
3176
  }, [clearHighlightRowClasses]);
3160
3177
  const onCellFocused = React.useCallback((event) => {
3161
- if (!params.onCellFocused || event.rowIndex == null) {
3178
+ if (event.rowIndex == null) {
3162
3179
  return;
3163
3180
  }
3164
3181
  const api = event.api;
@@ -3172,8 +3189,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3172
3189
  if (!colDef || typeof colDef === 'string') {
3173
3190
  return;
3174
3191
  }
3175
- params.onCellFocused({ colDef, data });
3176
- }, [params]);
3192
+ // Prevent repeated callbacks to cell focus when focus didn't change
3193
+ const { sourceEvent } = event;
3194
+ if (sourceEvent) {
3195
+ const cell = sourceEvent.target.closest('.ag-cell');
3196
+ if (window.__stepaggrid_lastfocuseventtarget === cell) {
3197
+ return;
3198
+ }
3199
+ window.__stepaggrid_lastfocuseventtarget = cell;
3200
+ }
3201
+ paramsOnCellFocused?.({ colDef, data });
3202
+ }, [paramsOnCellFocused]);
3177
3203
  const onRowDragEnd = React.useCallback((event) => {
3178
3204
  clearHighlightRowClasses();
3179
3205
  gridElementRef.current = undefined;
@@ -3256,7 +3282,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3256
3282
  enableClickSelection: params.enableClickSelection ?? false,
3257
3283
  mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
3258
3284
  }
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 }) })] }));
3285
+ : 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
3286
  };
3261
3287
  const quickFilterParser = (filterStr) => {
3262
3288
  // filter is exact matches exactly groups separated by commas
@@ -3401,14 +3427,10 @@ const GridCell = (props, custom) => {
3401
3427
  resizable: true,
3402
3428
  valueSetter: custom?.editor ? blockValueSetter : undefined,
3403
3429
  editable: props.editable ?? !!custom?.editor,
3404
- ...(custom?.editor
3405
- ? {
3406
- cellClassRules: GridCellMultiSelectClassRules,
3407
- cellEditor: GenericCellEditorComponentWrapper(custom?.editor),
3408
- }
3409
- : {
3410
- cellEditor: CellEditorToBlockEditing,
3411
- }),
3430
+ ...(custom?.editor && {
3431
+ cellClassRules: GridCellMultiSelectClassRules,
3432
+ cellEditor: GenericCellEditorComponentWrapper(custom?.editor),
3433
+ }),
3412
3434
  suppressKeyboardEvent: suppressCellKeyboardEvents,
3413
3435
  ...(custom?.editorParams
3414
3436
  ? {
@@ -3435,19 +3457,6 @@ const GridCell = (props, custom) => {
3435
3457
  },
3436
3458
  };
3437
3459
  };
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
3460
  const GenericCellEditorComponentWrapper = (editor) => {
3452
3461
  const obj = { editor };
3453
3462
  return React.forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
@@ -5541,12 +5550,9 @@ const GridContextProvider = (props) => {
5541
5550
  const preRow = gridApi.getFocusedCell();
5542
5551
  // 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
5552
  // we are managing it ourselves
5544
- gridApi.stopEditing();
5545
- if (tabDirection === 1) {
5546
- gridApi.tabToNextCell();
5547
- }
5548
- else {
5549
- gridApi.tabToPreviousCell();
5553
+ const didTab = tabDirection === 1 ? gridApi.tabToNextCell() : gridApi.tabToPreviousCell();
5554
+ if (!didTab) {
5555
+ break;
5550
5556
  }
5551
5557
  if (gridApi.isDestroyed()) {
5552
5558
  return true;