@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.
@@ -2760,7 +2760,7 @@ ModuleRegistry.registerModules([AllCommunityModule]);
2760
2760
  /**
2761
2761
  * Wrapper for AgGrid to add commonly used functionality.
2762
2762
  */
2763
- 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 }) => {
2763
+ 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 }) => {
2764
2764
  const { gridReady, gridRenderState, setApis, ensureRowVisible, getFirstRowId, selectRowsById, focusByRowById, ensureSelectedRowIsVisible, autoSizeColumns, sizeColumnsToFit, externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync, isExternalFilterPresent, doesExternalFilterPass, setOnBulkEditingComplete, getColDef, showNoRowsOverlay, prePopupOps, startCellEditing, } = useGridContext();
2765
2765
  const { updatedDep, updatingCols } = useContext(GridUpdatingContext);
2766
2766
  const gridDivRef = useRef(null);
@@ -2826,10 +2826,27 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
2826
2826
  needsAutoSize.current = false;
2827
2827
  }, [autoSizeColumns, gridRenderState, params, rowData, sizeColumns, sizeColumnsToFit]);
2828
2828
  const lastOwnerDocumentRef = useRef();
2829
+ const wasVisibleRef = useRef(false);
2829
2830
  /**
2830
2831
  * Auto-size windows that had deferred auto-size
2832
+ * Reset focus if panel went from invisible to visible.
2831
2833
  */
2832
2834
  useInterval(() => {
2835
+ // If grid has become visible after previously being hidden, then refocus the last focused cell.
2836
+ const visible = !!gridDivRef.current?.checkVisibility();
2837
+ if (visible && !wasVisibleRef.current) {
2838
+ wasVisibleRef.current = true;
2839
+ const el = window.__stepaggrid_lastfocuseventtarget;
2840
+ if (el) {
2841
+ // Setting this to null will cause a new refocus event
2842
+ window.__stepaggrid_lastfocuseventtarget = null;
2843
+ // Check element is still part of document
2844
+ if (el.checkVisibility()) {
2845
+ el.focus();
2846
+ }
2847
+ }
2848
+ }
2849
+ wasVisibleRef.current = visible;
2833
2850
  // Check if window has been popped out and needs resize
2834
2851
  const currentDocument = gridDivRef.current?.ownerDocument;
2835
2852
  if (currentDocument !== lastOwnerDocumentRef.current) {
@@ -3156,7 +3173,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3156
3173
  }
3157
3174
  }, [clearHighlightRowClasses]);
3158
3175
  const onCellFocused = useCallback((event) => {
3159
- if (!params.onCellFocused || event.rowIndex == null) {
3176
+ if (event.rowIndex == null) {
3160
3177
  return;
3161
3178
  }
3162
3179
  const api = event.api;
@@ -3170,8 +3187,17 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3170
3187
  if (!colDef || typeof colDef === 'string') {
3171
3188
  return;
3172
3189
  }
3173
- params.onCellFocused({ colDef, data });
3174
- }, [params]);
3190
+ // Prevent repeated callbacks to cell focus when focus didn't change
3191
+ const { sourceEvent } = event;
3192
+ if (sourceEvent) {
3193
+ const cell = sourceEvent.target.closest('.ag-cell');
3194
+ if (window.__stepaggrid_lastfocuseventtarget === cell) {
3195
+ return;
3196
+ }
3197
+ window.__stepaggrid_lastfocuseventtarget = cell;
3198
+ }
3199
+ paramsOnCellFocused?.({ colDef, data });
3200
+ }, [paramsOnCellFocused]);
3175
3201
  const onRowDragEnd = useCallback((event) => {
3176
3202
  clearHighlightRowClasses();
3177
3203
  gridElementRef.current = undefined;
@@ -3254,7 +3280,7 @@ const Grid = ({ 'data-testid': dataTestId, defaultPostSort = true, rowSelection
3254
3280
  enableClickSelection: params.enableClickSelection ?? false,
3255
3281
  mode: rowSelection == 'single' ? 'singleRow' : 'multiRow',
3256
3282
  }
3257
- : 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 }) })] }));
3283
+ : 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 }) })] }));
3258
3284
  };
3259
3285
  const quickFilterParser = (filterStr) => {
3260
3286
  // filter is exact matches exactly groups separated by commas
@@ -3399,14 +3425,10 @@ const GridCell = (props, custom) => {
3399
3425
  resizable: true,
3400
3426
  valueSetter: custom?.editor ? blockValueSetter : undefined,
3401
3427
  editable: props.editable ?? !!custom?.editor,
3402
- ...(custom?.editor
3403
- ? {
3404
- cellClassRules: GridCellMultiSelectClassRules,
3405
- cellEditor: GenericCellEditorComponentWrapper(custom?.editor),
3406
- }
3407
- : {
3408
- cellEditor: CellEditorToBlockEditing,
3409
- }),
3428
+ ...(custom?.editor && {
3429
+ cellClassRules: GridCellMultiSelectClassRules,
3430
+ cellEditor: GenericCellEditorComponentWrapper(custom?.editor),
3431
+ }),
3410
3432
  suppressKeyboardEvent: suppressCellKeyboardEvents,
3411
3433
  ...(custom?.editorParams
3412
3434
  ? {
@@ -3433,19 +3455,6 @@ const GridCell = (props, custom) => {
3433
3455
  },
3434
3456
  };
3435
3457
  };
3436
- /**
3437
- * Ag-grid will start its own editor if editable is true and there is no cell editor
3438
- * like in the case of a cell that is editable because it triggers a modal.
3439
- * This will block that editor.
3440
- */
3441
- const CellEditorToBlockEditing = ({ stopEditing }) => {
3442
- useEffect(() => {
3443
- defer(() => {
3444
- stopEditing();
3445
- });
3446
- }, [stopEditing]);
3447
- return jsx(Fragment, {});
3448
- };
3449
3458
  const GenericCellEditorComponentWrapper = (editor) => {
3450
3459
  const obj = { editor };
3451
3460
  return forwardRef(function GenericCellEditorComponentFr(cellEditorParams, _) {
@@ -5539,12 +5548,9 @@ const GridContextProvider = (props) => {
5539
5548
  const preRow = gridApi.getFocusedCell();
5540
5549
  // If we don't do this ag-grid will do its own continuation of an edit on tab, we don't want that as
5541
5550
  // we are managing it ourselves
5542
- gridApi.stopEditing();
5543
- if (tabDirection === 1) {
5544
- gridApi.tabToNextCell();
5545
- }
5546
- else {
5547
- gridApi.tabToPreviousCell();
5551
+ const didTab = tabDirection === 1 ? gridApi.tabToNextCell() : gridApi.tabToPreviousCell();
5552
+ if (!didTab) {
5553
+ break;
5548
5554
  }
5549
5555
  if (gridApi.isDestroyed()) {
5550
5556
  return true;