@linzjs/step-ag-grid 8.2.1 → 8.3.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/dist/src/contexts/GridContext.d.ts +1 -0
- package/dist/step-ag-grid.esm.js +69 -36
- package/dist/step-ag-grid.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/components/Grid.tsx +21 -9
- package/src/components/GridCell.tsx +2 -1
- package/src/components/gridForm/GridFormDropDown.tsx +20 -11
- package/src/components/gridPopoverEdit/GridPopoverMenu.tsx +2 -2
- package/src/contexts/GridContext.tsx +4 -0
- package/src/contexts/GridContextProvider.tsx +21 -8
- package/src/stories/grid/GridNonEditableRow.stories.tsx +1 -3
|
@@ -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[];
|
package/dist/step-ag-grid.esm.js
CHANGED
|
@@ -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 () {
|
|
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
|
|
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
|
-
|
|
2347
|
+
postPopupFocusedCell = gridApi.getFocusedCell();
|
|
2333
2348
|
if (tabDirection &&
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
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([]);
|
|
@@ -2824,6 +2840,20 @@ var Grid = function (params) {
|
|
|
2824
2840
|
useEffect(function () {
|
|
2825
2841
|
updateQuickFilter();
|
|
2826
2842
|
}, [updateQuickFilter]);
|
|
2843
|
+
var combineEditables = function () {
|
|
2844
|
+
var editables = [];
|
|
2845
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
2846
|
+
editables[_i] = arguments[_i];
|
|
2847
|
+
}
|
|
2848
|
+
return function (params) {
|
|
2849
|
+
var results = editables.map(function (editable) { return fnOrVar(editable, params); });
|
|
2850
|
+
// If editable is not set anywhere then it's non-editable
|
|
2851
|
+
if (results.every(function (v) { return v == null; }))
|
|
2852
|
+
return false;
|
|
2853
|
+
// If any editable value is or returns false then it's non-editable
|
|
2854
|
+
return !results.some(function (v) { return v == false; });
|
|
2855
|
+
};
|
|
2856
|
+
};
|
|
2827
2857
|
/**
|
|
2828
2858
|
* Synchronise externally selected items to grid on externalSelectedItems change
|
|
2829
2859
|
*/
|
|
@@ -2832,21 +2862,18 @@ var Grid = function (params) {
|
|
|
2832
2862
|
}, [synchroniseExternallySelectedItemsToGrid]);
|
|
2833
2863
|
var columnDefs = useMemo(function () {
|
|
2834
2864
|
var adjustColDefs = params.columnDefs.map(function (colDef) {
|
|
2835
|
-
var _a
|
|
2836
|
-
|
|
2837
|
-
|
|
2838
|
-
|
|
2839
|
-
!fnOrVar((_b = (_a = params.defaultColDef) === null || _a === void 0 ? void 0 : _a.editable) !== null && _b !== void 0 ? _b : colDef.editable, ccp);
|
|
2840
|
-
} }) });
|
|
2865
|
+
var _a;
|
|
2866
|
+
var colDefEditable = colDef.editable;
|
|
2867
|
+
var editable = combineEditables(params.readOnly !== false, (_a = params.defaultColDef) === null || _a === void 0 ? void 0 : _a.editable, colDefEditable);
|
|
2868
|
+
return __assign(__assign({}, colDef), { editable: editable, cellClassRules: __assign(__assign({}, colDef.cellClassRules), { "GridCell-readonly": function (ccp) { return !editable(ccp); } }) });
|
|
2841
2869
|
});
|
|
2842
2870
|
return params.selectable
|
|
2843
2871
|
? __spreadArray([
|
|
2844
2872
|
{
|
|
2845
2873
|
colId: "selection",
|
|
2846
2874
|
editable: false,
|
|
2847
|
-
|
|
2848
|
-
|
|
2849
|
-
maxWidth: 35,
|
|
2875
|
+
minWidth: 42,
|
|
2876
|
+
maxWidth: 42,
|
|
2850
2877
|
suppressSizeToFit: true,
|
|
2851
2878
|
checkboxSelection: true,
|
|
2852
2879
|
headerComponent: GridHeaderSelect,
|
|
@@ -2888,6 +2915,7 @@ var Grid = function (params) {
|
|
|
2888
2915
|
}, []);
|
|
2889
2916
|
var startCellEditing = useCallback(function (event) {
|
|
2890
2917
|
var _a;
|
|
2918
|
+
prePopupOps();
|
|
2891
2919
|
if (!event.node.isSelected()) {
|
|
2892
2920
|
event.node.setSelected(true, true);
|
|
2893
2921
|
}
|
|
@@ -2901,7 +2929,7 @@ var Grid = function (params) {
|
|
|
2901
2929
|
colKey: event.column.getColId()
|
|
2902
2930
|
});
|
|
2903
2931
|
}
|
|
2904
|
-
}, [checkUpdating]);
|
|
2932
|
+
}, [checkUpdating, prePopupOps]);
|
|
2905
2933
|
var onCellDoubleClick = useCallback(function (event) {
|
|
2906
2934
|
if (!invokeEditAction(event))
|
|
2907
2935
|
startCellEditing(event);
|
|
@@ -2990,13 +3018,13 @@ var suppressCellKeyboardEvents = function (e) {
|
|
|
2990
3018
|
return !["ArrowLeft", "ArrowRight", "ArrowDown", "ArrowUp", "Tab", " ", "Home", "End", "PageUp", "PageDown"].includes(e.event.key);
|
|
2991
3019
|
};
|
|
2992
3020
|
/*
|
|
2993
|
-
* All cells should use this
|
|
3021
|
+
* All cells should use this.
|
|
2994
3022
|
*/
|
|
2995
3023
|
var GridCell = function (props, custom) {
|
|
2996
|
-
var _a;
|
|
2997
|
-
return __assign(__assign(__assign(__assign(__assign(__assign({ colId: props.field, sortable: !!((props === null || props === void 0 ? void 0 : props.field) || (props === null || props === void 0 ? void 0 : props.valueGetter)), resizable: true }, ((custom === null || custom === void 0 ? void 0 : custom.editor) && {
|
|
3024
|
+
var _a, _b;
|
|
3025
|
+
return __assign(__assign(__assign(__assign(__assign(__assign({ colId: props.field, sortable: !!((props === null || props === void 0 ? void 0 : props.field) || (props === null || props === void 0 ? void 0 : props.valueGetter)), resizable: true, editable: (_a = props.editable) !== null && _a !== void 0 ? _a : false }, ((custom === null || custom === void 0 ? void 0 : custom.editor) && {
|
|
2998
3026
|
cellClassRules: GridCellMultiSelectClassRules,
|
|
2999
|
-
editable: (
|
|
3027
|
+
editable: (_b = props.editable) !== null && _b !== void 0 ? _b : true,
|
|
3000
3028
|
cellEditor: GenericCellEditorComponentWrapper(custom === null || custom === void 0 ? void 0 : custom.editor)
|
|
3001
3029
|
})), { suppressKeyboardEvent: suppressCellKeyboardEvents }), ((custom === null || custom === void 0 ? void 0 : custom.editorParams) && {
|
|
3002
3030
|
cellEditorParams: __assign(__assign({}, custom.editorParams), { multiEdit: custom.multiEdit })
|
|
@@ -3408,6 +3436,22 @@ var GridFormDropDown = function (props) {
|
|
|
3408
3436
|
}
|
|
3409
3437
|
});
|
|
3410
3438
|
}); }, [filter, filteredValues, options, props, selectItemHandler, selectedItem, selectedRows, subSelectedValue]);
|
|
3439
|
+
var onMouseEnterFocus = useCallback(function (item) {
|
|
3440
|
+
setSelectedItem(item);
|
|
3441
|
+
if (item.subComponent) {
|
|
3442
|
+
subComponentIsValid.current = true;
|
|
3443
|
+
subComponentInitialValue.current = null;
|
|
3444
|
+
}
|
|
3445
|
+
else {
|
|
3446
|
+
setSubSelectedValue(null);
|
|
3447
|
+
subComponentIsValid.current = true;
|
|
3448
|
+
}
|
|
3449
|
+
}, []);
|
|
3450
|
+
var onMouseLeaveFocus = useCallback(function () {
|
|
3451
|
+
setSelectedItem(null);
|
|
3452
|
+
setSubSelectedValue(null);
|
|
3453
|
+
subComponentIsValid.current = true;
|
|
3454
|
+
}, []);
|
|
3411
3455
|
var popoverWrapper = useGridPopoverHook({
|
|
3412
3456
|
className: props.className,
|
|
3413
3457
|
invalid: function () { return !!(selectedItem && !subComponentIsValid.current); },
|
|
@@ -3440,18 +3484,7 @@ var GridFormDropDown = function (props) {
|
|
|
3440
3484
|
lastHeader = null;
|
|
3441
3485
|
}
|
|
3442
3486
|
}
|
|
3443
|
-
return ((!filteredValues || filteredValues.includes(item)) && (jsxs(Fragment$1, { children: [showHeader, jsxs("div", { children: [jsxs(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onFocus: function () {
|
|
3444
|
-
setSelectedItem(item);
|
|
3445
|
-
if (item.subComponent) {
|
|
3446
|
-
setSelectedItem(item);
|
|
3447
|
-
subComponentIsValid.current = true;
|
|
3448
|
-
subComponentInitialValue.current = null;
|
|
3449
|
-
}
|
|
3450
|
-
else {
|
|
3451
|
-
setSubSelectedValue(null);
|
|
3452
|
-
subComponentIsValid.current = true;
|
|
3453
|
-
}
|
|
3454
|
-
}, onClick: function (e) {
|
|
3487
|
+
return ((!filteredValues || filteredValues.includes(item)) && (jsxs(Fragment$1, { children: [showHeader, jsxs("div", { children: [jsxs(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onFocus: function () { return onMouseEnterFocus(item); }, onMouseEnter: function () { return onMouseEnterFocus(item); }, onMouseLeave: onMouseLeaveFocus, onClick: function (e) {
|
|
3455
3488
|
if (item.subComponent) {
|
|
3456
3489
|
e.keepOpen = true;
|
|
3457
3490
|
}
|
|
@@ -4006,7 +4039,7 @@ var GridFormPopoverMenu = function (props) {
|
|
|
4006
4039
|
* Popout burger menu
|
|
4007
4040
|
*/
|
|
4008
4041
|
var GridPopoverMenu = function (colDef, custom) {
|
|
4009
|
-
return GridCell(__assign(__assign({ minWidth:
|
|
4042
|
+
return GridCell(__assign(__assign({ minWidth: 48, maxWidth: 48, width: 40, editable: colDef.editable != null ? colDef.editable : true, cellStyle: { justifyContent: "center" }, cellRenderer: GridRenderPopoutMenuCell }, colDef), { cellRendererParams: {
|
|
4010
4043
|
// Menus open on single click, this parameter is picked up in Grid.tsx
|
|
4011
4044
|
singleClickEdit: true
|
|
4012
4045
|
} }), __assign({ editor: GridFormPopoverMenu }, custom));
|