material-react-table 0.6.0 → 0.6.1
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/filtersFNs.d.ts +8 -4
- package/dist/material-react-table.cjs.development.js +27 -13
- 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 +28 -14
- package/dist/material-react-table.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/filtersFNs.ts +3 -2
- package/src/useMRT.tsx +13 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useState, useMemo, useContext, createContext, Fragment, useRef, useEffect } from 'react';
|
|
1
|
+
import React, { useState, useMemo, useCallback, useContext, createContext, Fragment, useRef, useEffect } from 'react';
|
|
2
2
|
import { useTable, useFilters, useGlobalFilter, useGroupBy, useSortBy, useExpanded, usePagination, useRowSelect, useResizeColumns, useFlexLayout, useAsyncDebounce } from 'react-table';
|
|
3
3
|
import { matchSorter } from 'match-sorter';
|
|
4
4
|
import { Menu, MenuItem, TextField, InputAdornment, Tooltip, IconButton, Chip, FormControlLabel, Switch, Box, Button, Divider, TableCell, TableSortLabel, Collapse, Skeleton, Checkbox, TableRow, TableHead, alpha, TableBody, TableFooter, Table, TablePagination, useMediaQuery, Alert, Toolbar, TableContainer, Paper, LinearProgress } from '@mui/material';
|
|
@@ -97,6 +97,21 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
97
97
|
return target;
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
+
var fuzzySearchFN = function fuzzySearchFN(rows, columnIds, filterValue) {
|
|
101
|
+
return matchSorter(rows, filterValue.toString().trim(), {
|
|
102
|
+
keys: columnIds.map(function (c) {
|
|
103
|
+
return "values." + c;
|
|
104
|
+
}),
|
|
105
|
+
sorter: function sorter(rankedItems) {
|
|
106
|
+
return rankedItems;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
fuzzySearchFN.autoRemove = function (val) {
|
|
112
|
+
return !val;
|
|
113
|
+
};
|
|
114
|
+
|
|
100
115
|
var fuzzyFilterFN = function fuzzyFilterFN(rows, id, filterValue) {
|
|
101
116
|
return matchSorter(rows, filterValue.toString().trim(), {
|
|
102
117
|
keys: ["values." + id],
|
|
@@ -204,10 +219,11 @@ var defaultFilterFNs = {
|
|
|
204
219
|
contains: containsFilterFN,
|
|
205
220
|
empty: emptyFilterFN,
|
|
206
221
|
endsWith: endsWithFilterFN,
|
|
207
|
-
greaterThan: greaterThanFilterFN,
|
|
208
|
-
lessThan: lessThanFilterFN,
|
|
209
222
|
equals: equalsFilterFN,
|
|
210
223
|
fuzzy: fuzzyFilterFN,
|
|
224
|
+
globalFuzzy: fuzzySearchFN,
|
|
225
|
+
greaterThan: greaterThanFilterFN,
|
|
226
|
+
lessThan: lessThanFilterFN,
|
|
211
227
|
notEmpty: notEmptyFilterFN,
|
|
212
228
|
notEquals: notEqualsFilterFN,
|
|
213
229
|
startsWith: startsWithFilterFN
|
|
@@ -218,7 +234,7 @@ var MaterialReactTableContext = /*#__PURE__*/function () {
|
|
|
218
234
|
}();
|
|
219
235
|
|
|
220
236
|
var MaterialReactTableProvider = function MaterialReactTableProvider(props) {
|
|
221
|
-
var _props$initialState$d, _props$initialState, _props$initialState$f, _props$initialState2, _props$initialState$s, _props$initialState3, _props$initialState$s2, _props$initialState4;
|
|
237
|
+
var _props$initialState$d, _props$initialState, _props$initialState$f, _props$initialState2, _props$initialState$s, _props$initialState3, _props$initialState$s2, _props$initialState4, _props$globalFilter;
|
|
222
238
|
|
|
223
239
|
var hooks = [useFilters, useGlobalFilter, useGroupBy, useSortBy, useExpanded, usePagination, useRowSelect];
|
|
224
240
|
if (props.enableColumnResizing) hooks.unshift(useResizeColumns, useFlexLayout);
|
|
@@ -246,8 +262,7 @@ var MaterialReactTableProvider = function MaterialReactTableProvider(props) {
|
|
|
246
262
|
var filterTypes = useMemo(function () {
|
|
247
263
|
return _extends({}, defaultFilterFNs, props.filterTypes);
|
|
248
264
|
}, [props.filterTypes]);
|
|
249
|
-
|
|
250
|
-
var getInitialFilterTypeState = function getInitialFilterTypeState() {
|
|
265
|
+
var findLowestLevelCols = useCallback(function () {
|
|
251
266
|
var lowestLevelColumns = props.columns;
|
|
252
267
|
var currentCols = props.columns;
|
|
253
268
|
|
|
@@ -269,24 +284,23 @@ var MaterialReactTableProvider = function MaterialReactTableProvider(props) {
|
|
|
269
284
|
currentCols = nextCols;
|
|
270
285
|
}
|
|
271
286
|
|
|
272
|
-
|
|
287
|
+
return lowestLevelColumns.filter(function (col) {
|
|
273
288
|
return !col.columns;
|
|
274
289
|
});
|
|
275
|
-
|
|
290
|
+
}, [props.columns]);
|
|
291
|
+
|
|
292
|
+
var _useState6 = useState(function () {
|
|
293
|
+
return Object.assign.apply(Object, [{}].concat(findLowestLevelCols().map(function (c) {
|
|
276
294
|
var _ref, _c$filter, _props$initialState5, _props$initialState5$, _ref2;
|
|
277
295
|
|
|
278
296
|
return _ref2 = {}, _ref2[c.accessor] = (_ref = (_c$filter = c.filter) != null ? _c$filter : props == null ? void 0 : (_props$initialState5 = props.initialState) == null ? void 0 : (_props$initialState5$ = _props$initialState5.filters) == null ? void 0 : _props$initialState5$[c.accessor]) != null ? _ref : !!c.filterSelectOptions ? 'equals' : 'fuzzy', _ref2;
|
|
279
297
|
})));
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
var _useState6 = useState(function () {
|
|
283
|
-
return getInitialFilterTypeState();
|
|
284
298
|
}),
|
|
285
299
|
currentFilterTypes = _useState6[0],
|
|
286
300
|
setCurrentFilterTypes = _useState6[1];
|
|
287
301
|
|
|
288
302
|
var columns = useMemo(function () {
|
|
289
|
-
return
|
|
303
|
+
return findLowestLevelCols().map(function (column) {
|
|
290
304
|
column.filter = filterTypes[currentFilterTypes[column.accessor]];
|
|
291
305
|
return column;
|
|
292
306
|
});
|
|
@@ -295,7 +309,7 @@ var MaterialReactTableProvider = function MaterialReactTableProvider(props) {
|
|
|
295
309
|
columns: columns,
|
|
296
310
|
// @ts-ignore
|
|
297
311
|
filterTypes: filterTypes,
|
|
298
|
-
|
|
312
|
+
globalFilter: (_props$globalFilter = props.globalFilter) != null ? _props$globalFilter : 'globalFuzzy',
|
|
299
313
|
useControlledState: function useControlledState(state) {
|
|
300
314
|
return useMemo(function () {
|
|
301
315
|
return _extends({}, state, {
|