@linzjs/step-ag-grid 14.3.3 → 14.4.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.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@linzjs/step-ag-grid",
3
3
  "repository": "github:linz/step-ag-grid.git",
4
4
  "license": "MIT",
5
- "version": "14.3.3",
5
+ "version": "14.4.0",
6
6
  "keywords": [
7
7
  "aggrid",
8
8
  "ag-grid",
@@ -83,7 +83,6 @@ export const Grid = ({
83
83
  const {
84
84
  gridReady,
85
85
  setApis,
86
- prePopupOps,
87
86
  ensureRowVisible,
88
87
  getFirstRowId,
89
88
  selectRowsById,
@@ -98,7 +97,8 @@ export const Grid = ({
98
97
  setOnCellEditingComplete,
99
98
  getColDef,
100
99
  } = useContext(GridContext);
101
- const { checkUpdating, updatedDep, updatingCols } = useContext(GridUpdatingContext);
100
+ const { updatedDep, updatingCols } = useContext(GridUpdatingContext);
101
+ const gridContext = useContext(GridContext);
102
102
 
103
103
  const gridDivRef = useRef<HTMLDivElement>(null);
104
104
 
@@ -387,23 +387,13 @@ export const Grid = ({
387
387
  */
388
388
  const startCellEditing = useCallback(
389
389
  (event: CellEvent) => {
390
- prePopupOps();
391
- if (!event.node.isSelected()) {
392
- event.node.setSelected(true, true);
393
- }
394
- // Cell already being edited, so don't re-edit until finished
395
- if (checkUpdating([event.colDef.field ?? ""], event.data.id)) {
396
- return;
397
- }
398
-
399
- if (event.rowIndex !== null) {
400
- event.api.startEditingCell({
401
- rowIndex: event.rowIndex,
402
- colKey: event.column.getColId(),
390
+ event.data.id &&
391
+ gridContext.startCellEditing({
392
+ rowId: event.data.id,
393
+ colId: event.column.getColId(),
403
394
  });
404
- }
405
395
  },
406
- [checkUpdating, prePopupOps],
396
+ [gridContext],
407
397
  );
408
398
 
409
399
  /**
@@ -39,6 +39,7 @@ export interface GridContextType<RowType extends GridBaseRow> {
39
39
  autoSizeColumns: (props?: AutoSizeColumnsProps) => AutoSizeColumnsResult;
40
40
  sizeColumnsToFit: () => void;
41
41
  cancelEdit: () => void;
42
+ startCellEditing: ({ rowId, colId }: { rowId: number; colId: string }) => void;
42
43
  stopEditing: () => void;
43
44
  updatingCells: (
44
45
  props: { selectedRows: GridBaseRow[]; field?: string },
@@ -147,6 +148,9 @@ export const GridContext = createContext<GridContextType<any>>({
147
148
  cancelEdit: () => {
148
149
  console.error("no context provider for cancelEdit");
149
150
  },
151
+ startCellEditing: () => {
152
+ console.error("no context provider for startCellEditing");
153
+ },
150
154
  stopEditing: () => {
151
155
  console.error("no context provider for stopEditing");
152
156
  },
@@ -21,7 +21,7 @@ interface GridContextProps {
21
21
  * Also, make sure the provider is created in a separate component, otherwise it won't be found.
22
22
  */
23
23
  export const GridContextProvider = <RowType extends GridBaseRow>(props: GridContextProps): ReactElement => {
24
- const { modifyUpdating } = useContext(GridUpdatingContext);
24
+ const { modifyUpdating, checkUpdating } = useContext(GridUpdatingContext);
25
25
  const [gridApi, setGridApi] = useState<GridApi>();
26
26
  const [columnApi, setColumnApi] = useState<ColumnApi>();
27
27
  const [gridReady, setGridReady] = useState(false);
@@ -377,6 +377,41 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
377
377
  gridApi.stopEditing();
378
378
  }, [gridApi]);
379
379
 
380
+ const startCellEditing = useCallback(
381
+ async ({ rowId, colId }: { rowId: number; colId: string }) => {
382
+ if (!gridApi) return;
383
+
384
+ const colDef = gridApi.getColumnDef(colId);
385
+ if (!colDef) return;
386
+
387
+ // Cell already being edited, so don't re-edit until finished
388
+ if (checkUpdating([colDef.field ?? ""], rowId)) {
389
+ return;
390
+ }
391
+ const rowNode = gridApi.getRowNode(`${rowId}`);
392
+ if (!rowNode) {
393
+ return;
394
+ }
395
+
396
+ if (!rowNode.isSelected()) {
397
+ rowNode.setSelected(true, true);
398
+ }
399
+ prePopupOps();
400
+
401
+ const rowIndex = rowNode.rowIndex;
402
+ if (rowIndex != null) {
403
+ const focusAndEdit = () => {
404
+ gridApi.startEditingCell({
405
+ rowIndex,
406
+ colKey: colId,
407
+ });
408
+ };
409
+ defer(focusAndEdit);
410
+ }
411
+ },
412
+ [checkUpdating, gridApi, prePopupOps],
413
+ );
414
+
380
415
  /**
381
416
  * This differs from stopEdit in that it will also invoke cellEditingCompleteCallback
382
417
  */
@@ -618,6 +653,7 @@ export const GridContextProvider = <RowType extends GridBaseRow>(props: GridCont
618
653
  ensureSelectedRowIsVisible,
619
654
  sizeColumnsToFit,
620
655
  autoSizeColumns,
656
+ startCellEditing,
621
657
  stopEditing,
622
658
  cancelEdit,
623
659
  updatingCells,