material-react-table 0.7.3 → 0.7.4
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/MaterialReactTable.d.ts +3 -1
- package/dist/material-react-table.cjs.development.js +66 -16
- package/dist/material-react-table.cjs.development.js.map +1 -1
- package/dist/material-react-table.cjs.production.min.js +1 -1
- package/dist/material-react-table.cjs.production.min.js.map +1 -1
- package/dist/material-react-table.esm.js +66 -16
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +5 -5
- package/src/MaterialReactTable.tsx +4 -0
- package/src/table/MRT_TableRoot.tsx +67 -13
|
@@ -2872,7 +2872,7 @@ var createDisplayColumn = function createDisplayColumn(table, column) {
|
|
|
2872
2872
|
};
|
|
2873
2873
|
|
|
2874
2874
|
var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
2875
|
-
var
|
|
2875
|
+
var _initialState$current, _initialState$current2, _initialState$isDense, _initialState$isFullS, _initialState$showFil, _initialState$showGlo, _initialState$paginat, _initialState$paginat2, _initialState$paginat3, _initialState$paginat4, _initialState$paginat5, _initialState$paginat6, _props$globalFilterTy;
|
|
2876
2876
|
|
|
2877
2877
|
var _useState = useState(props.idPrefix),
|
|
2878
2878
|
idPrefix = _useState[0],
|
|
@@ -2883,46 +2883,69 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
2883
2883
|
|
|
2884
2884
|
return setIdPrefix((_props$idPrefix = props.idPrefix) != null ? _props$idPrefix : Math.random().toString(36).substring(2, 9));
|
|
2885
2885
|
}, [props.idPrefix]);
|
|
2886
|
+
var initialState = useMemo(function () {
|
|
2887
|
+
if (!props.enablePersistentState || !props.idPrefix) {
|
|
2888
|
+
return props.initialState;
|
|
2889
|
+
}
|
|
2890
|
+
|
|
2891
|
+
if (typeof window === 'undefined') {
|
|
2892
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
2893
|
+
console.error('The MRT Persistent Table State feature is not supported if using SSR, but you can wrap your <MaterialReactTable /> in a MUI <NoSsr> tags to let it work');
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
return props.initialState;
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
var storedState = props.persistentStateMode === 'localStorage' ? localStorage.getItem("mrt-" + idPrefix + "-table-state") : props.persistentStateMode === 'sessionStorage' ? sessionStorage.getItem("mrt-" + idPrefix + "-table-state") : '{}';
|
|
2900
|
+
|
|
2901
|
+
if (storedState) {
|
|
2902
|
+
var parsedState = JSON.parse(storedState);
|
|
2903
|
+
|
|
2904
|
+
if (parsedState) {
|
|
2905
|
+
return _extends({}, props.initialState, parsedState);
|
|
2906
|
+
}
|
|
2907
|
+
}
|
|
2908
|
+
|
|
2909
|
+
return props.initialState;
|
|
2910
|
+
}, []);
|
|
2886
2911
|
|
|
2887
|
-
var _useState2 = useState((
|
|
2912
|
+
var _useState2 = useState((_initialState$current = initialState == null ? void 0 : initialState.currentEditingCell) != null ? _initialState$current : null),
|
|
2888
2913
|
currentEditingCell = _useState2[0],
|
|
2889
2914
|
setCurrentEditingCell = _useState2[1];
|
|
2890
2915
|
|
|
2891
|
-
var _useState3 = useState((
|
|
2916
|
+
var _useState3 = useState((_initialState$current2 = initialState == null ? void 0 : initialState.currentEditingRow) != null ? _initialState$current2 : null),
|
|
2892
2917
|
currentEditingRow = _useState3[0],
|
|
2893
2918
|
setCurrentEditingRow = _useState3[1];
|
|
2894
2919
|
|
|
2895
|
-
var _useState4 = useState((
|
|
2920
|
+
var _useState4 = useState((_initialState$isDense = initialState == null ? void 0 : initialState.isDensePadding) != null ? _initialState$isDense : false),
|
|
2896
2921
|
isDensePadding = _useState4[0],
|
|
2897
2922
|
setIsDensePadding = _useState4[1];
|
|
2898
2923
|
|
|
2899
|
-
var _useState5 = useState((
|
|
2924
|
+
var _useState5 = useState((_initialState$isFullS = initialState == null ? void 0 : initialState.isFullScreen) != null ? _initialState$isFullS : false),
|
|
2900
2925
|
isFullScreen = _useState5[0],
|
|
2901
2926
|
setIsFullScreen = _useState5[1];
|
|
2902
2927
|
|
|
2903
|
-
var _useState6 = useState((
|
|
2928
|
+
var _useState6 = useState((_initialState$showFil = initialState == null ? void 0 : initialState.showFilters) != null ? _initialState$showFil : false),
|
|
2904
2929
|
showFilters = _useState6[0],
|
|
2905
2930
|
setShowFilters = _useState6[1];
|
|
2906
2931
|
|
|
2907
|
-
var _useState7 = useState((
|
|
2932
|
+
var _useState7 = useState((_initialState$showGlo = initialState == null ? void 0 : initialState.showGlobalFilter) != null ? _initialState$showGlo : false),
|
|
2908
2933
|
showGlobalFilter = _useState7[0],
|
|
2909
2934
|
setShowGlobalFilter = _useState7[1];
|
|
2910
2935
|
|
|
2911
2936
|
var _useState8 = useState({
|
|
2912
|
-
pageIndex: (
|
|
2913
|
-
pageSize: (
|
|
2914
|
-
pageCount: (
|
|
2937
|
+
pageIndex: (_initialState$paginat = initialState == null ? void 0 : (_initialState$paginat2 = initialState.pagination) == null ? void 0 : _initialState$paginat2.pageIndex) != null ? _initialState$paginat : 0,
|
|
2938
|
+
pageSize: (_initialState$paginat3 = initialState == null ? void 0 : (_initialState$paginat4 = initialState.pagination) == null ? void 0 : _initialState$paginat4.pageSize) != null ? _initialState$paginat3 : 10,
|
|
2939
|
+
pageCount: (_initialState$paginat5 = initialState == null ? void 0 : (_initialState$paginat6 = initialState.pagination) == null ? void 0 : _initialState$paginat6.pageCount) != null ? _initialState$paginat5 : -1
|
|
2915
2940
|
}),
|
|
2916
2941
|
pagination = _useState8[0],
|
|
2917
2942
|
setPagination = _useState8[1];
|
|
2918
2943
|
|
|
2919
2944
|
var _useState9 = useState(function () {
|
|
2920
2945
|
return Object.assign.apply(Object, [{}].concat(getAllLeafColumnDefs(props.columns).map(function (c) {
|
|
2921
|
-
var _ref, _c$filter,
|
|
2946
|
+
var _ref, _c$filter, _initialState$current3, _c$filterSelectOption, _ref2;
|
|
2922
2947
|
|
|
2923
|
-
return _ref2 = {}, _ref2[c.id] = (_ref = (_c$filter = c.filter) != null ? _c$filter :
|
|
2924
|
-
return cf.id === c.id;
|
|
2925
|
-
})) != null ? _ref : !!((_c$filterSelectOption = c.filterSelectOptions) != null && _c$filterSelectOption.length) ? MRT_FILTER_TYPE.EQUALS : MRT_FILTER_TYPE.BEST_MATCH, _ref2;
|
|
2948
|
+
return _ref2 = {}, _ref2[c.id] = (_ref = (_c$filter = c.filter) != null ? _c$filter : initialState == null ? void 0 : (_initialState$current3 = initialState.currentFilterTypes) == null ? void 0 : _initialState$current3[c.id]) != null ? _ref : !!((_c$filterSelectOption = c.filterSelectOptions) != null && _c$filterSelectOption.length) ? MRT_FILTER_TYPE.EQUALS : MRT_FILTER_TYPE.BEST_MATCH, _ref2;
|
|
2926
2949
|
})));
|
|
2927
2950
|
}),
|
|
2928
2951
|
currentFilterTypes = _useState9[0],
|
|
@@ -3031,7 +3054,6 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
3031
3054
|
return originalRow.subRows;
|
|
3032
3055
|
},
|
|
3033
3056
|
globalFilterType: currentGlobalFilterType,
|
|
3034
|
-
idPrefix: idPrefix,
|
|
3035
3057
|
onPaginationChange: function onPaginationChange(updater) {
|
|
3036
3058
|
return setPagination(function (old) {
|
|
3037
3059
|
return functionalUpdate(updater, old);
|
|
@@ -3040,6 +3062,9 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
3040
3062
|
}, props, {
|
|
3041
3063
|
columns: columns,
|
|
3042
3064
|
data: data,
|
|
3065
|
+
idPrefix: idPrefix,
|
|
3066
|
+
//@ts-ignore
|
|
3067
|
+
initialState: initialState,
|
|
3043
3068
|
state: _extends({
|
|
3044
3069
|
currentEditingCell: currentEditingCell,
|
|
3045
3070
|
currentEditingRow: currentEditingRow,
|
|
@@ -3065,6 +3090,28 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
3065
3090
|
setShowGlobalFilter: setShowGlobalFilter
|
|
3066
3091
|
});
|
|
3067
3092
|
|
|
3093
|
+
useEffect(function () {
|
|
3094
|
+
if (typeof window === 'undefined' || !props.enablePersistentState) {
|
|
3095
|
+
return;
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
if (!props.idPrefix && process.env.NODE_ENV !== 'production') {
|
|
3099
|
+
console.warn('a unique idPrefix prop is required for persistent table state to work');
|
|
3100
|
+
return;
|
|
3101
|
+
}
|
|
3102
|
+
|
|
3103
|
+
var itemArgs = ["mrt-" + idPrefix + "-table-state", JSON.stringify(tableInstance.getState())];
|
|
3104
|
+
|
|
3105
|
+
if (props.persistentStateMode === 'localStorage') {
|
|
3106
|
+
var _localStorage;
|
|
3107
|
+
|
|
3108
|
+
(_localStorage = localStorage).setItem.apply(_localStorage, itemArgs);
|
|
3109
|
+
} else if (props.persistentStateMode === 'sessionStorage') {
|
|
3110
|
+
var _sessionStorage;
|
|
3111
|
+
|
|
3112
|
+
(_sessionStorage = sessionStorage).setItem.apply(_sessionStorage, itemArgs);
|
|
3113
|
+
}
|
|
3114
|
+
}, [props.enablePersistentState, props.idPrefix, props.persistentStateMode, tableInstance]);
|
|
3068
3115
|
return React.createElement(React.Fragment, null, React.createElement(Dialog, {
|
|
3069
3116
|
TransitionComponent: Grow,
|
|
3070
3117
|
PaperComponent: Box,
|
|
@@ -3083,7 +3130,7 @@ var MRT_TableRoot = function MRT_TableRoot(props) {
|
|
|
3083
3130
|
}));
|
|
3084
3131
|
};
|
|
3085
3132
|
|
|
3086
|
-
var _excluded$5 = ["autoResetExpanded", "columnResizeMode", "editingMode", "enableColumnActions", "enableColumnFilters", "enableColumnResizing", "enableDensePaddingToggle", "enableExpandAll", "enableFilters", "enableFullScreenToggle", "enableGlobalFilter", "enableHiding", "enableMultiRowSelection", "enablePagination", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarBottom", "enableToolbarInternalActions", "enableToolbarTop", "icons", "localization", "positionActionsColumn", "positionPagination", "positionToolbarActions", "positionToolbarAlertBanner"];
|
|
3133
|
+
var _excluded$5 = ["autoResetExpanded", "columnResizeMode", "editingMode", "enableColumnActions", "enableColumnFilters", "enableColumnResizing", "enableDensePaddingToggle", "enableExpandAll", "enableFilters", "enableFullScreenToggle", "enableGlobalFilter", "enableHiding", "enableMultiRowSelection", "enablePagination", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarBottom", "enableToolbarInternalActions", "enableToolbarTop", "icons", "localization", "persistentStateMode", "positionActionsColumn", "positionPagination", "positionToolbarActions", "positionToolbarAlertBanner"];
|
|
3087
3134
|
var MaterialReactTable = (function (_ref) {
|
|
3088
3135
|
var _ref$autoResetExpande = _ref.autoResetExpanded,
|
|
3089
3136
|
autoResetExpanded = _ref$autoResetExpande === void 0 ? false : _ref$autoResetExpande,
|
|
@@ -3131,6 +3178,8 @@ var MaterialReactTable = (function (_ref) {
|
|
|
3131
3178
|
enableToolbarTop = _ref$enableToolbarTop === void 0 ? true : _ref$enableToolbarTop,
|
|
3132
3179
|
icons = _ref.icons,
|
|
3133
3180
|
localization = _ref.localization,
|
|
3181
|
+
_ref$persistentStateM = _ref.persistentStateMode,
|
|
3182
|
+
persistentStateMode = _ref$persistentStateM === void 0 ? 'sessionStorage' : _ref$persistentStateM,
|
|
3134
3183
|
_ref$positionActionsC = _ref.positionActionsColumn,
|
|
3135
3184
|
positionActionsColumn = _ref$positionActionsC === void 0 ? 'first' : _ref$positionActionsC,
|
|
3136
3185
|
_ref$positionPaginati = _ref.positionPagination,
|
|
@@ -3166,6 +3215,7 @@ var MaterialReactTable = (function (_ref) {
|
|
|
3166
3215
|
enableToolbarTop: enableToolbarTop,
|
|
3167
3216
|
icons: _extends({}, MRT_Default_Icons, icons),
|
|
3168
3217
|
localization: _extends({}, MRT_DefaultLocalization_EN, localization),
|
|
3218
|
+
persistentStateMode: persistentStateMode,
|
|
3169
3219
|
positionActionsColumn: positionActionsColumn,
|
|
3170
3220
|
positionPagination: positionPagination,
|
|
3171
3221
|
positionToolbarActions: positionToolbarActions,
|