@linzjs/step-ag-grid 14.3.3 → 14.5.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.
@@ -36,6 +36,10 @@ export interface GridContextType<RowType extends GridBaseRow> {
36
36
  autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult;
37
37
  sizeColumnsToFit: () => void;
38
38
  cancelEdit: () => void;
39
+ startCellEditing: ({ rowId, colId }: {
40
+ rowId: number;
41
+ colId: string;
42
+ }) => void;
39
43
  stopEditing: () => void;
40
44
  updatingCells: (props: {
41
45
  selectedRows: GridBaseRow[];
@@ -220,6 +220,9 @@ var GridContext = createContext({
220
220
  cancelEdit: function () {
221
221
  console.error("no context provider for cancelEdit");
222
222
  },
223
+ startCellEditing: function () {
224
+ console.error("no context provider for startCellEditing");
225
+ },
223
226
  stopEditing: function () {
224
227
  console.error("no context provider for stopEditing");
225
228
  },
@@ -716,13 +719,14 @@ var GridHeaderSelect = function (_a) {
716
719
  * Wrapper for AgGrid to add commonly used functionality.
717
720
  */
718
721
  var Grid = function (_a) {
719
- var _b, _c, _d;
720
- var dataTestId = _a["data-testid"], _e = _a.rowSelection, rowSelection = _e === void 0 ? "multiple" : _e, _f = _a.suppressColumnVirtualization, suppressColumnVirtualization = _f === void 0 ? true : _f, _g = _a.theme, theme = _g === void 0 ? "ag-theme-alpine" : _g, _h = _a.sizeColumns, sizeColumns = _h === void 0 ? "auto" : _h, _j = _a.selectColumnPinned, selectColumnPinned = _j === void 0 ? null : _j, params = __rest(_a, ["data-testid", "rowSelection", "suppressColumnVirtualization", "theme", "sizeColumns", "selectColumnPinned"]);
721
- var _k = useContext(GridContext), gridReady = _k.gridReady, setApis = _k.setApis, prePopupOps = _k.prePopupOps, ensureRowVisible = _k.ensureRowVisible, getFirstRowId = _k.getFirstRowId, selectRowsById = _k.selectRowsById, focusByRowById = _k.focusByRowById, ensureSelectedRowIsVisible = _k.ensureSelectedRowIsVisible, autoSizeColumns = _k.autoSizeColumns, sizeColumnsToFit = _k.sizeColumnsToFit, externallySelectedItemsAreInSync = _k.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _k.setExternallySelectedItemsAreInSync, isExternalFilterPresent = _k.isExternalFilterPresent, doesExternalFilterPass = _k.doesExternalFilterPass, setOnCellEditingComplete = _k.setOnCellEditingComplete, getColDef = _k.getColDef;
722
- var _l = useContext(GridUpdatingContext), checkUpdating = _l.checkUpdating, updatedDep = _l.updatedDep, updatingCols = _l.updatingCols;
722
+ var _b, _c, _d, _e;
723
+ var dataTestId = _a["data-testid"], _f = _a.rowSelection, rowSelection = _f === void 0 ? "multiple" : _f, _g = _a.suppressColumnVirtualization, suppressColumnVirtualization = _g === void 0 ? true : _g, _h = _a.theme, theme = _h === void 0 ? "ag-theme-alpine" : _h, _j = _a.sizeColumns, sizeColumns = _j === void 0 ? "auto" : _j, _k = _a.selectColumnPinned, selectColumnPinned = _k === void 0 ? null : _k, params = __rest(_a, ["data-testid", "rowSelection", "suppressColumnVirtualization", "theme", "sizeColumns", "selectColumnPinned"]);
724
+ var _l = useContext(GridContext), gridReady = _l.gridReady, setApis = _l.setApis, ensureRowVisible = _l.ensureRowVisible, getFirstRowId = _l.getFirstRowId, selectRowsById = _l.selectRowsById, focusByRowById = _l.focusByRowById, ensureSelectedRowIsVisible = _l.ensureSelectedRowIsVisible, autoSizeColumns = _l.autoSizeColumns, sizeColumnsToFit = _l.sizeColumnsToFit, externallySelectedItemsAreInSync = _l.externallySelectedItemsAreInSync, setExternallySelectedItemsAreInSync = _l.setExternallySelectedItemsAreInSync, isExternalFilterPresent = _l.isExternalFilterPresent, doesExternalFilterPass = _l.doesExternalFilterPass, setOnCellEditingComplete = _l.setOnCellEditingComplete, getColDef = _l.getColDef;
725
+ var _m = useContext(GridUpdatingContext), updatedDep = _m.updatedDep, updatingCols = _m.updatingCols;
726
+ var gridContext = useContext(GridContext);
723
727
  var gridDivRef = useRef(null);
724
728
  var lastSelectedIds = useRef([]);
725
- var _m = useState(false), staleGrid = _m[0], setStaleGrid = _m[1];
729
+ var _o = useState(false), staleGrid = _o[0], setStaleGrid = _o[1];
726
730
  var postSortRows = usePostSortRowsHook({ setStaleGrid: setStaleGrid });
727
731
  /**
728
732
  * onContentSize should only be called at maximum twice.
@@ -985,22 +989,12 @@ var Grid = function (_a) {
985
989
  * Make sure node is selected for editing and start edit
986
990
  */
987
991
  var startCellEditing = useCallback(function (event) {
988
- var _a;
989
- prePopupOps();
990
- if (!event.node.isSelected()) {
991
- event.node.setSelected(true, true);
992
- }
993
- // Cell already being edited, so don't re-edit until finished
994
- if (checkUpdating([(_a = event.colDef.field) !== null && _a !== void 0 ? _a : ""], event.data.id)) {
995
- return;
996
- }
997
- if (event.rowIndex !== null) {
998
- event.api.startEditingCell({
999
- rowIndex: event.rowIndex,
1000
- colKey: event.column.getColId()
992
+ event.data.id &&
993
+ gridContext.startCellEditing({
994
+ rowId: event.data.id,
995
+ colId: event.column.getColId()
1001
996
  });
1002
- }
1003
- }, [checkUpdating, prePopupOps]);
997
+ }, [gridContext]);
1004
998
  /**
1005
999
  * Handle double click edit
1006
1000
  */
@@ -1048,8 +1042,11 @@ var Grid = function (_a) {
1048
1042
  * but we don't want the non-flex auto-sized columns to "fit" size, so suppressSizeToFit is set to true.
1049
1043
  */
1050
1044
  var columnDefsAdjusted = useMemo(function () {
1051
- return columnDefs.map(function (colDef) { return (__assign(__assign({}, colDef), { suppressSizeToFit: (sizeColumns === "auto" || sizeColumns === "auto-skip-headers") && !colDef.flex })); });
1052
- }, [columnDefs, sizeColumns]);
1045
+ return columnDefs.map(function (colDef) {
1046
+ var _a;
1047
+ return (__assign(__assign({}, colDef), { suppressSizeToFit: (sizeColumns === "auto" || sizeColumns === "auto-skip-headers") && !colDef.flex, sortable: colDef.sortable && ((_a = params.defaultColDef) === null || _a === void 0 ? void 0 : _a.sortable) !== false }));
1048
+ });
1049
+ }, [columnDefs, (_d = params.defaultColDef) === null || _d === void 0 ? void 0 : _d.sortable, sizeColumns]);
1053
1050
  /**
1054
1051
  * Set of colIds that need auto-sizing.
1055
1052
  */
@@ -1123,7 +1120,7 @@ var Grid = function (_a) {
1123
1120
  }, onRowDataChanged: onRowDataChanged, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, domLayout: params.domLayout, onColumnResized: onColumnResized, defaultColDef: __assign({ minWidth: 48 }, omit(params.defaultColDef, ["editable"])), columnDefs: columnDefsAdjusted, rowData: params.rowData, noRowsOverlayComponent: GridNoRowsOverlay, noRowsOverlayComponentParams: {
1124
1121
  rowData: params.rowData,
1125
1122
  noRowsOverlayText: params.noRowsOverlayText
1126
- }, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_d = params.postSortRows) !== null && _d !== void 0 ? _d : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true }) })) })));
1123
+ }, onModelUpdated: onModelUpdated, onGridReady: onGridReady, onSortChanged: ensureSelectedRowIsVisible, postSortRows: (_e = params.postSortRows) !== null && _e !== void 0 ? _e : postSortRows, onSelectionChanged: synchroniseExternalStateToGridSelection, onColumnMoved: params.onColumnMoved, alwaysShowVerticalScroll: params.alwaysShowVerticalScroll, isExternalFilterPresent: isExternalFilterPresent, doesExternalFilterPass: doesExternalFilterPass, maintainColumnOrder: true }) })) })));
1127
1124
  };
