@dooherceg/material-react-table 3.2.8 → 3.2.9
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/index.esm.js +28 -17
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +28 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -792,9 +792,16 @@ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
|
|
|
792
792
|
};
|
|
793
793
|
const handleConfirmDelete = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
794
794
|
setDeleting(true);
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
795
|
+
try {
|
|
796
|
+
yield onDeleteConfirm();
|
|
797
|
+
setOpen(false);
|
|
798
|
+
}
|
|
799
|
+
catch (error) {
|
|
800
|
+
console.error('[MRT] Error while deleting row(s):', error);
|
|
801
|
+
}
|
|
802
|
+
finally {
|
|
803
|
+
setDeleting(false);
|
|
804
|
+
}
|
|
798
805
|
});
|
|
799
806
|
const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
800
807
|
setOpen(false);
|
|
@@ -835,16 +842,15 @@ const createDeleteAction = (_a = {}) => {
|
|
|
835
842
|
return executeDelete({ table, rowsToDelete: [row] });
|
|
836
843
|
};
|
|
837
844
|
// Wraps row context into a zero-argument callback expected by row action UI.
|
|
845
|
+
// Must return the promise (not fire-and-forget it) so callers like DeleteRowAction
|
|
846
|
+
// can `await` it and keep the confirmation modal open until delete actually finishes.
|
|
838
847
|
const createRowDeleteExecutor = (context) => {
|
|
839
|
-
return () =>
|
|
840
|
-
void handleSingleRowDelete(context);
|
|
841
|
-
};
|
|
848
|
+
return () => handleSingleRowDelete(context);
|
|
842
849
|
};
|
|
843
850
|
// Wraps toolbar context into a zero-argument callback expected by toolbar action UI.
|
|
851
|
+
// Same reasoning as createRowDeleteExecutor — the returned promise must propagate.
|
|
844
852
|
const createToolbarDeleteExecutor = (context) => {
|
|
845
|
-
return () =>
|
|
846
|
-
void handleMultipleRowDelete(context);
|
|
847
|
-
};
|
|
853
|
+
return () => handleMultipleRowDelete(context);
|
|
848
854
|
};
|
|
849
855
|
// Uses custom row renderer when provided; otherwise renders default delete action UI.
|
|
850
856
|
const renderRowAction = (context) => {
|
|
@@ -2628,6 +2634,11 @@ const useMRT_Effects = (table) => {
|
|
|
2628
2634
|
}, [density]);
|
|
2629
2635
|
};
|
|
2630
2636
|
|
|
2637
|
+
// Keeps the local rows array from growing past the current page size. New rows are
|
|
2638
|
+
// inserted at the front, so overflow is trimmed off the tail (the oldest existing
|
|
2639
|
+
// rows), since the local state is expected to be reconciled with the source of
|
|
2640
|
+
// truth on the next fetch.
|
|
2641
|
+
const capRowsToPageSize = (rows, pageSize) => pageSize && rows.length > pageSize ? rows.slice(0, pageSize) : rows;
|
|
2631
2642
|
const normalizeRowInput = (rowInput) => (Array.isArray(rowInput) ? rowInput : [rowInput]);
|
|
2632
2643
|
const getResolvedRowId = (row, index, parentRow, getRowId) => {
|
|
2633
2644
|
const customRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(row, index, parentRow);
|
|
@@ -2638,7 +2649,7 @@ const getResolvedRowId = (row, index, parentRow, getRowId) => {
|
|
|
2638
2649
|
return String(row.id);
|
|
2639
2650
|
return undefined;
|
|
2640
2651
|
};
|
|
2641
|
-
const handleAddRow = ({ setRowsState, }) => {
|
|
2652
|
+
const handleAddRow = ({ pageSize, setRowsState, }) => {
|
|
2642
2653
|
return (rowInput) => {
|
|
2643
2654
|
const rowsToAdd = normalizeRowInput(rowInput);
|
|
2644
2655
|
const hasValidRowIds = rowsToAdd.every((row, index) => {
|
|
@@ -2648,7 +2659,7 @@ const handleAddRow = ({ setRowsState, }) => {
|
|
|
2648
2659
|
if (!hasValidRowIds) {
|
|
2649
2660
|
throw new Error('Each row must have a valid `id` property or a `getRowId` function must be provided to generate unique IDs.');
|
|
2650
2661
|
}
|
|
2651
|
-
setRowsState((previousRows) => [...
|
|
2662
|
+
setRowsState((previousRows) => capRowsToPageSize([...rowsToAdd, ...previousRows], pageSize));
|
|
2652
2663
|
};
|
|
2653
2664
|
};
|
|
2654
2665
|
const handleUpdateRow = ({ getRowId, setRowsState, }) => {
|
|
@@ -2678,7 +2689,7 @@ const handleSetRows = ({ setRowsState, }) => {
|
|
|
2678
2689
|
setRowsState(normalizeRowInput(rowInput));
|
|
2679
2690
|
};
|
|
2680
2691
|
};
|
|
2681
|
-
const handleUpsertRow = ({ getRowId, setRowsState, }) => {
|
|
2692
|
+
const handleUpsertRow = ({ getRowId, pageSize, setRowsState, }) => {
|
|
2682
2693
|
return (rowInput) => {
|
|
2683
2694
|
const rowsToUpsert = normalizeRowInput(rowInput);
|
|
2684
2695
|
setRowsState((previousRows) => {
|
|
@@ -2692,19 +2703,17 @@ const handleUpsertRow = ({ getRowId, setRowsState, }) => {
|
|
|
2692
2703
|
indexByRowId.set(rowId, index);
|
|
2693
2704
|
}
|
|
2694
2705
|
});
|
|
2706
|
+
const rowsToInsert = [];
|
|
2695
2707
|
rowsToUpsert.forEach((row, index) => {
|
|
2696
2708
|
const rowId = getResolvedRowId(row, index, undefined, getRowId);
|
|
2697
2709
|
const existingIndex = rowId !== undefined ? indexByRowId.get(rowId) : undefined;
|
|
2698
2710
|
if (existingIndex === undefined) {
|
|
2699
|
-
|
|
2700
|
-
indexByRowId.set(rowId, nextRows.length);
|
|
2701
|
-
}
|
|
2702
|
-
nextRows.push(row);
|
|
2711
|
+
rowsToInsert.push(row);
|
|
2703
2712
|
return;
|
|
2704
2713
|
}
|
|
2705
2714
|
nextRows[existingIndex] = row;
|
|
2706
2715
|
});
|
|
2707
|
-
return nextRows;
|
|
2716
|
+
return capRowsToPageSize([...rowsToInsert, ...nextRows], pageSize);
|
|
2708
2717
|
});
|
|
2709
2718
|
};
|
|
2710
2719
|
};
|
|
@@ -3134,6 +3143,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3134
3143
|
table.addRow = handleAddRow({
|
|
3135
3144
|
setRowsState,
|
|
3136
3145
|
getRowId: resolveRowId,
|
|
3146
|
+
pageSize: statefulTableOptions.state.pagination.pageSize,
|
|
3137
3147
|
});
|
|
3138
3148
|
table.updateRow = handleUpdateRow({
|
|
3139
3149
|
setRowsState,
|
|
@@ -3146,6 +3156,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3146
3156
|
table.upsertRow = handleUpsertRow({
|
|
3147
3157
|
setRowsState,
|
|
3148
3158
|
getRowId: resolveRowId,
|
|
3159
|
+
pageSize: statefulTableOptions.state.pagination.pageSize,
|
|
3149
3160
|
});
|
|
3150
3161
|
table.removeRow = handleRemoveRow({
|
|
3151
3162
|
setRowsState,
|