@linzjs/step-ag-grid 8.2.0 → 8.2.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.
@@ -4,6 +4,7 @@ import { GridBaseRow } from "../components/Grid";
4
4
  export interface GridContextType {
5
5
  gridReady: boolean;
6
6
  setGridApi: (gridApi: GridApi | undefined) => void;
7
+ prePopupOps: () => void;
7
8
  setQuickFilter: (quickFilter: string) => void;
8
9
  editingCells: () => boolean;
9
10
  getSelectedRows: <T extends GridBaseRow>() => T[];
@@ -1962,6 +1962,9 @@ var MenuRadioGroup = forwardRef(MenuRadioGroupFr);
1962
1962
 
1963
1963
  var GridContext = createContext({
1964
1964
  gridReady: false,
1965
+ prePopupOps: function () {
1966
+ console.error("no context provider for prePopupOps");
1967
+ },
1965
1968
  externallySelectedItemsAreInSync: false,
1966
1969
  setGridApi: function () {
1967
1970
  console.error("no context provider for setGridApi");
@@ -2071,6 +2074,7 @@ var GridContextProvider = function (props) {
2071
2074
  var _a = useState(), gridApi = _a[0], _setGridApi = _a[1];
2072
2075
  var _b = useState(false), gridReady = _b[0], setGridReady = _b[1];
2073
2076
  var idsBeforeUpdate = useRef([]);
2077
+ var prePopupFocusedCell = useRef();
2074
2078
  var _c = useState(false), externallySelectedItemsAreInSync = _c[0], setExternallySelectedItemsAreInSync = _c[1];
2075
2079
  var setGridApi = useCallback(function (gridApi) {
2076
2080
  _setGridApi(gridApi);
@@ -2088,6 +2092,13 @@ var GridContextProvider = function (props) {
2088
2092
  }
2089
2093
  return gridApi ? hasApiFn(gridApi) : noApiFn();
2090
2094
  }, [gridApi]);
2095
+ /**
2096
+ * Before a popup record the currently focused cell.
2097
+ */
2098
+ var prePopupOps = useCallback(function () {
2099
+ var _a;
2100
+ prePopupFocusedCell.current = (_a = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getFocusedCell()) !== null && _a !== void 0 ? _a : undefined;
2101
+ }, [gridApi]);
2091
2102
  /**
2092
2103
  * Set the quick filter value to grid.
2093
2104
  */
@@ -2273,7 +2284,12 @@ var GridContextProvider = function (props) {
2273
2284
  document.body.clientWidth && gridApi.sizeColumnsToFit();
2274
2285
  });
2275
2286
  }, [gridApiOp]);
2276
- var stopEditing = useCallback(function () { return gridApiOp(function (gridApi) { return gridApi.stopEditing(); }); }, [gridApiOp]);
2287
+ var stopEditing = useCallback(function () {
2288
+ if (prePopupFocusedCell.current) {
2289
+ gridApi === null || gridApi === void 0 ? void 0 : gridApi.setFocusedCell(prePopupFocusedCell.current.rowIndex, prePopupFocusedCell.current.column);
2290
+ }
2291
+ gridApiOp(function (gridApi) { return gridApi.stopEditing(); });
2292
+ }, [gridApi, gridApiOp]);
2277
2293
  var selectNextCell = useCallback(function (tabDirection) {
2278
2294
  if (tabDirection === void 0) { tabDirection = 0; }
2279
2295
  gridApiOp(function (gridApi) {
@@ -2289,12 +2305,11 @@ var GridContextProvider = function (props) {
2289
2305
  case 0:
2290
2306
  setSaving && setSaving(true);
2291
2307
  return [4 /*yield*/, gridApiOp(function (gridApi) { return __awaiter(void 0, void 0, void 0, function () {
2292
- var preOpCell, selectedRows, ok, cell, postOpCell;
2308
+ var selectedRows, ok, cell, postPopupFocusedCell;
2293
2309
  var _a;
2294
2310
  return __generator(this, function (_b) {
2295
2311
  switch (_b.label) {
2296
2312
  case 0:
2297
- preOpCell = gridApi.getFocusedCell();
2298
2313
  selectedRows = props.selectedRows;
2299
2314
  ok = false;
2300
2315
  return [4 /*yield*/, modifyUpdating((_a = props.field) !== null && _a !== void 0 ? _a : "", selectedRows.map(function (data) { return data.id; }), function () { return __awaiter(void 0, void 0, void 0, function () {
@@ -2329,12 +2344,12 @@ var GridContextProvider = function (props) {
2329
2344
  // Don't set saving if ok as the form has already closed
2330
2345
  setSaving && setSaving(false);
2331
2346
  }
2332
- postOpCell = gridApi.getFocusedCell();
2347
+ postPopupFocusedCell = gridApi.getFocusedCell();
2333
2348
  if (tabDirection &&
2334
- preOpCell &&
2335
- postOpCell &&
2336
- preOpCell.rowIndex == postOpCell.rowIndex &&
2337
- preOpCell.column.getColId() == postOpCell.column.getColId()) {
2349
+ prePopupFocusedCell.current &&
2350
+ postPopupFocusedCell &&
2351
+ prePopupFocusedCell.current.rowIndex == postPopupFocusedCell.rowIndex &&
2352
+ prePopupFocusedCell.current.column.getColId() == postPopupFocusedCell.column.getColId()) {
2338
2353
  selectNextCell(tabDirection);
2339
2354
  }
2340
2355
  return [2 /*return*/, ok];
@@ -2372,6 +2387,7 @@ var GridContextProvider = function (props) {
2372
2387
  }); }, [externallySelectedItemsAreInSync]);
2373
2388
  return (jsx(GridContext.Provider, __assign({ value: {
2374
2389
  gridReady: gridReady,
2390
+ prePopupOps: prePopupOps,
2375
2391
  setGridApi: setGridApi,
2376
2392
  setQuickFilter: setQuickFilter,
2377
2393
  selectRowsById: selectRowsById,
@@ -2722,7 +2738,7 @@ var GridHeaderSelect = function (_a) {
2722
2738
  */
2723
2739
  var Grid = function (params) {
2724
2740
  var _a, _b, _c;
2725
- var _d = useContext(GridContext), gridReady = _d.gridReady, setGridApi = _d.setGridApi, setQuickFilter = _d.setQuickFilter, ensureRowVisible = _d.ensureRowVisible, selectRowsById = _d.selectRowsById, focusByRowById = _d.focusByRowById, ensureSelectedRowIsVisible = _d.ensureSelectedRowIsVisible, sizeColumnsToFit = _d.sizeColumnsToFit, externallySelectedItemsAreInSync = _d.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _d.setExternallySelectedItemsAreInSync;
2741
+ var _d = useContext(GridContext), gridReady = _d.gridReady, setGridApi = _d.setGridApi, prePopupOps = _d.prePopupOps, setQuickFilter = _d.setQuickFilter, ensureRowVisible = _d.ensureRowVisible, selectRowsById = _d.selectRowsById, focusByRowById = _d.focusByRowById, ensureSelectedRowIsVisible = _d.ensureSelectedRowIsVisible, sizeColumnsToFit = _d.sizeColumnsToFit, externallySelectedItemsAreInSync = _d.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _d.setExternallySelectedItemsAreInSync;
2726
2742
  var checkUpdating = useContext(GridUpdatingContext).checkUpdating;
2727
2743
  var _e = useState(""), internalQuickFilter = _e[0], setInternalQuickFilter = _e[1];
2728
2744
  var lastSelectedIds = useRef([]);
@@ -2888,6 +2904,7 @@ var Grid = function (params) {
2888
2904
  }, []);
2889
2905
  var startCellEditing = useCallback(function (event) {
2890
2906
  var _a;
2907
+ prePopupOps();
2891
2908
  if (!event.node.isSelected()) {
2892
2909
  event.node.setSelected(true, true);
2893
2910
  }
@@ -2901,7 +2918,7 @@ var Grid = function (params) {
2901
2918
  colKey: event.column.getColId()
2902
2919
  });
2903
2920
  }
2904
- }, [checkUpdating]);
2921
+ }, [checkUpdating, prePopupOps]);
2905
2922
  var onCellDoubleClick = useCallback(function (event) {
2906
2923
  if (!invokeEditAction(event))
2907
2924
  startCellEditing(event);
@@ -2932,12 +2949,6 @@ var Grid = function (params) {
2932
2949
  startCellEditing(e);
2933
2950
  }
2934
2951
  }, [startCellEditing]);
2935
- var onCellEditingStopped = useCallback(function (event) {
2936
- refreshSelectedRows(event);
2937
- // The grid loses cell focus after editing
2938
- var cell = event.api.getFocusedCell();
2939
- cell && event.api.setFocusedCell(cell.rowIndex, cell.column);
2940
- }, [refreshSelectedRows]);
2941
2952
  // When rows added or removed then resize columns
2942
2953
  useEffect(function () {
2943
2954
  if (columnDefs === null || columnDefs === void 0 ? void 0 : columnDefs.length) {
@@ -2946,7 +2957,7 @@ var Grid = function (params) {
2946
2957
  }, [columnDefs === null || columnDefs === void 0 ? void 0 : columnDefs.length, sizeColumnsToFit]);
2947
2958
  return (jsxs("div", __assign({ "data-testid": params["data-testid"], className: clsx("Grid-container", "ag-theme-alpine", staleGrid && "Grid-sortIsStale", gridReady && params.rowData && "Grid-ready") }, { children: [params.quickFilter && (jsx("div", __assign({ className: "Grid-quickFilter" }, { children: jsx("input", { "aria-label": "Search", className: "lui-margin-top-xxs lui-margin-bottom-xxs Grid-quickFilterBox", type: "text", placeholder: (_a = params.quickFilterPlaceholder) !== null && _a !== void 0 ? _a : "Search...", value: internalQuickFilter, onChange: function (event) {
2948
2959
  setInternalQuickFilter(event.target.value);
2949
- } }) }))), jsx(AgGridReact, { animateRows: params.animateRows, rowClassRules: params.rowClassRules, defaultColDef: params.defaultColDef, getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: (_b = params.rowSelection) !== null && _b !== void 0 ? _b : "multiple", suppressBrowserResizeObserver: true, colResizeDefault: "shift", onFirstDataRendered: sizeColumnsToFit, onGridSizeChanged: sizeColumnsToFit, suppressClickEdit: true, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, onCellEditingStopped: onCellEditingStopped, domLayout: params.domLayout, columnDefs: columnDefs, rowData: params.rowData, noRowsOverlayComponent: noRowsOverlayComponent, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_c = params.postSortRows) !== null && _c !== void 0 ? _c : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll })] })));
2960
+ } }) }))), jsx(AgGridReact, { animateRows: params.animateRows, rowClassRules: params.rowClassRules, defaultColDef: params.defaultColDef, getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: (_b = params.rowSelection) !== null && _b !== void 0 ? _b : "multiple", suppressBrowserResizeObserver: true, colResizeDefault: "shift", onFirstDataRendered: sizeColumnsToFit, onGridSizeChanged: sizeColumnsToFit, suppressClickEdit: true, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, domLayout: params.domLayout, columnDefs: columnDefs, rowData: params.rowData, noRowsOverlayComponent: noRowsOverlayComponent, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_c = params.postSortRows) !== null && _c !== void 0 ? _c : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll })] })));
2950
2961
  };
2951
2962
 
2952
2963
  var GridCellMultiSelectClassRules = {
@@ -3955,9 +3966,12 @@ var GridFormPopoverMenu = function (props) {
3955
3966
  setSubComponentSelected(subComponentSelected === item ? null : item);
3956
3967
  e.keepOpen = true;
3957
3968
  return [3 /*break*/, 3];
3958
- case 1: return [4 /*yield*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
3959
- return [2 /*return*/, actionClick(item)];
3960
- }); }); }, e.key === "Tab" ? (e.shiftKey ? -1 : 1) : 0)];
3969
+ case 1:
3970
+ subComponentIsValid.current = true;
3971
+ setSubSelectedValue(null);
3972
+ return [4 /*yield*/, updateValue(function () { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
3973
+ return [2 /*return*/, actionClick(item)];
3974
+ }); }); }, e.key === "Tab" ? (e.shiftKey ? -1 : 1) : 0)];
3961
3975
  case 2:
3962
3976
  _a.sent();
3963
3977
  _a.label = 3;