@mui/x-data-grid 6.0.0-alpha.2 → 6.0.0-alpha.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/CHANGELOG.md +231 -12
- package/DataGrid/DataGrid.js +0 -20
- package/DataGrid/useDataGridComponent.js +2 -6
- package/colDef/gridNumericOperators.d.ts +1 -1
- package/colDef/gridSingleSelectOperators.d.ts +1 -1
- package/colDef/gridStringOperators.d.ts +1 -1
- package/components/cell/GridEditInputCell.js +3 -8
- package/components/cell/GridEditSingleSelectCell.js +6 -38
- package/components/panel/filterPanel/GridFilterForm.d.ts +12 -0
- package/components/panel/filterPanel/GridFilterForm.js +29 -7
- package/components/panel/filterPanel/GridFilterPanel.d.ts +12 -0
- package/components/panel/filterPanel/GridFilterPanel.js +64 -19
- package/hooks/core/pipeProcessing/useGridRegisterPipeApplier.d.ts +1 -1
- package/hooks/core/pipeProcessing/useGridRegisterPipeProcessor.d.ts +1 -1
- package/hooks/core/strategyProcessing/useGridRegisterStrategyProcessor.d.ts +1 -1
- package/hooks/core/useGridInitialization.d.ts +1 -1
- package/hooks/core/useGridStateInitialization.d.ts +1 -1
- package/hooks/features/columnHeaders/useGridColumnHeaders.d.ts +1 -1
- package/hooks/features/{editRows/gridEditRowsSelector.d.ts → editing/gridEditingSelectors.d.ts} +0 -0
- package/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/hooks/features/editing/index.d.ts +1 -0
- package/hooks/features/editing/index.js +1 -0
- package/hooks/features/{editRows/useGridCellEditing.new.d.ts → editing/useGridCellEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/hooks/features/{editRows/useGridEditing.new.d.ts → editing/useGridEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/hooks/features/{editRows/useGridRowEditing.new.d.ts → editing/useGridRowEditing.d.ts} +0 -0
- package/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/hooks/features/index.d.ts +1 -1
- package/hooks/features/index.js +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.d.ts +1 -1
- package/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
- package/hooks/utils/useGridApi.d.ts +1 -1
- package/hooks/utils/useGridApiEventHandler.d.ts +2 -2
- package/hooks/utils/useGridApiRef.d.ts +1 -1
- package/hooks/utils/useGridInitializeState.d.ts +1 -1
- package/hooks/utils/useGridNativeEventListener.d.ts +1 -1
- package/hooks/utils/useGridSelector.d.ts +1 -1
- package/hooks/utils/useGridState.d.ts +1 -1
- package/hooks/utils/useGridVisibleRows.d.ts +2 -2
- package/index.js +1 -1
- package/internals/index.d.ts +1 -2
- package/internals/index.js +1 -2
- package/legacy/DataGrid/DataGrid.js +0 -20
- package/legacy/DataGrid/useDataGridComponent.js +2 -6
- package/legacy/components/cell/GridEditInputCell.js +3 -8
- package/legacy/components/cell/GridEditSingleSelectCell.js +6 -52
- package/legacy/components/panel/filterPanel/GridFilterForm.js +31 -7
- package/legacy/components/panel/filterPanel/GridFilterPanel.js +67 -18
- package/legacy/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/legacy/hooks/features/editing/index.js +1 -0
- package/legacy/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/legacy/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/legacy/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/legacy/hooks/features/index.js +1 -1
- package/legacy/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
- package/legacy/index.js +1 -1
- package/legacy/internals/index.js +1 -2
- package/legacy/models/params/gridEditCellParams.js +0 -4
- package/models/api/gridApiCommon.d.ts +2 -5
- package/models/api/gridApiCommunity.d.ts +1 -7
- package/models/api/gridEditingApi.d.ts +36 -121
- package/models/api/index.d.ts +1 -1
- package/models/events/gridEventLookup.d.ts +1 -15
- package/models/params/gridEditCellParams.d.ts +4 -17
- package/models/params/gridEditCellParams.js +0 -4
- package/models/params/gridRowParams.d.ts +4 -4
- package/models/props/DataGridProps.d.ts +0 -24
- package/modern/DataGrid/DataGrid.js +0 -20
- package/modern/DataGrid/useDataGridComponent.js +2 -4
- package/modern/components/cell/GridEditInputCell.js +3 -4
- package/modern/components/cell/GridEditSingleSelectCell.js +6 -34
- package/modern/components/panel/filterPanel/GridFilterForm.js +29 -7
- package/modern/components/panel/filterPanel/GridFilterPanel.js +62 -17
- package/modern/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/modern/hooks/features/editing/index.js +1 -0
- package/modern/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +21 -6
- package/modern/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +3 -3
- package/modern/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +20 -6
- package/modern/hooks/features/index.js +1 -1
- package/modern/hooks/features/virtualization/useGridVirtualScroller.js +1 -1
- package/modern/index.js +1 -1
- package/modern/internals/index.js +1 -2
- package/modern/models/params/gridEditCellParams.js +0 -4
- package/node/DataGrid/DataGrid.js +0 -20
- package/node/DataGrid/useDataGridComponent.js +3 -8
- package/node/components/cell/GridEditInputCell.js +3 -9
- package/node/components/cell/GridEditSingleSelectCell.js +6 -38
- package/node/components/panel/filterPanel/GridFilterForm.js +30 -7
- package/node/components/panel/filterPanel/GridFilterPanel.js +63 -19
- package/node/hooks/features/{editRows/gridEditRowsSelector.js → editing/gridEditingSelectors.js} +0 -0
- package/node/hooks/features/{editRows → editing}/index.js +4 -4
- package/node/hooks/features/{editRows/useGridCellEditing.new.js → editing/useGridCellEditing.js} +28 -13
- package/node/hooks/features/{editRows/useGridEditing.new.js → editing/useGridEditing.js} +4 -4
- package/node/hooks/features/{editRows/useGridRowEditing.new.js → editing/useGridRowEditing.js} +28 -14
- package/node/hooks/features/index.js +4 -4
- package/node/hooks/features/virtualization/useGridVirtualScroller.js +2 -2
- package/node/index.js +1 -1
- package/node/internals/index.js +3 -17
- package/node/models/params/gridEditCellParams.js +0 -3
- package/package.json +2 -2
- package/hooks/features/editRows/index.d.ts +0 -1
- package/hooks/features/editRows/index.js +0 -1
- package/hooks/features/editRows/useGridCellEditing.old.d.ts +0 -4
- package/hooks/features/editRows/useGridCellEditing.old.js +0 -359
- package/hooks/features/editRows/useGridEditing.old.d.ts +0 -11
- package/hooks/features/editRows/useGridEditing.old.js +0 -167
- package/hooks/features/editRows/useGridRowEditing.old.d.ts +0 -4
- package/hooks/features/editRows/useGridRowEditing.old.js +0 -334
- package/legacy/hooks/features/editRows/index.js +0 -1
- package/legacy/hooks/features/editRows/useGridCellEditing.old.js +0 -411
- package/legacy/hooks/features/editRows/useGridEditing.old.js +0 -184
- package/legacy/hooks/features/editRows/useGridRowEditing.old.js +0 -505
- package/modern/hooks/features/editRows/index.js +0 -1
- package/modern/hooks/features/editRows/useGridCellEditing.old.js +0 -355
- package/modern/hooks/features/editRows/useGridEditing.old.js +0 -163
- package/modern/hooks/features/editRows/useGridRowEditing.old.js +0 -326
- package/node/hooks/features/editRows/useGridCellEditing.old.js +0 -380
- package/node/hooks/features/editRows/useGridEditing.old.js +0 -193
- package/node/hooks/features/editRows/useGridRowEditing.old.js +0 -358
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.editingStateInitializer = void 0;
|
|
9
|
-
exports.useGridEditing = useGridEditing;
|
|
10
|
-
|
|
11
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
12
|
-
|
|
13
|
-
var React = _interopRequireWildcard(require("react"));
|
|
14
|
-
|
|
15
|
-
var _gridEditRowModel = require("../../../models/gridEditRowModel");
|
|
16
|
-
|
|
17
|
-
var _useGridApiEventHandler = require("../../utils/useGridApiEventHandler");
|
|
18
|
-
|
|
19
|
-
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
20
|
-
|
|
21
|
-
var _useGridLogger = require("../../utils/useGridLogger");
|
|
22
|
-
|
|
23
|
-
var _gridEditRowsSelector = require("./gridEditRowsSelector");
|
|
24
|
-
|
|
25
|
-
var _useGridCellEditing = require("./useGridCellEditing.old");
|
|
26
|
-
|
|
27
|
-
var _useGridRowEditing = require("./useGridRowEditing.old");
|
|
28
|
-
|
|
29
|
-
var _gridRowsUtils = require("../rows/gridRowsUtils");
|
|
30
|
-
|
|
31
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
32
|
-
|
|
33
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
34
|
-
|
|
35
|
-
const editingStateInitializer = state => (0, _extends2.default)({}, state, {
|
|
36
|
-
editRows: {}
|
|
37
|
-
});
|
|
38
|
-
/**
|
|
39
|
-
* @requires useGridFocus - can be after, async only
|
|
40
|
-
* @requires useGridParamsApi (method)
|
|
41
|
-
* @requires useGridColumns (state)
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
exports.editingStateInitializer = editingStateInitializer;
|
|
46
|
-
|
|
47
|
-
function useGridEditing(apiRef, props) {
|
|
48
|
-
var _props$experimentalFe2;
|
|
49
|
-
|
|
50
|
-
const logger = (0, _useGridLogger.useGridLogger)(apiRef, 'useGridEditRows');
|
|
51
|
-
(0, _useGridCellEditing.useCellEditing)(apiRef, props);
|
|
52
|
-
(0, _useGridRowEditing.useGridRowEditing)(apiRef, props);
|
|
53
|
-
const debounceMap = React.useRef({});
|
|
54
|
-
apiRef.current.unstable_registerControlState({
|
|
55
|
-
stateId: 'editRows',
|
|
56
|
-
propModel: props.editRowsModel,
|
|
57
|
-
propOnChange: props.onEditRowsModelChange,
|
|
58
|
-
stateSelector: _gridEditRowsSelector.gridEditRowsStateSelector,
|
|
59
|
-
changeEvent: 'editRowsModelChange'
|
|
60
|
-
});
|
|
61
|
-
const isCellEditable = React.useCallback(params => !(0, _gridRowsUtils.isAutoGeneratedRow)(params.rowNode) && params.rowNode.type !== 'pinnedRow' && !!params.colDef.editable && !!params.colDef.renderEditCell && (!props.isCellEditable || props.isCellEditable(params)), // eslint-disable-next-line react-hooks/exhaustive-deps
|
|
62
|
-
[props.isCellEditable]);
|
|
63
|
-
|
|
64
|
-
const maybeDebounce = (id, field, debounceMs, callback) => {
|
|
65
|
-
if (!debounceMs) {
|
|
66
|
-
callback();
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (!debounceMap.current[id]) {
|
|
71
|
-
debounceMap.current[id] = {};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
if (debounceMap.current[id][field]) {
|
|
75
|
-
const [timeout] = debounceMap.current[id][field];
|
|
76
|
-
clearTimeout(timeout);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const callbackToRunImmediately = () => {
|
|
80
|
-
callback();
|
|
81
|
-
const [timeout] = debounceMap.current[id][field];
|
|
82
|
-
clearTimeout(timeout);
|
|
83
|
-
delete debounceMap.current[id][field];
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
const timeout = setTimeout(() => {
|
|
87
|
-
callback();
|
|
88
|
-
delete debounceMap.current[id][field];
|
|
89
|
-
}, debounceMs);
|
|
90
|
-
debounceMap.current[id][field] = [timeout, callbackToRunImmediately];
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
const runPendingEditCellValueMutation = React.useCallback((id, field) => {
|
|
94
|
-
if (!debounceMap.current[id]) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
if (!field) {
|
|
99
|
-
Object.keys(debounceMap.current[id]).forEach(debouncedField => {
|
|
100
|
-
const [, callback] = debounceMap.current[id][debouncedField];
|
|
101
|
-
callback();
|
|
102
|
-
});
|
|
103
|
-
} else if (debounceMap.current[id][field]) {
|
|
104
|
-
const [, callback] = debounceMap.current[id][field];
|
|
105
|
-
callback();
|
|
106
|
-
}
|
|
107
|
-
}, []);
|
|
108
|
-
const setEditCellValue = React.useCallback((params, event = {}) => {
|
|
109
|
-
maybeDebounce(params.id, params.field, params.debounceMs, () => {
|
|
110
|
-
var _props$experimentalFe;
|
|
111
|
-
|
|
112
|
-
if ((_props$experimentalFe = props.experimentalFeatures) != null && _props$experimentalFe.preventCommitWhileValidating) {
|
|
113
|
-
if (props.editMode === 'row') {
|
|
114
|
-
return apiRef.current.unstable_setRowEditingEditCellValue(params);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
return apiRef.current.unstable_setCellEditingEditCellValue(params);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const newParams = {
|
|
121
|
-
id: params.id,
|
|
122
|
-
field: params.field,
|
|
123
|
-
props: {
|
|
124
|
-
value: params.value
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
return apiRef.current.publishEvent('editCellPropsChange', newParams, event);
|
|
128
|
-
});
|
|
129
|
-
}, [apiRef, props.editMode, (_props$experimentalFe2 = props.experimentalFeatures) == null ? void 0 : _props$experimentalFe2.preventCommitWhileValidating]);
|
|
130
|
-
const parseValue = React.useCallback((id, field, value) => {
|
|
131
|
-
const column = apiRef.current.getColumn(field);
|
|
132
|
-
return column.valueParser ? column.valueParser(value, apiRef.current.getCellParams(id, field)) : value;
|
|
133
|
-
}, [apiRef]);
|
|
134
|
-
const setEditCellProps = React.useCallback(params => {
|
|
135
|
-
const {
|
|
136
|
-
id,
|
|
137
|
-
field,
|
|
138
|
-
props: editProps
|
|
139
|
-
} = params;
|
|
140
|
-
logger.debug(`Setting cell props on id: ${id} field: ${field}`);
|
|
141
|
-
apiRef.current.setState(state => {
|
|
142
|
-
const editRowsModel = (0, _extends2.default)({}, state.editRows);
|
|
143
|
-
editRowsModel[id] = (0, _extends2.default)({}, state.editRows[id]);
|
|
144
|
-
editRowsModel[id][field] = (0, _extends2.default)({}, editProps, {
|
|
145
|
-
value: parseValue(id, field, editProps.value)
|
|
146
|
-
});
|
|
147
|
-
return (0, _extends2.default)({}, state, {
|
|
148
|
-
editRows: editRowsModel
|
|
149
|
-
});
|
|
150
|
-
});
|
|
151
|
-
apiRef.current.forceUpdate();
|
|
152
|
-
const editRowsState = (0, _gridEditRowsSelector.gridEditRowsStateSelector)(apiRef.current.state);
|
|
153
|
-
return editRowsState[id][field];
|
|
154
|
-
}, [apiRef, logger, parseValue]);
|
|
155
|
-
const setEditRowsModel = React.useCallback(model => {
|
|
156
|
-
const currentModel = (0, _gridEditRowsSelector.gridEditRowsStateSelector)(apiRef.current.state);
|
|
157
|
-
|
|
158
|
-
if (currentModel !== model) {
|
|
159
|
-
logger.debug(`Setting editRows model`);
|
|
160
|
-
apiRef.current.setState(state => (0, _extends2.default)({}, state, {
|
|
161
|
-
editRows: model
|
|
162
|
-
}));
|
|
163
|
-
apiRef.current.forceUpdate();
|
|
164
|
-
}
|
|
165
|
-
}, [apiRef, logger]);
|
|
166
|
-
const getEditRowsModel = React.useCallback(() => (0, _gridEditRowsSelector.gridEditRowsStateSelector)(apiRef.current.state), [apiRef]);
|
|
167
|
-
const preventTextSelection = React.useCallback((params, event) => {
|
|
168
|
-
const isMoreThanOneClick = event.detail > 1;
|
|
169
|
-
|
|
170
|
-
if (params.isEditable && params.cellMode === _gridEditRowModel.GridCellModes.View && isMoreThanOneClick) {
|
|
171
|
-
// If we click more than one time, then we prevent the default behavior of selecting the text cell.
|
|
172
|
-
event.preventDefault();
|
|
173
|
-
}
|
|
174
|
-
}, []);
|
|
175
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellMouseDown', preventTextSelection);
|
|
176
|
-
(0, _useGridApiEventHandler.useGridApiOptionHandler)(apiRef, 'editCellPropsChange', props.onEditCellPropsChange); // TODO v6: remove, use `preProcessEditCellProps` instead
|
|
177
|
-
|
|
178
|
-
const editingSharedApi = {
|
|
179
|
-
isCellEditable,
|
|
180
|
-
setEditRowsModel,
|
|
181
|
-
getEditRowsModel,
|
|
182
|
-
setEditCellValue,
|
|
183
|
-
unstable_setEditCellProps: setEditCellProps,
|
|
184
|
-
unstable_parseValue: parseValue,
|
|
185
|
-
unstable_runPendingEditCellValueMutation: runPendingEditCellValueMutation
|
|
186
|
-
};
|
|
187
|
-
(0, _useGridApiMethod.useGridApiMethod)(apiRef, editingSharedApi, 'EditRowApi');
|
|
188
|
-
React.useEffect(() => {
|
|
189
|
-
if (props.editRowsModel !== undefined) {
|
|
190
|
-
apiRef.current.setEditRowsModel(props.editRowsModel);
|
|
191
|
-
}
|
|
192
|
-
}, [apiRef, props.editRowsModel]);
|
|
193
|
-
}
|
|
@@ -1,358 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.useGridRowEditing = void 0;
|
|
9
|
-
|
|
10
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
11
|
-
|
|
12
|
-
var React = _interopRequireWildcard(require("react"));
|
|
13
|
-
|
|
14
|
-
var _utils = require("@mui/material/utils");
|
|
15
|
-
|
|
16
|
-
var _useGridApiMethod = require("../../utils/useGridApiMethod");
|
|
17
|
-
|
|
18
|
-
var _gridEditRowModel = require("../../../models/gridEditRowModel");
|
|
19
|
-
|
|
20
|
-
var _useGridSelector = require("../../utils/useGridSelector");
|
|
21
|
-
|
|
22
|
-
var _gridColumnsSelector = require("../columns/gridColumnsSelector");
|
|
23
|
-
|
|
24
|
-
var _gridEditRowsSelector = require("./gridEditRowsSelector");
|
|
25
|
-
|
|
26
|
-
var _gridFocusStateSelector = require("../focus/gridFocusStateSelector");
|
|
27
|
-
|
|
28
|
-
var _useGridApiEventHandler = require("../../utils/useGridApiEventHandler");
|
|
29
|
-
|
|
30
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
31
|
-
|
|
32
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
33
|
-
|
|
34
|
-
const useGridRowEditing = (apiRef, props) => {
|
|
35
|
-
var _props$experimentalFe2, _props$experimentalFe4;
|
|
36
|
-
|
|
37
|
-
const focusTimeout = React.useRef(null);
|
|
38
|
-
const nextFocusedCell = React.useRef(null);
|
|
39
|
-
const columns = (0, _useGridSelector.useGridSelector)(apiRef, _gridColumnsSelector.gridColumnDefinitionsSelector);
|
|
40
|
-
|
|
41
|
-
const buildCallback = callback => (...args) => {
|
|
42
|
-
if (props.editMode === _gridEditRowModel.GridEditModes.Row) {
|
|
43
|
-
callback(...args);
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const setRowMode = React.useCallback((id, mode) => {
|
|
48
|
-
if (mode === apiRef.current.getRowMode(id)) {
|
|
49
|
-
return;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
apiRef.current.setState(state => {
|
|
53
|
-
const newEditRowsState = (0, _extends2.default)({}, state.editRows);
|
|
54
|
-
|
|
55
|
-
if (mode === _gridEditRowModel.GridRowModes.Edit) {
|
|
56
|
-
newEditRowsState[id] = {};
|
|
57
|
-
columns.forEach(column => {
|
|
58
|
-
const cellParams = apiRef.current.getCellParams(id, column.field);
|
|
59
|
-
|
|
60
|
-
if (cellParams.isEditable) {
|
|
61
|
-
newEditRowsState[id][column.field] = {
|
|
62
|
-
value: cellParams.value
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
} else {
|
|
67
|
-
delete newEditRowsState[id];
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return (0, _extends2.default)({}, state, {
|
|
71
|
-
editRows: newEditRowsState
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
apiRef.current.forceUpdate();
|
|
75
|
-
}, [apiRef, columns]);
|
|
76
|
-
const getRowMode = React.useCallback(id => {
|
|
77
|
-
if (props.editMode === _gridEditRowModel.GridEditModes.Cell) {
|
|
78
|
-
return _gridEditRowModel.GridRowModes.View;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
const editRowsState = (0, _gridEditRowsSelector.gridEditRowsStateSelector)(apiRef.current.state);
|
|
82
|
-
return editRowsState[id] ? _gridEditRowModel.GridRowModes.Edit : _gridEditRowModel.GridRowModes.View;
|
|
83
|
-
}, [apiRef, props.editMode]);
|
|
84
|
-
const commitRowChange = React.useCallback((id, event = {}) => {
|
|
85
|
-
var _props$experimentalFe;
|
|
86
|
-
|
|
87
|
-
if (props.editMode === _gridEditRowModel.GridEditModes.Cell) {
|
|
88
|
-
throw new Error(`MUI: You can't commit changes when the edit mode is 'cell'.`);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
apiRef.current.unstable_runPendingEditCellValueMutation(id);
|
|
92
|
-
const model = apiRef.current.getEditRowsModel();
|
|
93
|
-
const editRowProps = model[id];
|
|
94
|
-
|
|
95
|
-
if (!editRowProps) {
|
|
96
|
-
throw new Error(`MUI: Row at id: ${id} is not being edited.`);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if ((_props$experimentalFe = props.experimentalFeatures) != null && _props$experimentalFe.preventCommitWhileValidating) {
|
|
100
|
-
const isValid = Object.keys(editRowProps).reduce((acc, field) => {
|
|
101
|
-
return acc && !editRowProps[field].isValidating && !editRowProps[field].error;
|
|
102
|
-
}, true);
|
|
103
|
-
|
|
104
|
-
if (!isValid) {
|
|
105
|
-
return false;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
const hasFieldWithError = Object.values(editRowProps).some(value => !!value.error);
|
|
110
|
-
|
|
111
|
-
if (hasFieldWithError) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
const fieldsWithValidator = Object.keys(editRowProps).filter(field => {
|
|
116
|
-
const column = apiRef.current.getColumn(field);
|
|
117
|
-
return typeof column.preProcessEditCellProps === 'function';
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
if (fieldsWithValidator.length > 0) {
|
|
121
|
-
const row = apiRef.current.getRow(id);
|
|
122
|
-
const validatorErrors = fieldsWithValidator.map(async field => {
|
|
123
|
-
const column = apiRef.current.getColumn(field);
|
|
124
|
-
const newEditCellProps = await Promise.resolve(column.preProcessEditCellProps({
|
|
125
|
-
id,
|
|
126
|
-
row,
|
|
127
|
-
props: editRowProps[field]
|
|
128
|
-
}));
|
|
129
|
-
apiRef.current.unstable_setEditCellProps({
|
|
130
|
-
id,
|
|
131
|
-
field,
|
|
132
|
-
props: newEditCellProps
|
|
133
|
-
});
|
|
134
|
-
return newEditCellProps.error;
|
|
135
|
-
});
|
|
136
|
-
return Promise.all(validatorErrors).then(errors => {
|
|
137
|
-
if (errors.some(error => !!error)) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
apiRef.current.publishEvent('rowEditCommit', id, event);
|
|
142
|
-
return true;
|
|
143
|
-
});
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
apiRef.current.publishEvent('rowEditCommit', id, event);
|
|
147
|
-
return true;
|
|
148
|
-
}, [apiRef, props.editMode, (_props$experimentalFe2 = props.experimentalFeatures) == null ? void 0 : _props$experimentalFe2.preventCommitWhileValidating]);
|
|
149
|
-
const setRowEditingEditCellValue = React.useCallback(params => {
|
|
150
|
-
const model = apiRef.current.getEditRowsModel();
|
|
151
|
-
const editRow = model[params.id];
|
|
152
|
-
const row = apiRef.current.getRow(params.id);
|
|
153
|
-
let isValid = true;
|
|
154
|
-
return new Promise(resolve => {
|
|
155
|
-
Object.keys(editRow).forEach(async field => {
|
|
156
|
-
const column = apiRef.current.getColumn(field);
|
|
157
|
-
let editCellProps = field === params.field ? {
|
|
158
|
-
value: params.value
|
|
159
|
-
} : editRow[field]; // setEditCellProps runs the value parser and returns the updated props
|
|
160
|
-
|
|
161
|
-
editCellProps = apiRef.current.unstable_setEditCellProps({
|
|
162
|
-
id: params.id,
|
|
163
|
-
field,
|
|
164
|
-
props: (0, _extends2.default)({}, editCellProps, {
|
|
165
|
-
isValidating: true
|
|
166
|
-
})
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
if (column.preProcessEditCellProps) {
|
|
170
|
-
editCellProps = await Promise.resolve(column.preProcessEditCellProps({
|
|
171
|
-
id: params.id,
|
|
172
|
-
row,
|
|
173
|
-
props: (0, _extends2.default)({}, editCellProps, {
|
|
174
|
-
value: field === params.field ? apiRef.current.unstable_parseValue(params.id, field, params.value) : editCellProps.value
|
|
175
|
-
})
|
|
176
|
-
}));
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (editCellProps.error) {
|
|
180
|
-
isValid = false;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
apiRef.current.unstable_setEditCellProps({
|
|
184
|
-
id: params.id,
|
|
185
|
-
field,
|
|
186
|
-
props: (0, _extends2.default)({}, editCellProps, {
|
|
187
|
-
isValidating: false
|
|
188
|
-
})
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
resolve(isValid);
|
|
192
|
-
});
|
|
193
|
-
}, [apiRef]);
|
|
194
|
-
const rowEditingApi = {
|
|
195
|
-
setRowMode,
|
|
196
|
-
getRowMode,
|
|
197
|
-
commitRowChange,
|
|
198
|
-
unstable_setRowEditingEditCellValue: setRowEditingEditCellValue
|
|
199
|
-
};
|
|
200
|
-
(0, _useGridApiMethod.useGridApiMethod)(apiRef, rowEditingApi, 'EditRowApi');
|
|
201
|
-
const handleCellKeyDown = React.useCallback(async (params, event) => {
|
|
202
|
-
// Wait until IME is settled for Asian languages like Japanese and Chinese
|
|
203
|
-
// TODO: `event.which` is depricated but this is a temporary workaround
|
|
204
|
-
if (event.which === 229) {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
const {
|
|
209
|
-
cellMode,
|
|
210
|
-
isEditable
|
|
211
|
-
} = params;
|
|
212
|
-
|
|
213
|
-
if (!isEditable) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const isEditMode = cellMode === _gridEditRowModel.GridCellModes.Edit;
|
|
218
|
-
const rowParams = apiRef.current.getRowParams(params.id);
|
|
219
|
-
|
|
220
|
-
if (isEditMode) {
|
|
221
|
-
if (event.key === 'Enter') {
|
|
222
|
-
var _props$experimentalFe3;
|
|
223
|
-
|
|
224
|
-
// TODO: check the return before firing 'rowEditStop'
|
|
225
|
-
// On cell editing, it won't exits the edit mode with error
|
|
226
|
-
const isValid = await apiRef.current.commitRowChange(params.id);
|
|
227
|
-
|
|
228
|
-
if (!isValid && (_props$experimentalFe3 = props.experimentalFeatures) != null && _props$experimentalFe3.preventCommitWhileValidating) {
|
|
229
|
-
return;
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
apiRef.current.publishEvent('rowEditStop', rowParams, event);
|
|
233
|
-
} else if (event.key === 'Escape') {
|
|
234
|
-
apiRef.current.publishEvent('rowEditStop', rowParams, event);
|
|
235
|
-
}
|
|
236
|
-
} else if (event.key === 'Enter') {
|
|
237
|
-
apiRef.current.publishEvent('rowEditStart', rowParams, event);
|
|
238
|
-
}
|
|
239
|
-
}, [apiRef, (_props$experimentalFe4 = props.experimentalFeatures) == null ? void 0 : _props$experimentalFe4.preventCommitWhileValidating]);
|
|
240
|
-
const handleCellDoubleClick = React.useCallback((params, event) => {
|
|
241
|
-
if (!params.isEditable) {
|
|
242
|
-
return;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
const rowParams = apiRef.current.getRowParams(params.id);
|
|
246
|
-
apiRef.current.publishEvent('rowEditStart', rowParams, event);
|
|
247
|
-
}, [apiRef]);
|
|
248
|
-
const handleEditCellPropsChange = React.useCallback(params => {
|
|
249
|
-
const row = apiRef.current.getRow(params.id);
|
|
250
|
-
const model = apiRef.current.getEditRowsModel();
|
|
251
|
-
const editRow = model[params.id];
|
|
252
|
-
Object.keys(editRow).forEach(async field => {
|
|
253
|
-
const column = apiRef.current.getColumn(field);
|
|
254
|
-
|
|
255
|
-
if (column.preProcessEditCellProps) {
|
|
256
|
-
const editCellProps = field === params.field ? params.props : editRow[field];
|
|
257
|
-
const newEditCellProps = await Promise.resolve(column.preProcessEditCellProps({
|
|
258
|
-
id: params.id,
|
|
259
|
-
row,
|
|
260
|
-
props: editCellProps
|
|
261
|
-
}));
|
|
262
|
-
apiRef.current.unstable_setEditCellProps({
|
|
263
|
-
id: params.id,
|
|
264
|
-
field,
|
|
265
|
-
props: newEditCellProps
|
|
266
|
-
});
|
|
267
|
-
} else if (field === params.field) {
|
|
268
|
-
apiRef.current.unstable_setEditCellProps(params);
|
|
269
|
-
}
|
|
270
|
-
});
|
|
271
|
-
}, [apiRef]);
|
|
272
|
-
const handleRowEditStart = React.useCallback(params => {
|
|
273
|
-
apiRef.current.setRowMode(params.id, _gridEditRowModel.GridRowModes.Edit);
|
|
274
|
-
}, [apiRef]);
|
|
275
|
-
const handleRowEditStop = React.useCallback((params, event) => {
|
|
276
|
-
apiRef.current.setRowMode(params.id, _gridEditRowModel.GridRowModes.View);
|
|
277
|
-
|
|
278
|
-
if (event.key === 'Enter') {
|
|
279
|
-
apiRef.current.publishEvent('cellNavigationKeyDown', params, event);
|
|
280
|
-
}
|
|
281
|
-
}, [apiRef]);
|
|
282
|
-
const handleRowEditCommit = React.useCallback(id => {
|
|
283
|
-
const model = apiRef.current.getEditRowsModel();
|
|
284
|
-
const editRow = model[id];
|
|
285
|
-
|
|
286
|
-
if (!editRow) {
|
|
287
|
-
throw new Error(`MUI: Row at id: ${id} is not being edited.`);
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
const row = apiRef.current.getRow(id);
|
|
291
|
-
|
|
292
|
-
if (row) {
|
|
293
|
-
let rowUpdate = (0, _extends2.default)({}, row);
|
|
294
|
-
Object.keys(editRow).forEach(field => {
|
|
295
|
-
const column = apiRef.current.getColumn(field);
|
|
296
|
-
const value = editRow[field].value;
|
|
297
|
-
|
|
298
|
-
if (column.valueSetter) {
|
|
299
|
-
rowUpdate = column.valueSetter({
|
|
300
|
-
row: rowUpdate,
|
|
301
|
-
value
|
|
302
|
-
});
|
|
303
|
-
} else {
|
|
304
|
-
rowUpdate[field] = value;
|
|
305
|
-
}
|
|
306
|
-
});
|
|
307
|
-
apiRef.current.updateRows([rowUpdate]);
|
|
308
|
-
}
|
|
309
|
-
}, [apiRef]);
|
|
310
|
-
const handleCellFocusIn = React.useCallback(params => {
|
|
311
|
-
nextFocusedCell.current = params;
|
|
312
|
-
}, []);
|
|
313
|
-
|
|
314
|
-
const commitPropsAndExit = async (params, event) => {
|
|
315
|
-
if (params.cellMode === _gridEditRowModel.GridCellModes.View) {
|
|
316
|
-
return;
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
nextFocusedCell.current = null;
|
|
320
|
-
focusTimeout.current = setTimeout(async () => {
|
|
321
|
-
var _nextFocusedCell$curr;
|
|
322
|
-
|
|
323
|
-
if (((_nextFocusedCell$curr = nextFocusedCell.current) == null ? void 0 : _nextFocusedCell$curr.id) !== params.id) {
|
|
324
|
-
await apiRef.current.commitRowChange(params.id, event);
|
|
325
|
-
const rowParams = apiRef.current.getRowParams(params.id);
|
|
326
|
-
apiRef.current.publishEvent('rowEditStop', rowParams, event);
|
|
327
|
-
}
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
const handleCellFocusOut = (0, _utils.useEventCallback)((params, event) => {
|
|
332
|
-
commitPropsAndExit(params, event);
|
|
333
|
-
});
|
|
334
|
-
const handleColumnHeaderDragStart = (0, _utils.useEventCallback)(() => {
|
|
335
|
-
const cell = (0, _gridFocusStateSelector.gridFocusCellSelector)(apiRef);
|
|
336
|
-
|
|
337
|
-
if (!cell) {
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const params = apiRef.current.getCellParams(cell.id, cell.field);
|
|
342
|
-
commitPropsAndExit(params, {});
|
|
343
|
-
});
|
|
344
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellKeyDown', buildCallback(handleCellKeyDown));
|
|
345
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellDoubleClick', buildCallback(handleCellDoubleClick));
|
|
346
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'editCellPropsChange', buildCallback(handleEditCellPropsChange));
|
|
347
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'rowEditStart', buildCallback(handleRowEditStart));
|
|
348
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'rowEditStop', buildCallback(handleRowEditStop));
|
|
349
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'rowEditCommit', buildCallback(handleRowEditCommit));
|
|
350
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellFocusIn', buildCallback(handleCellFocusIn));
|
|
351
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'cellFocusOut', buildCallback(handleCellFocusOut));
|
|
352
|
-
(0, _useGridApiEventHandler.useGridApiEventHandler)(apiRef, 'columnHeaderDragStart', buildCallback(handleColumnHeaderDragStart));
|
|
353
|
-
(0, _useGridApiEventHandler.useGridApiOptionHandler)(apiRef, 'rowEditCommit', props.onRowEditCommit);
|
|
354
|
-
(0, _useGridApiEventHandler.useGridApiOptionHandler)(apiRef, 'rowEditStart', props.onRowEditStart);
|
|
355
|
-
(0, _useGridApiEventHandler.useGridApiOptionHandler)(apiRef, 'rowEditStop', props.onRowEditStop);
|
|
356
|
-
};
|
|
357
|
-
|
|
358
|
-
exports.useGridRowEditing = useGridRowEditing;
|