@linzjs/step-ag-grid 14.3.1 → 14.3.3
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/dist/src/contexts/GridContext.d.ts +3 -2
- package/dist/src/contexts/GridUpdatingContext.d.ts +1 -1
- package/dist/step-ag-grid.esm.js +61 -60
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +31 -45
- package/src/contexts/GridContext.tsx +7 -2
- package/src/contexts/GridContextProvider.tsx +26 -27
- package/src/contexts/GridUpdatingContext.tsx +3 -3
- package/src/contexts/GridUpdatingContextProvider.tsx +3 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { ColumnApi, GridApi, RowNode } from "ag-grid-community";
|
|
2
|
+
import { ColDef, ColumnApi, GridApi, RowNode } from "ag-grid-community";
|
|
3
3
|
import { CsvExportParams } from "ag-grid-community/dist/lib/interfaces/exportParams";
|
|
4
4
|
import { ColDefT, GridBaseRow } from "../components";
|
|
5
5
|
export type GridFilterExternal<RowType extends GridBaseRow> = (data: RowType, rowNode: RowNode) => boolean;
|
|
@@ -13,6 +13,8 @@ export type AutoSizeColumnsResult = {
|
|
|
13
13
|
} | null;
|
|
14
14
|
export interface GridContextType<RowType extends GridBaseRow> {
|
|
15
15
|
gridReady: boolean;
|
|
16
|
+
getColDef: (colId?: string) => ColDef | undefined;
|
|
17
|
+
getColumns: () => ColDefT<RowType>[];
|
|
16
18
|
setApis: (gridApi: GridApi | undefined, columnApi: ColumnApi | undefined, dataTestId?: string) => void;
|
|
17
19
|
prePopupOps: () => void;
|
|
18
20
|
setQuickFilter: (quickFilter: string) => void;
|
|
@@ -47,7 +49,6 @@ export interface GridContextType<RowType extends GridBaseRow> {
|
|
|
47
49
|
removeExternalFilter: (filter: GridFilterExternal<RowType>) => void;
|
|
48
50
|
isExternalFilterPresent: () => boolean;
|
|
49
51
|
doesExternalFilterPass: (node: RowNode) => boolean;
|
|
50
|
-
getColumns: () => ColDefT<RowType>[];
|
|
51
52
|
invisibleColumnIds: string[];
|
|
52
53
|
setInvisibleColumnIds: (colIds: string[]) => void;
|
|
53
54
|
downloadCsv: (csvExportParams?: CsvExportParams) => void;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
export type GridUpdatingContextType = {
|
|
3
3
|
checkUpdating: (fields: string | string[], id: number | string) => boolean;
|
|
4
|
-
isUpdating: () => boolean;
|
|
5
4
|
modifyUpdating: (fields: string | string[], ids: (number | string)[], fn: () => void | Promise<void>) => Promise<void>;
|
|
6
5
|
updatedDep: number;
|
|
6
|
+
updatingCols: () => string[];
|
|
7
7
|
};
|
|
8
8
|
export declare const GridUpdatingContext: import("react").Context<GridUpdatingContextType>;
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -123,6 +123,10 @@ function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else i
|
|
|
123
123
|
|
|
124
124
|
var GridContext = createContext({
|
|
125
125
|
gridReady: false,
|
|
126
|
+
getColDef: function () {
|
|
127
|
+
console.error("no context provider for getColDef");
|
|
128
|
+
return undefined;
|
|
129
|
+
},
|
|
126
130
|
getColumns: function () {
|
|
127
131
|
console.error("no context provider for getColumns");
|
|
128
132
|
return [];
|
|
@@ -265,9 +269,9 @@ var GridUpdatingContext = createContext({
|
|
|
265
269
|
console.error("Missing GridUpdatingContext");
|
|
266
270
|
return false;
|
|
267
271
|
},
|
|
268
|
-
|
|
272
|
+
updatingCols: function () {
|
|
269
273
|
console.error("Missing GridUpdatingContext");
|
|
270
|
-
return
|
|
274
|
+
return [];
|
|
271
275
|
},
|
|
272
276
|
modifyUpdating: function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
273
277
|
return __generator(this, function (_a) {
|
|
@@ -714,8 +718,8 @@ var GridHeaderSelect = function (_a) {
|
|
|
714
718
|
var Grid = function (_a) {
|
|
715
719
|
var _b, _c, _d;
|
|
716
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"]);
|
|
717
|
-
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;
|
|
718
|
-
var _l = useContext(GridUpdatingContext), checkUpdating = _l.checkUpdating, updatedDep = _l.updatedDep,
|
|
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;
|
|
719
723
|
var gridDivRef = useRef(null);
|
|
720
724
|
var lastSelectedIds = useRef([]);
|
|
721
725
|
var _m = useState(false), staleGrid = _m[0], setStaleGrid = _m[1];
|
|
@@ -944,12 +948,12 @@ var Grid = function (_a) {
|
|
|
944
948
|
return;
|
|
945
949
|
lastUpdatedDep.current = updatedDep;
|
|
946
950
|
// Don't update while there are spinners
|
|
947
|
-
if (
|
|
951
|
+
if (!isEmpty(updatingCols()))
|
|
948
952
|
return;
|
|
949
953
|
var skipHeader = sizeColumns === "auto-skip-headers";
|
|
950
954
|
autoSizeColumns({ skipHeader: skipHeader, userSizedColIds: userSizedColIds.current, colIds: colIdsEdited.current });
|
|
951
955
|
colIdsEdited.current.clear();
|
|
952
|
-
}, [autoSizeColumns,
|
|
956
|
+
}, [autoSizeColumns, (_c = params.rowData) === null || _c === void 0 ? void 0 : _c.length, setInitialContentSize, sizeColumns, updatedDep, updatingCols]);
|
|
953
957
|
/**
|
|
954
958
|
* Show/hide no rows overlay when model changes.
|
|
955
959
|
*/
|
|
@@ -1050,42 +1054,40 @@ var Grid = function (_a) {
|
|
|
1050
1054
|
* Set of colIds that need auto-sizing.
|
|
1051
1055
|
*/
|
|
1052
1056
|
var colIdsEdited = useRef(new Set());
|
|
1057
|
+
var lastUpdatedDep = useRef(updatedDep);
|
|
1053
1058
|
/**
|
|
1054
|
-
* When cell editing has completed
|
|
1059
|
+
* When cell editing has completed the colId as needing auto-sizing
|
|
1055
1060
|
*/
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1061
|
+
useEffect(function () {
|
|
1062
|
+
if (lastUpdatedDep.current === updatedDep)
|
|
1063
|
+
return;
|
|
1064
|
+
lastUpdatedDep.current = updatedDep;
|
|
1065
|
+
var colIds = updatingCols();
|
|
1066
|
+
// Updating possibly completed
|
|
1067
|
+
if (isEmpty(colIds)) {
|
|
1068
|
+
// Columns to resize?
|
|
1069
|
+
if (!isEmpty(colIdsEdited.current)) {
|
|
1070
|
+
var skipHeader = sizeColumns === "auto-skip-headers";
|
|
1071
|
+
if (sizeColumns === "auto" || skipHeader) {
|
|
1066
1072
|
autoSizeColumns({
|
|
1067
1073
|
skipHeader: skipHeader,
|
|
1068
1074
|
userSizedColIds: userSizedColIds.current,
|
|
1069
|
-
colIds:
|
|
1075
|
+
colIds: colIdsEdited.current
|
|
1070
1076
|
});
|
|
1077
|
+
}
|
|
1078
|
+
colIdsEdited.current.clear();
|
|
1071
1079
|
}
|
|
1072
1080
|
}
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
if (isUpdating())
|
|
1084
|
-
return;
|
|
1085
|
-
var skipHeader = sizeColumns === "auto-skip-headers";
|
|
1086
|
-
autoSizeColumns({ skipHeader: skipHeader, userSizedColIds: userSizedColIds.current, colIds: colIdsEdited.current });
|
|
1087
|
-
colIdsEdited.current.clear();
|
|
1088
|
-
}, [autoSizeColumns, updatedDep, sizeColumns, isUpdating]);
|
|
1081
|
+
else {
|
|
1082
|
+
// Updates not complete, add them to a list of columns needing resize
|
|
1083
|
+
colIds.forEach(function (colId) {
|
|
1084
|
+
var _a;
|
|
1085
|
+
if (colId && !((_a = getColDef(colId)) === null || _a === void 0 ? void 0 : _a.flex)) {
|
|
1086
|
+
colIdsEdited.current.add(colId);
|
|
1087
|
+
}
|
|
1088
|
+
});
|
|
1089
|
+
}
|
|
1090
|
+
}, [autoSizeColumns, getColDef, sizeColumns, updatedDep, updatingCols]);
|
|
1089
1091
|
/**
|
|
1090
1092
|
* Resize columns to fit if required on window/container resize
|
|
1091
1093
|
*/
|
|
@@ -1118,7 +1120,7 @@ var Grid = function (_a) {
|
|
|
1118
1120
|
setOnCellEditingComplete(params.onCellEditingComplete);
|
|
1119
1121
|
return (jsx("div", __assign({ "data-testid": dataTestId, className: clsx("Grid-container", theme, staleGrid && "Grid-sortIsStale", gridReady && params.rowData && "Grid-ready") }, { children: jsx("div", __assign({ style: { flex: 1 }, ref: gridDivRef }, { children: jsx(AgGridReact, { animateRows: params.animateRows, rowClassRules: params.rowClassRules, getRowId: function (params) { return "".concat(params.data.id); }, suppressRowClickSelection: true, rowSelection: rowSelection, suppressBrowserResizeObserver: true, onGridSizeChanged: onGridSizeChanged, suppressColumnVirtualisation: suppressColumnVirtualization, suppressClickEdit: true, onColumnVisible: function () {
|
|
1120
1122
|
setInitialContentSize();
|
|
1121
|
-
}, onRowDataChanged: onRowDataChanged, onCellKeyPress: onCellKeyPress, onCellClicked: onCellClicked, onCellDoubleClicked: onCellDoubleClick, onCellEditingStarted: refreshSelectedRows, domLayout: params.domLayout,
|
|
1123
|
+
}, 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: {
|
|
1122
1124
|
rowData: params.rowData,
|
|
1123
1125
|
noRowsOverlayText: params.noRowsOverlayText
|
|
1124
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 }) })) })));
|
|
@@ -4968,32 +4970,29 @@ var GridContextProvider = function (props) {
|
|
|
4968
4970
|
!((_a = nextColDef.cellEditorParams) === null || _a === void 0 ? void 0 : _a.preventAutoEdit) &&
|
|
4969
4971
|
!((_b = nextColDef.cellRendererParams) === null || _b === void 0 ? void 0 : _b.editAction));
|
|
4970
4972
|
};
|
|
4971
|
-
var foundEditableCell = false;
|
|
4972
4973
|
// Just in case I've missed something, we don't want the loop to hang everything
|
|
4973
|
-
var maxIterations = 50;
|
|
4974
|
-
|
|
4975
|
-
var postRow = null;
|
|
4976
|
-
do {
|
|
4977
|
-
preRow = gridApi.getFocusedCell();
|
|
4974
|
+
for (var maxIterations = 0; maxIterations < 50; maxIterations++) {
|
|
4975
|
+
var preRow = gridApi.getFocusedCell();
|
|
4978
4976
|
tabDirection === 1 ? gridApi.tabToNextCell() : gridApi.tabToPreviousCell();
|
|
4979
|
-
postRow = gridApi.getFocusedCell();
|
|
4980
|
-
|
|
4981
|
-
|
|
4982
|
-
|
|
4983
|
-
|
|
4984
|
-
|
|
4985
|
-
|
|
4986
|
-
|
|
4987
|
-
|
|
4988
|
-
|
|
4989
|
-
|
|
4990
|
-
|
|
4991
|
-
|
|
4992
|
-
|
|
4993
|
-
|
|
4977
|
+
var postRow = gridApi.getFocusedCell();
|
|
4978
|
+
if ((preRow === null || preRow === void 0 ? void 0 : preRow.rowIndex) !== (postRow === null || postRow === void 0 ? void 0 : postRow.rowIndex) || (preRow === null || preRow === void 0 ? void 0 : preRow.column) === (postRow === null || postRow === void 0 ? void 0 : postRow.column)) {
|
|
4979
|
+
// We didn't find an editable cell in the same row, or the cell column didn't change
|
|
4980
|
+
// implying it was start/end of grid
|
|
4981
|
+
break;
|
|
4982
|
+
}
|
|
4983
|
+
if (focusedCellIsEditable()) {
|
|
4984
|
+
var focusedCell = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getFocusedCell();
|
|
4985
|
+
if (focusedCell) {
|
|
4986
|
+
prePopupOps();
|
|
4987
|
+
gridApi.startEditingCell({
|
|
4988
|
+
rowIndex: focusedCell.rowIndex,
|
|
4989
|
+
colKey: focusedCell.column.getColId()
|
|
4990
|
+
});
|
|
4991
|
+
return true;
|
|
4992
|
+
}
|
|
4994
4993
|
}
|
|
4995
4994
|
}
|
|
4996
|
-
return
|
|
4995
|
+
return false;
|
|
4997
4996
|
}, [gridApi, prePopupOps]);
|
|
4998
4997
|
var updatingCells = useCallback(function (props, fnUpdate, setSaving, tabDirection) { return __awaiter(void 0, void 0, void 0, function () {
|
|
4999
4998
|
return __generator(this, function (_a) {
|
|
@@ -5045,7 +5044,7 @@ var GridContextProvider = function (props) {
|
|
|
5045
5044
|
postPopupFocusedCell &&
|
|
5046
5045
|
prePopupFocusedCell.current.rowIndex == postPopupFocusedCell.rowIndex &&
|
|
5047
5046
|
prePopupFocusedCell.current.column.getColId() == postPopupFocusedCell.column.getColId()) {
|
|
5048
|
-
if (!tabDirection || selectNextEditableCell(tabDirection)) {
|
|
5047
|
+
if (!tabDirection || !selectNextEditableCell(tabDirection)) {
|
|
5049
5048
|
cellEditingCompleteCallbackRef.current && cellEditingCompleteCallbackRef.current();
|
|
5050
5049
|
}
|
|
5051
5050
|
}
|
|
@@ -5104,6 +5103,7 @@ var GridContextProvider = function (props) {
|
|
|
5104
5103
|
var doesExternalFilterPass = function (node) {
|
|
5105
5104
|
return externalFilters.current.every(function (filter) { return filter(node.data, node); });
|
|
5106
5105
|
};
|
|
5106
|
+
var getColDef = useCallback(function (colId) { return (!!colId && (gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDef(colId))) || undefined; }, [gridApi]);
|
|
5107
5107
|
var getColumns = useCallback(function () { var _a; return (_a = gridApi === null || gridApi === void 0 ? void 0 : gridApi.getColumnDefs()) !== null && _a !== void 0 ? _a : []; }, [gridApi]);
|
|
5108
5108
|
useEffect(function () {
|
|
5109
5109
|
if (columnApi) {
|
|
@@ -5126,6 +5126,7 @@ var GridContextProvider = function (props) {
|
|
|
5126
5126
|
gridApi.exportDataAsCsv(__assign(__assign({ columnKeys: columnKeys, processCellCallback: downloadCsvUseValueFormattersProcessCellCallback }, csvExportParams), { fileName: fileName }));
|
|
5127
5127
|
}, [columnApi, gridApi]);
|
|
5128
5128
|
return (jsx(GridContext.Provider, __assign({ value: {
|
|
5129
|
+
getColDef: getColDef,
|
|
5129
5130
|
getColumns: getColumns,
|
|
5130
5131
|
invisibleColumnIds: invisibleColumnIds,
|
|
5131
5132
|
setInvisibleColumnIds: setInvisibleColumnIds,
|
|
@@ -5225,7 +5226,7 @@ var GridUpdatingContextProvider = function (props) {
|
|
|
5225
5226
|
updating.current = mergedUpdatingBlocks;
|
|
5226
5227
|
setUpdatedDep(function (updatedDep) { return updatedDep + 1; });
|
|
5227
5228
|
};
|
|
5228
|
-
var
|
|
5229
|
+
var updatingCols = function () { return Object.keys(updating.current); };
|
|
5229
5230
|
var modifyUpdating = function (fields, ids, fn) { return __awaiter(void 0, void 0, void 0, function () {
|
|
5230
5231
|
var idRef;
|
|
5231
5232
|
return __generator(this, function (_a) {
|
|
@@ -5253,7 +5254,7 @@ var GridUpdatingContextProvider = function (props) {
|
|
|
5253
5254
|
var checkUpdating = function (fields, id) {
|
|
5254
5255
|
return castArray(fields).some(function (f) { var _a; return (_a = updating.current[f]) === null || _a === void 0 ? void 0 : _a.includes(id); });
|
|
5255
5256
|
};
|
|
5256
|
-
return (jsx(GridUpdatingContext.Provider, __assign({ value: { modifyUpdating: modifyUpdating, checkUpdating: checkUpdating,
|
|
5257
|
+
return (jsx(GridUpdatingContext.Provider, __assign({ value: { modifyUpdating: modifyUpdating, checkUpdating: checkUpdating, updatingCols: updatingCols, updatedDep: updatedDep } }, { children: props.children })));
|
|
5257
5258
|
};
|
|
5258
5259
|
|
|
5259
5260
|
var css_248z = ".ActionButton{align-items:center;display:flex}.ActionButton-minimal.lui-button-lg.lui-button-icon-right{padding-right:38px}.ActionButton.lui-button-lg.lui-button-icon-right:not(.ActionButton-tight) .LuiIcon{margin:0 4px}.ActionButton.ActionButton-tight.lui-button-lg.lui-button-icon-right .LuiIcon{margin:0}.ActionButton-iconOnly.lui-button-lg.lui-button-icon-right:not(.ActionButton-tight){padding:8px 5px}.ActionButton-iconOnly.lui-button-lg.lui-button-icon-right.ActionButton-tight{padding:0}.ActionButton-minimalArea{position:relative}.ActionButton-minimalAreaDisplay{position:absolute}.ActionButton-minimalAreaExpand{visibility:hidden}.ActionButton-inProgress.lui-button-lg.lui-button-icon-right{background-color:#e2f3f7;color:#007198;cursor:progress}.ActionButton-inProgress.lui-button-lg.lui-button-icon-right svg *{fill:#0000}.ActionButton-fill{justify-content:center;width:100%}";
|