@dooherceg/material-react-table 3.2.8 → 3.2.10
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.d.ts +10 -1
- package/dist/index.esm.js +64 -25
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +64 -25
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -773,7 +773,12 @@ function MRT_DeleteRowButton({ onClick, }) {
|
|
|
773
773
|
const iconButtonStyle = {
|
|
774
774
|
p: 0,
|
|
775
775
|
};
|
|
776
|
-
|
|
776
|
+
const handleClick = (event) => {
|
|
777
|
+
// Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
|
|
778
|
+
event.stopPropagation();
|
|
779
|
+
onClick();
|
|
780
|
+
};
|
|
781
|
+
return (jsxRuntime.jsx(IconButton, { disableRipple: true, color: "error", sx: iconButtonStyle, onClick: handleClick, children: jsxRuntime.jsx(DeleteOutlineIcon, {}) }));
|
|
777
782
|
}
|
|
778
783
|
|
|
779
784
|
const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
|
|
@@ -794,14 +799,25 @@ const DeleteRowAction = ({ onDeleteConfirm, table, deleteConfirmation, }) => {
|
|
|
794
799
|
};
|
|
795
800
|
const handleConfirmDelete = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
796
801
|
setDeleting(true);
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
802
|
+
try {
|
|
803
|
+
yield onDeleteConfirm();
|
|
804
|
+
setOpen(false);
|
|
805
|
+
}
|
|
806
|
+
catch (error) {
|
|
807
|
+
console.error('[MRT] Error while deleting row(s):', error);
|
|
808
|
+
}
|
|
809
|
+
finally {
|
|
810
|
+
setDeleting(false);
|
|
811
|
+
}
|
|
800
812
|
});
|
|
801
813
|
const handleClose = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
802
814
|
setOpen(false);
|
|
803
815
|
});
|
|
804
|
-
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Dialog, { open: open, onClose: () => setOpen(false), keepMounted: true, "aria-describedby": "alert-dialog-slide-description", role: "alertdialog", sx: dialogSx, children: jsxRuntime.jsxs(Stack, { flexDirection: "column", height: "min-content", sx: contentContainerSx,
|
|
816
|
+
return (jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [jsxRuntime.jsx(Dialog, { open: open, onClose: () => setOpen(false), keepMounted: true, "aria-describedby": "alert-dialog-slide-description", role: "alertdialog", sx: dialogSx, children: jsxRuntime.jsxs(Stack, { flexDirection: "column", height: "min-content", sx: contentContainerSx,
|
|
817
|
+
// Dialog renders via a portal, but React still bubbles synthetic events up
|
|
818
|
+
// through the component tree — stop here so clicks inside the confirmation
|
|
819
|
+
// dialog don't reach muiTableBodyRowProps onClick (row click handlers).
|
|
820
|
+
onClick: (event) => event.stopPropagation(), children: [jsxRuntime.jsxs(Stack, { flexDirection: "row", alignItems: "center", justifyContent: "space-between", sx: Object.assign({ width: '100%' }, headerSx), children: [jsxRuntime.jsx(DialogTitle, { sx: Object.assign({ p: '0.7rem' }, titleSx), children: deleteConfirmationTitle }), jsxRuntime.jsx(DialogActions, { sx: {
|
|
805
821
|
p: '0.7rem',
|
|
806
822
|
}, children: jsxRuntime.jsx(IconButton, Object.assign({ color: "error", "aria-label": "close", onClick: handleClose }, closeButtonProps, { children: jsxRuntime.jsx(CancelIcon, {}) })) })] }), jsxRuntime.jsxs(Stack, { children: [jsxRuntime.jsx(DialogContent, { sx: Object.assign({ pr: '6rem' }, bodySx), children: deleteConfirmationMessage }), jsxRuntime.jsxs(DialogActions, { sx: footerSx, children: [jsxRuntime.jsx(Button, Object.assign({ onClick: () => setOpen(false), disabled: deleting, autoFocus: true, variant: "soft" }, cancelButtonProps, { children: cancelButtonLabel })), jsxRuntime.jsx(Button, Object.assign({ onClick: handleConfirmDelete, disabled: deleting, variant: "contained", color: "error" }, confirmButtonProps, { children: deleting ? deletingLabel : confirmButtonLabel }))] })] })] }) }), jsxRuntime.jsx(MRT_DeleteRowButton, { onClick: handleDeleteRowButtonClick })] }));
|
|
807
823
|
};
|
|
@@ -837,16 +853,15 @@ const createDeleteAction = (_a = {}) => {
|
|
|
837
853
|
return executeDelete({ table, rowsToDelete: [row] });
|
|
838
854
|
};
|
|
839
855
|
// Wraps row context into a zero-argument callback expected by row action UI.
|
|
856
|
+
// Must return the promise (not fire-and-forget it) so callers like DeleteRowAction
|
|
857
|
+
// can `await` it and keep the confirmation modal open until delete actually finishes.
|
|
840
858
|
const createRowDeleteExecutor = (context) => {
|
|
841
|
-
return () =>
|
|
842
|
-
void handleSingleRowDelete(context);
|
|
843
|
-
};
|
|
859
|
+
return () => handleSingleRowDelete(context);
|
|
844
860
|
};
|
|
845
861
|
// Wraps toolbar context into a zero-argument callback expected by toolbar action UI.
|
|
862
|
+
// Same reasoning as createRowDeleteExecutor — the returned promise must propagate.
|
|
846
863
|
const createToolbarDeleteExecutor = (context) => {
|
|
847
|
-
return () =>
|
|
848
|
-
void handleMultipleRowDelete(context);
|
|
849
|
-
};
|
|
864
|
+
return () => handleMultipleRowDelete(context);
|
|
850
865
|
};
|
|
851
866
|
// Uses custom row renderer when provided; otherwise renders default delete action UI.
|
|
852
867
|
const renderRowAction = (context) => {
|
|
@@ -868,7 +883,12 @@ const createDeleteAction = (_a = {}) => {
|
|
|
868
883
|
};
|
|
869
884
|
|
|
870
885
|
const MRT_EditRowButton = ({ onClick }) => {
|
|
871
|
-
|
|
886
|
+
const handleClick = (event) => {
|
|
887
|
+
// Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
|
|
888
|
+
event.stopPropagation();
|
|
889
|
+
onClick === null || onClick === void 0 ? void 0 : onClick(event);
|
|
890
|
+
};
|
|
891
|
+
return (jsxRuntime.jsx(IconButton, { sx: { p: 0 }, disableRipple: true, color: "primary", onClick: handleClick, children: jsxRuntime.jsx(EditNoteIcon, {}) }));
|
|
872
892
|
};
|
|
873
893
|
|
|
874
894
|
const EditRowAction = ({ onEditButtonClick, }) => {
|
|
@@ -2630,6 +2650,11 @@ const useMRT_Effects = (table) => {
|
|
|
2630
2650
|
}, [density]);
|
|
2631
2651
|
};
|
|
2632
2652
|
|
|
2653
|
+
// Keeps the local rows array from growing past the current page size. New rows are
|
|
2654
|
+
// inserted at the front, so overflow is trimmed off the tail (the oldest existing
|
|
2655
|
+
// rows), since the local state is expected to be reconciled with the source of
|
|
2656
|
+
// truth on the next fetch.
|
|
2657
|
+
const capRowsToPageSize = (rows, pageSize) => pageSize && rows.length > pageSize ? rows.slice(0, pageSize) : rows;
|
|
2633
2658
|
const normalizeRowInput = (rowInput) => (Array.isArray(rowInput) ? rowInput : [rowInput]);
|
|
2634
2659
|
const getResolvedRowId = (row, index, parentRow, getRowId) => {
|
|
2635
2660
|
const customRowId = getRowId === null || getRowId === void 0 ? void 0 : getRowId(row, index, parentRow);
|
|
@@ -2640,7 +2665,7 @@ const getResolvedRowId = (row, index, parentRow, getRowId) => {
|
|
|
2640
2665
|
return String(row.id);
|
|
2641
2666
|
return undefined;
|
|
2642
2667
|
};
|
|
2643
|
-
const handleAddRow = ({ setRowsState, }) => {
|
|
2668
|
+
const handleAddRow = ({ pageSize, setRowsState, }) => {
|
|
2644
2669
|
return (rowInput) => {
|
|
2645
2670
|
const rowsToAdd = normalizeRowInput(rowInput);
|
|
2646
2671
|
const hasValidRowIds = rowsToAdd.every((row, index) => {
|
|
@@ -2650,7 +2675,7 @@ const handleAddRow = ({ setRowsState, }) => {
|
|
|
2650
2675
|
if (!hasValidRowIds) {
|
|
2651
2676
|
throw new Error('Each row must have a valid `id` property or a `getRowId` function must be provided to generate unique IDs.');
|
|
2652
2677
|
}
|
|
2653
|
-
setRowsState((previousRows) => [...
|
|
2678
|
+
setRowsState((previousRows) => capRowsToPageSize([...rowsToAdd, ...previousRows], pageSize));
|
|
2654
2679
|
};
|
|
2655
2680
|
};
|
|
2656
2681
|
const handleUpdateRow = ({ getRowId, setRowsState, }) => {
|
|
@@ -2680,7 +2705,7 @@ const handleSetRows = ({ setRowsState, }) => {
|
|
|
2680
2705
|
setRowsState(normalizeRowInput(rowInput));
|
|
2681
2706
|
};
|
|
2682
2707
|
};
|
|
2683
|
-
const handleUpsertRow = ({ getRowId, setRowsState, }) => {
|
|
2708
|
+
const handleUpsertRow = ({ getRowId, pageSize, setRowsState, }) => {
|
|
2684
2709
|
return (rowInput) => {
|
|
2685
2710
|
const rowsToUpsert = normalizeRowInput(rowInput);
|
|
2686
2711
|
setRowsState((previousRows) => {
|
|
@@ -2694,19 +2719,17 @@ const handleUpsertRow = ({ getRowId, setRowsState, }) => {
|
|
|
2694
2719
|
indexByRowId.set(rowId, index);
|
|
2695
2720
|
}
|
|
2696
2721
|
});
|
|
2722
|
+
const rowsToInsert = [];
|
|
2697
2723
|
rowsToUpsert.forEach((row, index) => {
|
|
2698
2724
|
const rowId = getResolvedRowId(row, index, undefined, getRowId);
|
|
2699
2725
|
const existingIndex = rowId !== undefined ? indexByRowId.get(rowId) : undefined;
|
|
2700
2726
|
if (existingIndex === undefined) {
|
|
2701
|
-
|
|
2702
|
-
indexByRowId.set(rowId, nextRows.length);
|
|
2703
|
-
}
|
|
2704
|
-
nextRows.push(row);
|
|
2727
|
+
rowsToInsert.push(row);
|
|
2705
2728
|
return;
|
|
2706
2729
|
}
|
|
2707
2730
|
nextRows[existingIndex] = row;
|
|
2708
2731
|
});
|
|
2709
|
-
return nextRows;
|
|
2732
|
+
return capRowsToPageSize([...rowsToInsert, ...nextRows], pageSize);
|
|
2710
2733
|
});
|
|
2711
2734
|
};
|
|
2712
2735
|
};
|
|
@@ -3136,6 +3159,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3136
3159
|
table.addRow = handleAddRow({
|
|
3137
3160
|
setRowsState,
|
|
3138
3161
|
getRowId: resolveRowId,
|
|
3162
|
+
pageSize: statefulTableOptions.state.pagination.pageSize,
|
|
3139
3163
|
});
|
|
3140
3164
|
table.updateRow = handleUpdateRow({
|
|
3141
3165
|
setRowsState,
|
|
@@ -3148,6 +3172,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3148
3172
|
table.upsertRow = handleUpsertRow({
|
|
3149
3173
|
setRowsState,
|
|
3150
3174
|
getRowId: resolveRowId,
|
|
3175
|
+
pageSize: statefulTableOptions.state.pagination.pageSize,
|
|
3151
3176
|
});
|
|
3152
3177
|
table.removeRow = handleRemoveRow({
|
|
3153
3178
|
setRowsState,
|
|
@@ -6299,7 +6324,9 @@ const MRT_NewEntryButton = (_a) => {
|
|
|
6299
6324
|
var _b;
|
|
6300
6325
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
|
6301
6326
|
const { options: { icons: { AddIcon }, localization, }, setNewEntryModal, } = table;
|
|
6302
|
-
const handleOpenNewEntryModal = () => {
|
|
6327
|
+
const handleOpenNewEntryModal = (event) => {
|
|
6328
|
+
// Prevent bubbling to muiTableBodyRowProps onClick (row click handlers)
|
|
6329
|
+
event.stopPropagation();
|
|
6303
6330
|
setNewEntryModal({ open: true });
|
|
6304
6331
|
};
|
|
6305
6332
|
return (jsxRuntime.jsx(Tooltip, { title: (_b = rest === null || rest === void 0 ? void 0 : rest.title) !== null && _b !== void 0 ? _b : localization.newEntry, children: jsxRuntime.jsx(Button, Object.assign({ "aria-label": localization.newEntry, onClick: handleOpenNewEntryModal, size: "small", startIcon: jsxRuntime.jsx(AddIcon, { fontSize: "small" }), variant: "text" }, rest, { title: undefined, children: localization.newEntry })) }));
|
|
@@ -8506,6 +8533,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
|
|
|
8506
8533
|
const [expanded, setExpanded] = react.useState((_k = initialState === null || initialState === void 0 ? void 0 : initialState.expanded) !== null && _k !== void 0 ? _k : {});
|
|
8507
8534
|
const [rowSelection, setRowSelection] = react.useState((_l = initialState === null || initialState === void 0 ? void 0 : initialState.rowSelection) !== null && _l !== void 0 ? _l : {});
|
|
8508
8535
|
const [activeExports, setActiveExports] = react.useState(initialState === null || initialState === void 0 ? void 0 : initialState.activeExports);
|
|
8536
|
+
// Counter that increments on every manual refetch() call, without changing any other state
|
|
8537
|
+
const [refetchIndex, setRefetchIndex] = react.useState(0);
|
|
8538
|
+
const refetch = () => setRefetchIndex((prev) => prev + 1);
|
|
8509
8539
|
// --- Debounced save ---
|
|
8510
8540
|
// saveState is optional — if not provided, do nothing
|
|
8511
8541
|
const debouncedSave = useDebounce.useDebouncedCallback((partial) => {
|
|
@@ -8588,7 +8618,9 @@ const useServerTableState = ({ initialState, saveState, saveDebounceMs = 500, })
|
|
|
8588
8618
|
pagination,
|
|
8589
8619
|
sorting,
|
|
8590
8620
|
columnVisibilityShowTrigger,
|
|
8621
|
+
refetchIndex,
|
|
8591
8622
|
},
|
|
8623
|
+
refetch,
|
|
8592
8624
|
};
|
|
8593
8625
|
};
|
|
8594
8626
|
|
|
@@ -8632,7 +8664,7 @@ const buildInitialExportState = (availableExports, savedActiveExports) => {
|
|
|
8632
8664
|
grouped: false,
|
|
8633
8665
|
});
|
|
8634
8666
|
};
|
|
8635
|
-
const
|
|
8667
|
+
const MaterialReactServerTableInstanceComponent = (_a, ref) => {
|
|
8636
8668
|
var _b, _c;
|
|
8637
8669
|
var { config, loadData, saveState, getAllSelectableRowIds, getTotalRows, onSaveFilters, onDeleteSavedFilter, initialSavedFilters, loadExport, exportPermissions, enableNewEntryButton, actions, deleteRowsFn, editRowFn, enableResetState, resetState, extendColumns } = _a,
|
|
8638
8670
|
// Extra MRT_TableOptions props (e.g. formConfig) passed directly through to useMaterialReactTable
|
|
@@ -8660,7 +8692,7 @@ const MaterialReactServerTableInstance = (_a) => {
|
|
|
8660
8692
|
});
|
|
8661
8693
|
return Object.fromEntries(allowedEntries);
|
|
8662
8694
|
}, [config.availableExports, exportPermissions]);
|
|
8663
|
-
const { tableState, handlers, fetchTrigger } = useServerTableState({
|
|
8695
|
+
const { tableState, handlers, fetchTrigger, refetch } = useServerTableState({
|
|
8664
8696
|
initialState: Object.assign(Object.assign({}, config.initialState), { activeExports: buildInitialExportState(allowedExports, (_b = config.initialState) === null || _b === void 0 ? void 0 : _b.activeExports) }),
|
|
8665
8697
|
saveState,
|
|
8666
8698
|
});
|
|
@@ -8680,6 +8712,9 @@ const MaterialReactServerTableInstance = (_a) => {
|
|
|
8680
8712
|
editRowFn,
|
|
8681
8713
|
onSaveFilters,
|
|
8682
8714
|
onDeleteSavedFilter, initialSavedFilters: initialSavedFilters !== null && initialSavedFilters !== void 0 ? initialSavedFilters : (_c = config.initialState) === null || _c === void 0 ? void 0 : _c.savedFilters, availableExports: hasAvailableExports ? allowedExports : undefined, loadExport: hasAvailableExports ? loadExport : undefined, enableNewEntryButton }, tableOptionsOverrides), handlers));
|
|
8715
|
+
// Lets any code that already has `table` (row actions, deleteRowsFn/editRowFn,
|
|
8716
|
+
// custom cell renderers, etc.) trigger a manual reload without needing a ref.
|
|
8717
|
+
table.refetch = refetch;
|
|
8683
8718
|
const fetchData = react.useCallback((tableInstance) => __awaiter(void 0, void 0, void 0, function* () {
|
|
8684
8719
|
setIsLoading(true);
|
|
8685
8720
|
try {
|
|
@@ -8707,9 +8742,12 @@ const MaterialReactServerTableInstance = (_a) => {
|
|
|
8707
8742
|
fetchTrigger.pagination,
|
|
8708
8743
|
fetchTrigger.sorting,
|
|
8709
8744
|
fetchTrigger.columnVisibilityShowTrigger,
|
|
8745
|
+
fetchTrigger.refetchIndex,
|
|
8710
8746
|
]);
|
|
8747
|
+
react.useImperativeHandle(ref, () => ({ refetch, table }), [refetch, table]);
|
|
8711
8748
|
return jsxRuntime.jsx(MaterialReactTable, { table: table });
|
|
8712
8749
|
};
|
|
8750
|
+
const MaterialReactServerTableInstance = react.forwardRef(MaterialReactServerTableInstanceComponent);
|
|
8713
8751
|
|
|
8714
8752
|
const MaterialReactServerTableSkeleton = () => (jsxRuntime.jsxs(Paper, { "data-testid": "server-table-skeleton", sx: {
|
|
8715
8753
|
display: 'flex',
|
|
@@ -8732,7 +8770,7 @@ const MaterialReactServerTableSkeleton = () => (jsxRuntime.jsxs(Paper, { "data-t
|
|
|
8732
8770
|
px: '1.3rem',
|
|
8733
8771
|
}), children: jsxRuntime.jsxs(Box, { sx: { alignItems: 'center', display: 'flex', gap: '1rem' }, children: [jsxRuntime.jsx(Skeleton, { animation: "wave", height: 36, variant: "rounded", width: 136 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 31, variant: "text", width: 176 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 22, variant: "text", width: 70 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 24, variant: "circular", width: 24 }), jsxRuntime.jsx(Skeleton, { animation: "wave", height: 24, variant: "circular", width: 24 })] }) })] }));
|
|
8734
8772
|
|
|
8735
|
-
const
|
|
8773
|
+
const MaterialReactServerTableComponent = (_a, ref) => {
|
|
8736
8774
|
var { loadConfig, saveState, localization } = _a, instanceProps = __rest(_a, ["loadConfig", "saveState", "localization"]);
|
|
8737
8775
|
const mergedLocalization = Object.assign(Object.assign({}, MRT_Localization_HR), localization);
|
|
8738
8776
|
const [configLoading, setConfigLoading] = react.useState(true);
|
|
@@ -8768,8 +8806,9 @@ const MaterialReactServerTable = (_a) => {
|
|
|
8768
8806
|
if (!config) {
|
|
8769
8807
|
return (jsxRuntime.jsx(MaterialReactServerTableError, { description: mergedLocalization.serverTableErrorMessage }));
|
|
8770
8808
|
}
|
|
8771
|
-
return (jsxRuntime.jsx(MaterialReactServerTableInstance, Object.assign({ config: config, saveState: saveState }, instanceProps)));
|
|
8809
|
+
return (jsxRuntime.jsx(MaterialReactServerTableInstance, Object.assign({ ref: ref, config: config, saveState: saveState }, instanceProps)));
|
|
8772
8810
|
};
|
|
8811
|
+
const MaterialReactServerTable = react.forwardRef(MaterialReactServerTableComponent);
|
|
8773
8812
|
|
|
8774
8813
|
const MRT_ColumnPinningButtons = (_a) => {
|
|
8775
8814
|
var { column, table } = _a, rest = __rest(_a, ["column", "table"]);
|