1128
1125
 
1129
1126
  var GridPopoverContext = createContext({
@@ -4647,16 +4644,16 @@ var GridWrapper = function (_a) {
4647
4644
  * Also, make sure the provider is created in a separate component, otherwise it won't be found.
4648
4645
  */
4649
4646
  var GridContextProvider = function (props) {
4650
- var modifyUpdating = useContext(GridUpdatingContext).modifyUpdating;
4651
- var _a = useState(), gridApi = _a[0], setGridApi = _a[1];
4652
- var _b = useState(), columnApi = _b[0], setColumnApi = _b[1];
4653
- var _c = useState(false), gridReady = _c[0], setGridReady = _c[1];
4654
- var _d = useState(""), quickFilter = _d[0], setQuickFilter = _d[1];
4655
- var _e = useState([]), invisibleColumnIds = _e[0], setInvisibleColumnIds = _e[1];
4647
+ var _a = useContext(GridUpdatingContext), modifyUpdating = _a.modifyUpdating, checkUpdating = _a.checkUpdating;
4648
+ var _b = useState(), gridApi = _b[0], setGridApi = _b[1];
4649
+ var _c = useState(), columnApi = _c[0], setColumnApi = _c[1];
4650
+ var _d = useState(false), gridReady = _d[0], setGridReady = _d[1];
4651
+ var _e = useState(""), quickFilter = _e[0], setQuickFilter = _e[1];
4652
+ var _f = useState([]), invisibleColumnIds = _f[0], setInvisibleColumnIds = _f[1];
4656
4653
  var testId = useRef();
4657
4654
  var idsBeforeUpdate = useRef([]);
4658
4655
  var prePopupFocusedCell = useRef();
4659
- var _f = useState(false), externallySelectedItemsAreInSync = _f[0], setExternallySelectedItemsAreInSync = _f[1];
4656
+ var _g = useState(false), externallySelectedItemsAreInSync = _g[0], setExternallySelectedItemsAreInSync = _g[1];
4660
4657
  var externalFilters = useRef([]);
4661
4658
  /**
4662
4659
  * Set quick filter directly on grid, based on previously save quickFilter state.
@@ -4941,6 +4938,43 @@ var GridContextProvider = function (props) {
4941
4938
  }
4942
4939
  gridApi.stopEditing();
4943
4940
  }, [gridApi]);
4941
+ var startCellEditing = useCallback(function (_a) {
4942
+ var rowId = _a.rowId, colId = _a.colId;
4943
+ return __awaiter(void 0, void 0, void 0, function () {
4944
+ var colDef, rowNode, rowIndex, focusAndEdit;
4945
+ var _b;
4946
+ return __generator(this, function (_c) {
4947
+ if (!gridApi)
4948
+ return [2 /*return*/];
4949
+ colDef = gridApi.getColumnDef(colId);
4950
+ if (!colDef)
4951
+ return [2 /*return*/];
4952
+ prePopupOps();
4953
+ rowNode = gridApi.getRowNode("".concat(rowId));
4954
+ if (!rowNode) {
4955
+ return [2 /*return*/];
4956
+ }
4957
+ if (!rowNode.isSelected()) {
4958
+ rowNode.setSelected(true, false);
4959
+ }
4960
+ // Cell already being edited, so don't re-edit until finished
4961
+ if (checkUpdating([(_b = colDef.field) !== null && _b !== void 0 ? _b : ""], rowId)) {
4962
+ return [2 /*return*/];
4963
+ }
4964
+ rowIndex = rowNode.rowIndex;
4965
+ if (rowIndex != null) {
4966
+ focusAndEdit = function () {
4967
+ gridApi.startEditingCell({
4968
+ rowIndex: rowIndex,
4969
+ colKey: colId
4970
+ });
4971
+ };
4972
+ defer$1(focusAndEdit);
4973
+ }
4974
+ return [2 /*return*/];
4975
+ });
4976
+ });
4977
+ }, [checkUpdating, gridApi, prePopupOps]);
4944
4978
  /**
4945
4979
  * This differs from stopEdit in that it will also invoke cellEditingCompleteCallback
4946
4980
  */
@@ -5151,6 +5185,7 @@ var GridContextProvider = function (props) {
5151
5185
  ensureSelectedRowIsVisible: ensureSelectedRowIsVisible,
5152
5186
  sizeColumnsToFit: sizeColumnsToFit,
5153
5187
  autoSizeColumns: autoSizeColumns,
5188
+ startCellEditing: startCellEditing,
5154
5189
  stopEditing: stopEditing,
5155
5190
  cancelEdit: cancelEdit,
5156
5191
  updatingCells: updatingCells,