@mui/x-data-grid-premium 8.24.0 → 8.26.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/CHANGELOG.md +196 -6479
- package/DataGridPremium/DataGridPremium.js +25 -1
- package/DataGridPremium/useDataGridPremiumComponent.js +3 -0
- package/DataGridPremium/useDataGridPremiumProps.js +5 -1
- package/components/GridAggregationRowOverlay.js +1 -0
- package/components/GridEmptyPivotOverlay.js +1 -0
- package/components/GridPremiumColumnMenu.js +1 -0
- package/components/GridPremiumToolbar.js +55 -3
- package/components/columnMenu/menuItems/GridColumnMenuAggregationItem.js +1 -0
- package/components/resizablePanel/ResizablePanel.js +1 -0
- package/components/resizablePanel/ResizablePanelHandle.js +1 -0
- package/esm/DataGridPremium/DataGridPremium.js +25 -1
- package/esm/DataGridPremium/useDataGridPremiumComponent.js +3 -0
- package/esm/DataGridPremium/useDataGridPremiumProps.js +5 -1
- package/esm/components/GridAggregationRowOverlay.js +2 -0
- package/esm/components/GridEmptyPivotOverlay.js +2 -0
- package/esm/components/GridPremiumColumnMenu.js +2 -0
- package/esm/components/GridPremiumToolbar.js +57 -5
- package/esm/components/columnMenu/menuItems/GridColumnMenuAggregationItem.js +2 -0
- package/esm/components/resizablePanel/ResizablePanel.js +2 -0
- package/esm/components/resizablePanel/ResizablePanelHandle.js +2 -0
- package/esm/hooks/features/aggregation/useGridAggregationPreProcessors.js +2 -0
- package/esm/hooks/features/clipboard/useGridClipboardImport.js +20 -9
- package/esm/hooks/features/history/constants.d.ts +2 -0
- package/esm/hooks/features/history/constants.js +1 -0
- package/esm/hooks/features/history/defaultHistoryHandlers.d.ts +20 -0
- package/esm/hooks/features/history/defaultHistoryHandlers.js +365 -0
- package/esm/hooks/features/history/gridHistoryInterfaces.d.ts +95 -0
- package/esm/hooks/features/history/gridHistoryInterfaces.js +1 -0
- package/esm/hooks/features/history/gridHistorySelectors.d.ts +16 -0
- package/esm/hooks/features/history/gridHistorySelectors.js +7 -0
- package/esm/hooks/features/history/index.d.ts +3 -0
- package/esm/hooks/features/history/index.js +2 -0
- package/esm/hooks/features/history/useGridHistory.d.ts +6 -0
- package/esm/hooks/features/history/useGridHistory.js +294 -0
- package/esm/hooks/features/index.d.ts +2 -1
- package/esm/hooks/features/index.js +2 -1
- package/esm/hooks/utils/useGridChartIntegration.js +2 -0
- package/esm/index.js +1 -1
- package/esm/models/dataGridPremiumProps.d.ts +26 -1
- package/esm/models/gridApiPremium.d.ts +2 -1
- package/esm/models/gridStatePremium.d.ts +2 -0
- package/esm/typeOverloads/modules.d.ts +25 -2
- package/esm/typeOverloads/modules.js +5 -1
- package/hooks/features/aggregation/useGridAggregationPreProcessors.js +1 -0
- package/hooks/features/clipboard/useGridClipboardImport.js +20 -9
- package/hooks/features/history/constants.d.ts +2 -0
- package/hooks/features/history/constants.js +7 -0
- package/hooks/features/history/defaultHistoryHandlers.d.ts +20 -0
- package/hooks/features/history/defaultHistoryHandlers.js +376 -0
- package/hooks/features/history/gridHistoryInterfaces.d.ts +95 -0
- package/hooks/features/history/gridHistoryInterfaces.js +5 -0
- package/hooks/features/history/gridHistorySelectors.d.ts +16 -0
- package/hooks/features/history/gridHistorySelectors.js +13 -0
- package/hooks/features/history/index.d.ts +3 -0
- package/hooks/features/history/index.js +43 -0
- package/hooks/features/history/useGridHistory.d.ts +6 -0
- package/hooks/features/history/useGridHistory.js +303 -0
- package/hooks/features/index.d.ts +2 -1
- package/hooks/features/index.js +11 -0
- package/hooks/utils/useGridChartIntegration.js +1 -0
- package/index.js +1 -1
- package/models/dataGridPremiumProps.d.ts +26 -1
- package/models/gridApiPremium.d.ts +2 -1
- package/models/gridStatePremium.d.ts +2 -0
- package/package.json +5 -5
- package/typeOverloads/modules.d.ts +25 -2
- package/typeOverloads/modules.js +1 -3
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.createRowEditHistoryHandler = exports.createDefaultHistoryHandlers = exports.createClipboardPasteHistoryHandler = exports.createCellEditHistoryHandler = void 0;
|
|
8
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
9
|
+
var _isDeepEqual = require("@mui/x-internals/isDeepEqual");
|
|
10
|
+
var _xDataGridPro = require("@mui/x-data-grid-pro");
|
|
11
|
+
/**
|
|
12
|
+
* Create the default handler for cellEditStop events.
|
|
13
|
+
*/
|
|
14
|
+
const createCellEditHistoryHandler = apiRef => {
|
|
15
|
+
return {
|
|
16
|
+
store: params => {
|
|
17
|
+
const {
|
|
18
|
+
id,
|
|
19
|
+
field
|
|
20
|
+
} = params;
|
|
21
|
+
const oldValue = apiRef.current.getRow(id)[field];
|
|
22
|
+
const newValue = apiRef.current.getRowWithUpdatedValues(id, field)[field];
|
|
23
|
+
if ((0, _isDeepEqual.isDeepEqual)(oldValue, newValue)) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
id,
|
|
28
|
+
field,
|
|
29
|
+
oldValue,
|
|
30
|
+
newValue
|
|
31
|
+
};
|
|
32
|
+
},
|
|
33
|
+
validate: (data, direction) => {
|
|
34
|
+
const {
|
|
35
|
+
id,
|
|
36
|
+
field,
|
|
37
|
+
oldValue,
|
|
38
|
+
newValue
|
|
39
|
+
} = data;
|
|
40
|
+
|
|
41
|
+
// Check if column is visible
|
|
42
|
+
if (!(0, _xDataGridPro.gridVisibleColumnFieldsSelector)(apiRef).includes(field)) {
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
const {
|
|
46
|
+
rowIdToIndexMap,
|
|
47
|
+
range
|
|
48
|
+
} = (0, _xDataGridPro.gridVisibleRowsSelector)(apiRef);
|
|
49
|
+
|
|
50
|
+
// Check if row is in the current page
|
|
51
|
+
const rowIndex = rowIdToIndexMap.get(id);
|
|
52
|
+
if (rowIndex === undefined || rowIndex < (range?.firstRowIndex || 0) || rowIndex > (range?.lastRowIndex || rowIndex)) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
const row = apiRef.current.getRow(id);
|
|
56
|
+
|
|
57
|
+
// Check if the value hasn't changed externally
|
|
58
|
+
const currentValue = row[field];
|
|
59
|
+
const expectedValue = direction === 'undo' ? newValue : oldValue;
|
|
60
|
+
if (!(0, _isDeepEqual.isDeepEqual)(currentValue, expectedValue)) {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
return true;
|
|
64
|
+
},
|
|
65
|
+
undo: async data => {
|
|
66
|
+
const {
|
|
67
|
+
id,
|
|
68
|
+
field,
|
|
69
|
+
oldValue
|
|
70
|
+
} = data;
|
|
71
|
+
if (apiRef.current.state.props.dataSource?.updateRow) {
|
|
72
|
+
const row = apiRef.current.getRow(id);
|
|
73
|
+
await apiRef.current.dataSource.editRow({
|
|
74
|
+
rowId: id,
|
|
75
|
+
updatedRow: (0, _extends2.default)({}, row, {
|
|
76
|
+
[field]: oldValue
|
|
77
|
+
}),
|
|
78
|
+
previousRow: row
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
apiRef.current.updateRows([{
|
|
82
|
+
id,
|
|
83
|
+
[field]: oldValue
|
|
84
|
+
}]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Use `requestAnimationFrame` to ensure all undo updates are applied
|
|
88
|
+
requestAnimationFrame(() => {
|
|
89
|
+
apiRef.current.setCellFocus(id, field);
|
|
90
|
+
apiRef.current.scrollToIndexes({
|
|
91
|
+
rowIndex: apiRef.current.getRowIndexRelativeToVisibleRows(id),
|
|
92
|
+
colIndex: apiRef.current.getColumnIndex(field)
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
},
|
|
96
|
+
redo: async data => {
|
|
97
|
+
const {
|
|
98
|
+
id,
|
|
99
|
+
field,
|
|
100
|
+
newValue
|
|
101
|
+
} = data;
|
|
102
|
+
if (apiRef.current.state.props.dataSource?.updateRow) {
|
|
103
|
+
const row = apiRef.current.getRow(id);
|
|
104
|
+
await apiRef.current.dataSource.editRow({
|
|
105
|
+
rowId: id,
|
|
106
|
+
updatedRow: (0, _extends2.default)({}, row, {
|
|
107
|
+
[field]: newValue
|
|
108
|
+
}),
|
|
109
|
+
previousRow: row
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
apiRef.current.updateRows([{
|
|
113
|
+
id,
|
|
114
|
+
[field]: newValue
|
|
115
|
+
}]);
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Use `requestAnimationFrame` to ensure all redo updates are applied
|
|
119
|
+
requestAnimationFrame(() => {
|
|
120
|
+
apiRef.current.setCellFocus(id, field);
|
|
121
|
+
apiRef.current.scrollToIndexes({
|
|
122
|
+
rowIndex: apiRef.current.getRowIndexRelativeToVisibleRows(id),
|
|
123
|
+
colIndex: apiRef.current.getColumnIndex(field)
|
|
124
|
+
});
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Create the default handler for rowEditStop events.
|
|
132
|
+
*/
|
|
133
|
+
exports.createCellEditHistoryHandler = createCellEditHistoryHandler;
|
|
134
|
+
const createRowEditHistoryHandler = apiRef => {
|
|
135
|
+
return {
|
|
136
|
+
store: params => {
|
|
137
|
+
const {
|
|
138
|
+
id
|
|
139
|
+
} = params;
|
|
140
|
+
const oldRow = apiRef.current.getRow(id) || {};
|
|
141
|
+
const newRow = apiRef.current.getRowWithUpdatedValues(id, '');
|
|
142
|
+
if ((0, _isDeepEqual.isDeepEqual)(oldRow, newRow)) {
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
id,
|
|
147
|
+
oldRow,
|
|
148
|
+
newRow
|
|
149
|
+
};
|
|
150
|
+
},
|
|
151
|
+
validate: (data, direction) => {
|
|
152
|
+
const {
|
|
153
|
+
id,
|
|
154
|
+
oldRow,
|
|
155
|
+
newRow
|
|
156
|
+
} = data;
|
|
157
|
+
const {
|
|
158
|
+
rowIdToIndexMap,
|
|
159
|
+
range
|
|
160
|
+
} = (0, _xDataGridPro.gridVisibleRowsSelector)(apiRef);
|
|
161
|
+
|
|
162
|
+
// Check if row is in the current page
|
|
163
|
+
const rowIndex = rowIdToIndexMap.get(id);
|
|
164
|
+
if (rowIndex === undefined || rowIndex < (range?.firstRowIndex || 0) || rowIndex > (range?.lastRowIndex || rowIndex)) {
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
const row = apiRef.current.getRow(id);
|
|
168
|
+
|
|
169
|
+
// Check if modified fields haven't changed externally
|
|
170
|
+
const expectedRow = direction === 'undo' ? newRow : oldRow;
|
|
171
|
+
for (const field of Object.keys(expectedRow)) {
|
|
172
|
+
if (!(0, _isDeepEqual.isDeepEqual)(row[field], expectedRow[field])) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return true;
|
|
177
|
+
},
|
|
178
|
+
undo: async data => {
|
|
179
|
+
const {
|
|
180
|
+
id,
|
|
181
|
+
oldRow,
|
|
182
|
+
newRow
|
|
183
|
+
} = data;
|
|
184
|
+
if (apiRef.current.state.props.dataSource?.updateRow) {
|
|
185
|
+
await apiRef.current.dataSource.editRow({
|
|
186
|
+
rowId: id,
|
|
187
|
+
updatedRow: oldRow,
|
|
188
|
+
previousRow: newRow
|
|
189
|
+
});
|
|
190
|
+
} else {
|
|
191
|
+
apiRef.current.updateRows([(0, _extends2.default)({
|
|
192
|
+
id
|
|
193
|
+
}, oldRow)]);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Use `requestAnimationFrame` to ensure all undo updates are applied
|
|
197
|
+
requestAnimationFrame(() => {
|
|
198
|
+
apiRef.current.setCellFocus(id, Object.keys(oldRow)[0]);
|
|
199
|
+
apiRef.current.scrollToIndexes({
|
|
200
|
+
rowIndex: apiRef.current.getRowIndexRelativeToVisibleRows(id),
|
|
201
|
+
colIndex: 0
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
},
|
|
205
|
+
redo: async data => {
|
|
206
|
+
const {
|
|
207
|
+
id,
|
|
208
|
+
oldRow,
|
|
209
|
+
newRow
|
|
210
|
+
} = data;
|
|
211
|
+
if (apiRef.current.state.props.dataSource?.updateRow) {
|
|
212
|
+
await apiRef.current.dataSource.editRow({
|
|
213
|
+
rowId: id,
|
|
214
|
+
updatedRow: newRow,
|
|
215
|
+
previousRow: oldRow
|
|
216
|
+
});
|
|
217
|
+
} else {
|
|
218
|
+
apiRef.current.updateRows([(0, _extends2.default)({
|
|
219
|
+
id
|
|
220
|
+
}, newRow)]);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
// Use `requestAnimationFrame` to ensure all redo updates are applied
|
|
224
|
+
requestAnimationFrame(() => {
|
|
225
|
+
apiRef.current.setCellFocus(id, Object.keys(newRow)[0]);
|
|
226
|
+
apiRef.current.scrollToIndexes({
|
|
227
|
+
rowIndex: apiRef.current.getRowIndexRelativeToVisibleRows(id),
|
|
228
|
+
colIndex: 0
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
};
|
|
233
|
+
};
|
|
234
|
+
|
|
235
|
+
/**
|
|
236
|
+
* Create the default handler for clipboardPasteEnd events.
|
|
237
|
+
*/
|
|
238
|
+
exports.createRowEditHistoryHandler = createRowEditHistoryHandler;
|
|
239
|
+
const createClipboardPasteHistoryHandler = apiRef => {
|
|
240
|
+
return {
|
|
241
|
+
store: params => params,
|
|
242
|
+
validate: (data, direction) => {
|
|
243
|
+
const {
|
|
244
|
+
oldRows,
|
|
245
|
+
newRows
|
|
246
|
+
} = data;
|
|
247
|
+
const updatedRowIds = Array.from(newRows.keys());
|
|
248
|
+
|
|
249
|
+
// Check if any rows were updated
|
|
250
|
+
if (updatedRowIds.length === 0) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Check if all affected rows are still visible and have expected values
|
|
255
|
+
const {
|
|
256
|
+
rowIdToIndexMap,
|
|
257
|
+
range
|
|
258
|
+
} = (0, _xDataGridPro.gridVisibleRowsSelector)(apiRef);
|
|
259
|
+
for (let i = 0; i < updatedRowIds.length; i += 1) {
|
|
260
|
+
const rowId = updatedRowIds[i];
|
|
261
|
+
const rowIndex = rowIdToIndexMap.get(rowId);
|
|
262
|
+
if (rowIndex === undefined || rowIndex < (range?.firstRowIndex || 0) || rowIndex > (range?.lastRowIndex || rowIndex)) {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
const row = apiRef.current.getRow(rowId);
|
|
266
|
+
if (!row) {
|
|
267
|
+
return false;
|
|
268
|
+
}
|
|
269
|
+
const expectedRow = direction === 'undo' ? newRows.get(rowId) : oldRows.get(rowId);
|
|
270
|
+
|
|
271
|
+
// Check if the row values match what we expect
|
|
272
|
+
for (const field of Object.keys(expectedRow)) {
|
|
273
|
+
if (!(0, _isDeepEqual.isDeepEqual)(row[field], expectedRow[field])) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
return true;
|
|
279
|
+
},
|
|
280
|
+
undo: async data => {
|
|
281
|
+
const {
|
|
282
|
+
oldRows,
|
|
283
|
+
newRows
|
|
284
|
+
} = data;
|
|
285
|
+
const oldRowsValues = Array.from(oldRows.values());
|
|
286
|
+
const visibleColumns = apiRef.current.getVisibleColumns();
|
|
287
|
+
|
|
288
|
+
// Focus the first affected cell
|
|
289
|
+
if (oldRowsValues.length > 0 && visibleColumns.length > 0) {
|
|
290
|
+
const columnOrder = (0, _xDataGridPro.gridColumnFieldsSelector)(apiRef);
|
|
291
|
+
|
|
292
|
+
// Since we undo, oldRowData is the new data that will be set and newRowData is the current row
|
|
293
|
+
const firstOldRow = Array.from(newRows.values())[0];
|
|
294
|
+
const [firstNewRowId, firstNewRow] = Array.from(oldRows.entries())[0];
|
|
295
|
+
let differentFieldIndex = columnOrder.length - 1;
|
|
296
|
+
// Find the first field that is different to set the focus on
|
|
297
|
+
for (let i = 0; i < columnOrder.length; i += 1) {
|
|
298
|
+
const field = columnOrder[i];
|
|
299
|
+
if (!(0, _isDeepEqual.isDeepEqual)(firstOldRow[field], firstNewRow[field])) {
|
|
300
|
+
differentFieldIndex = i;
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// Restore all rows to their original state
|
|
306
|
+
apiRef.current.updateRows(oldRowsValues);
|
|
307
|
+
if (differentFieldIndex >= 0) {
|
|
308
|
+
requestAnimationFrame(() => {
|
|
309
|
+
apiRef.current.setCellFocus(firstNewRowId, columnOrder[differentFieldIndex]);
|
|
310
|
+
apiRef.current.scrollToIndexes({
|
|
311
|
+
rowIndex: apiRef.current.getRowIndexRelativeToVisibleRows(firstNewRowId),
|
|
312
|
+
colIndex: differentFieldIndex
|
|
313
|
+
});
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
redo: async data => {
|
|
319
|
+
const {
|
|
320
|
+
oldRows,
|
|
321
|
+
newRows
|
|
322
|
+
} = data;
|
|
323
|
+
const newRowsValues = Array.from(newRows.values());
|
|
324
|
+
const visibleColumns = apiRef.current.getVisibleColumns();
|
|
325
|
+
|
|
326
|
+
// Focus the first affected cell
|
|
327
|
+
if (newRowsValues.length > 0 && visibleColumns.length > 0) {
|
|
328
|
+
const columnOrder = (0, _xDataGridPro.gridColumnFieldsSelector)(apiRef);
|
|
329
|
+
const firstOldRow = Array.from(oldRows.values())[0];
|
|
330
|
+
const [firstNewRowId, firstNewRow] = Array.from(newRows.entries())[0];
|
|
331
|
+
let differentFieldIndex = columnOrder.length - 1;
|
|
332
|
+
// Find the first field that is different to set the focus on
|
|
333
|
+
for (let i = 0; i < columnOrder.length; i += 1) {
|
|
334
|
+
const field = columnOrder[i];
|
|
335
|
+
if (!(0, _isDeepEqual.isDeepEqual)(firstOldRow[field], firstNewRow[field])) {
|
|
336
|
+
differentFieldIndex = i;
|
|
337
|
+
break;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Restore all rows to the pasted state
|
|
342
|
+
apiRef.current.updateRows(newRowsValues);
|
|
343
|
+
if (differentFieldIndex >= 0) {
|
|
344
|
+
requestAnimationFrame(() => {
|
|
345
|
+
apiRef.current.setCellFocus(firstNewRowId, columnOrder[differentFieldIndex]);
|
|
346
|
+
apiRef.current.scrollToIndexes({
|
|
347
|
+
rowIndex: apiRef.current.getRowIndexRelativeToVisibleRows(firstNewRowId),
|
|
348
|
+
colIndex: differentFieldIndex
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
};
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Create the default history events map.
|
|
359
|
+
*/
|
|
360
|
+
exports.createClipboardPasteHistoryHandler = createClipboardPasteHistoryHandler;
|
|
361
|
+
const createDefaultHistoryHandlers = (apiRef, props) => {
|
|
362
|
+
const handlers = {};
|
|
363
|
+
const canHaveEditing = props.isCellEditable || props.columns.some(col => col.editable);
|
|
364
|
+
if (!canHaveEditing) {
|
|
365
|
+
return handlers;
|
|
366
|
+
}
|
|
367
|
+
if (!props.dataSource || props.dataSource.updateRow) {
|
|
368
|
+
handlers.cellEditStop = createCellEditHistoryHandler(apiRef);
|
|
369
|
+
handlers.rowEditStop = createRowEditHistoryHandler(apiRef);
|
|
370
|
+
}
|
|
371
|
+
if (!props.dataSource) {
|
|
372
|
+
handlers.clipboardPasteEnd = createClipboardPasteHistoryHandler(apiRef);
|
|
373
|
+
}
|
|
374
|
+
return handlers;
|
|
375
|
+
};
|
|
376
|
+
exports.createDefaultHistoryHandlers = createDefaultHistoryHandlers;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import type { GridRowId, GridEvents, GridValidRowModel } from '@mui/x-data-grid-pro';
|
|
2
|
+
/**
|
|
3
|
+
* Handler for a specific grid event
|
|
4
|
+
*/
|
|
5
|
+
export interface GridHistoryEventHandler<T = any> {
|
|
6
|
+
/**
|
|
7
|
+
* Store the data to be used for undo/redo operations.
|
|
8
|
+
* @param {any} params The parameters from the original event.
|
|
9
|
+
* @returns {T | null} The data to store in the history stack.
|
|
10
|
+
* Return `null` if the event should not be stored.
|
|
11
|
+
* This can be used to descrease the granularity of the undo steps.
|
|
12
|
+
*/
|
|
13
|
+
store: (...params: any[]) => T | null;
|
|
14
|
+
/**
|
|
15
|
+
* Undo the changes made by this event.
|
|
16
|
+
* @param {T} data The stored data.
|
|
17
|
+
* @returns {boolean | Promise<boolean>} True if the operation was successful, false otherwise.
|
|
18
|
+
*/
|
|
19
|
+
undo: (data: T) => void | Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* Redo the changes made by this event.
|
|
22
|
+
* @param {T} data The stored data.
|
|
23
|
+
* @returns {boolean | Promise<boolean>} True if the operation was successful, false otherwise.
|
|
24
|
+
*/
|
|
25
|
+
redo: (data: T) => void | Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* Validate if the undo/redo operation can be performed.
|
|
28
|
+
* If validation is not needed, do not provide this method to avoid impacting performance.
|
|
29
|
+
* @param {T} data The stored data.
|
|
30
|
+
* @param {'undo' | 'redo'} operation - The operation to validate.
|
|
31
|
+
* @returns {boolean} True if the operation is valid, false otherwise.
|
|
32
|
+
*/
|
|
33
|
+
validate?: (data: T, operation: 'undo' | 'redo') => boolean;
|
|
34
|
+
}
|
|
35
|
+
export interface GridHistoryItem<T = any> {
|
|
36
|
+
eventName: GridEvents;
|
|
37
|
+
data: T;
|
|
38
|
+
}
|
|
39
|
+
export interface GridHistoryState {
|
|
40
|
+
stack: GridHistoryItem[];
|
|
41
|
+
/**
|
|
42
|
+
* The current position in the stack.
|
|
43
|
+
* Points to the last executed action.
|
|
44
|
+
* -1 means no actions have been executed.
|
|
45
|
+
*/
|
|
46
|
+
currentPosition: number;
|
|
47
|
+
/**
|
|
48
|
+
* True if the stack size is greater than 0 and there is at least one event handler.
|
|
49
|
+
*/
|
|
50
|
+
enabled: boolean;
|
|
51
|
+
}
|
|
52
|
+
export interface GridHistoryApi {
|
|
53
|
+
/**
|
|
54
|
+
* The history API.
|
|
55
|
+
*/
|
|
56
|
+
history: {
|
|
57
|
+
/**
|
|
58
|
+
* Undo the last action.
|
|
59
|
+
* @returns {Promise<boolean>} True if the operation was successful, false otherwise.
|
|
60
|
+
*/
|
|
61
|
+
undo: () => Promise<boolean>;
|
|
62
|
+
/**
|
|
63
|
+
* Redo the last undone action.
|
|
64
|
+
* @returns {Promise<boolean>} True if the operation was successful, false otherwise.
|
|
65
|
+
*/
|
|
66
|
+
redo: () => Promise<boolean>;
|
|
67
|
+
/**
|
|
68
|
+
* Clear the entire history.
|
|
69
|
+
*/
|
|
70
|
+
clear: () => void;
|
|
71
|
+
/**
|
|
72
|
+
* @returns {boolean} True if there are undo steps available, false otherwise.
|
|
73
|
+
*/
|
|
74
|
+
canUndo: () => boolean;
|
|
75
|
+
/**
|
|
76
|
+
* @returns {boolean} True if there are redo steps available, false otherwise.
|
|
77
|
+
*/
|
|
78
|
+
canRedo: () => boolean;
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
export interface GridCellEditHistoryData {
|
|
82
|
+
id: GridRowId;
|
|
83
|
+
field: string;
|
|
84
|
+
oldValue: any;
|
|
85
|
+
newValue: any;
|
|
86
|
+
}
|
|
87
|
+
export interface GridRowEditHistoryData {
|
|
88
|
+
id: GridRowId;
|
|
89
|
+
oldRow: GridValidRowModel;
|
|
90
|
+
newRow: GridValidRowModel;
|
|
91
|
+
}
|
|
92
|
+
export interface GridClipboardPasteHistoryData {
|
|
93
|
+
oldRows: Map<GridRowId, GridValidRowModel>;
|
|
94
|
+
newRows: Map<GridRowId, GridValidRowModel>;
|
|
95
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { GridStatePremium } from "../../../models/gridStatePremium.js";
|
|
2
|
+
export declare const gridHistoryEnabledSelector: (args_0: import("react").RefObject<{
|
|
3
|
+
state: GridStatePremium;
|
|
4
|
+
} | null>) => boolean;
|
|
5
|
+
export declare const gridHistoryStackSelector: (args_0: import("react").RefObject<{
|
|
6
|
+
state: GridStatePremium;
|
|
7
|
+
} | null>) => import("./gridHistoryInterfaces.js").GridHistoryItem<any>[];
|
|
8
|
+
export declare const gridHistoryCurrentPositionSelector: (args_0: import("react").RefObject<{
|
|
9
|
+
state: GridStatePremium;
|
|
10
|
+
} | null>) => number;
|
|
11
|
+
export declare const gridHistoryCanUndoSelector: (args_0: import("react").RefObject<{
|
|
12
|
+
state: GridStatePremium;
|
|
13
|
+
} | null>) => boolean;
|
|
14
|
+
export declare const gridHistoryCanRedoSelector: (args_0: import("react").RefObject<{
|
|
15
|
+
state: GridStatePremium;
|
|
16
|
+
} | null>) => boolean;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.gridHistoryStackSelector = exports.gridHistoryEnabledSelector = exports.gridHistoryCurrentPositionSelector = exports.gridHistoryCanUndoSelector = exports.gridHistoryCanRedoSelector = void 0;
|
|
7
|
+
var _internals = require("@mui/x-data-grid-pro/internals");
|
|
8
|
+
const gridHistoryStateSelector = (0, _internals.createRootSelector)(state => state.history);
|
|
9
|
+
const gridHistoryEnabledSelector = exports.gridHistoryEnabledSelector = (0, _internals.createSelector)(gridHistoryStateSelector, history => history.enabled);
|
|
10
|
+
const gridHistoryStackSelector = exports.gridHistoryStackSelector = (0, _internals.createSelector)(gridHistoryStateSelector, history => history.stack);
|
|
11
|
+
const gridHistoryCurrentPositionSelector = exports.gridHistoryCurrentPositionSelector = (0, _internals.createSelector)(gridHistoryStateSelector, history => history.currentPosition);
|
|
12
|
+
const gridHistoryCanUndoSelector = exports.gridHistoryCanUndoSelector = (0, _internals.createSelector)(gridHistoryCurrentPositionSelector, currentPosition => currentPosition >= 0);
|
|
13
|
+
const gridHistoryCanRedoSelector = exports.gridHistoryCanRedoSelector = (0, _internals.createSelector)(gridHistoryStackSelector, gridHistoryCurrentPositionSelector, (stack, currentPosition) => currentPosition < stack.length - 1);
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export type { GridHistoryEventHandler } from "./gridHistoryInterfaces.js";
|
|
2
|
+
export { createCellEditHistoryHandler, createRowEditHistoryHandler, createClipboardPasteHistoryHandler } from "./defaultHistoryHandlers.js";
|
|
3
|
+
export { gridHistoryCanUndoSelector, gridHistoryCanRedoSelector, gridHistoryEnabledSelector } from "./gridHistorySelectors.js";
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createCellEditHistoryHandler", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _defaultHistoryHandlers.createCellEditHistoryHandler;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "createClipboardPasteHistoryHandler", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _defaultHistoryHandlers.createClipboardPasteHistoryHandler;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "createRowEditHistoryHandler", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _defaultHistoryHandlers.createRowEditHistoryHandler;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "gridHistoryCanRedoSelector", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _gridHistorySelectors.gridHistoryCanRedoSelector;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "gridHistoryCanUndoSelector", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _gridHistorySelectors.gridHistoryCanUndoSelector;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "gridHistoryEnabledSelector", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _gridHistorySelectors.gridHistoryEnabledSelector;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var _defaultHistoryHandlers = require("./defaultHistoryHandlers");
|
|
43
|
+
var _gridHistorySelectors = require("./gridHistorySelectors");
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { RefObject } from '@mui/x-internals/types';
|
|
2
|
+
import { GridStateInitializer } from '@mui/x-data-grid-pro/internals';
|
|
3
|
+
import { GridPrivateApiPremium } from "../../../models/gridApiPremium.js";
|
|
4
|
+
import { DataGridPremiumProcessedProps } from "../../../models/dataGridPremiumProps.js";
|
|
5
|
+
export declare const historyStateInitializer: GridStateInitializer;
|
|
6
|
+
export declare const useGridHistory: (apiRef: RefObject<GridPrivateApiPremium>, props: Pick<DataGridPremiumProcessedProps, "columns" | "isCellEditable" | "dataSource" | "historyStackSize" | "historyEventHandlers" | "historyValidationEvents" | "onUndo" | "onRedo">) => void;
|