@cutting/material-react-table 4.0.2 → 4.0.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/index.esm.js +33 -4
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +36 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/MaterialReactTable.smoke.test.tsx +19 -0
- package/src/components/body/MRT_TableBodyCellValue.tsx +2 -2
- package/src/components/toolbar/MRT_BottomToolbar.tsx +1 -2
- package/src/components/toolbar/MRT_TablePagination.tsx +1 -2
- package/src/components/toolbar/MRT_TopToolbar.tsx +1 -2
- package/src/utils/highlight.utils.ts +52 -0
package/dist/index.js
CHANGED
|
@@ -7,13 +7,11 @@ var matchSorterUtils = require('@tanstack/match-sorter-utils');
|
|
|
7
7
|
var reactTable = require('@tanstack/react-table');
|
|
8
8
|
var reactVirtual = require('@tanstack/react-virtual');
|
|
9
9
|
var styles = require('@mui/material/styles');
|
|
10
|
-
var highlightWords = require('highlight-words');
|
|
11
10
|
var utils = require('@mui/material/utils');
|
|
12
11
|
var DatePicker = require('@mui/x-date-pickers/DatePicker');
|
|
13
12
|
var DateTimePicker = require('@mui/x-date-pickers/DateTimePicker');
|
|
14
13
|
var TimePicker = require('@mui/x-date-pickers/TimePicker');
|
|
15
14
|
var iconsMaterial = require('@mui/icons-material');
|
|
16
|
-
var useMediaQuery = require('@mui/material/useMediaQuery');
|
|
17
15
|
|
|
18
16
|
/******************************************************************************
|
|
19
17
|
Copyright (c) Microsoft Corporation.
|
|
@@ -688,6 +686,37 @@ const MRT_EditCellTextField = (_a) => {
|
|
|
688
686
|
}) })));
|
|
689
687
|
};
|
|
690
688
|
|
|
689
|
+
const escapeRegExp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
|
|
690
|
+
const termsToRegExpString = (terms) => terms.replace(/\s{2,}/g, ' ').split(' ').join('|');
|
|
691
|
+
const buildRegExp = (terms, matchExactly) => {
|
|
692
|
+
const fromString = /^([/~@;%#'])(.*?)\1([gimsuy]*)$/.exec(terms);
|
|
693
|
+
if (fromString) {
|
|
694
|
+
return new RegExp(fromString[2], fromString[3]);
|
|
695
|
+
}
|
|
696
|
+
const escaped = escapeRegExp(terms.trim());
|
|
697
|
+
const pattern = matchExactly ? escaped : termsToRegExpString(escaped);
|
|
698
|
+
return new RegExp(`(${pattern})`, 'ig');
|
|
699
|
+
};
|
|
700
|
+
let uidCounter = 0;
|
|
701
|
+
const uid = () => `mrt-hl-${(uidCounter += 1).toString(36)}`;
|
|
702
|
+
const highlightWords = ({ matchExactly = false, query, text, }) => {
|
|
703
|
+
const safeQuery = typeof query === 'string' ? query.trim() : query;
|
|
704
|
+
if (safeQuery === '') {
|
|
705
|
+
return [{ key: uid(), match: false, text }];
|
|
706
|
+
}
|
|
707
|
+
const searchRegexp = buildRegExp(query, matchExactly);
|
|
708
|
+
return text
|
|
709
|
+
.split(searchRegexp)
|
|
710
|
+
.filter((str) => str.length > 0)
|
|
711
|
+
.map((str) => ({
|
|
712
|
+
key: uid(),
|
|
713
|
+
match: matchExactly
|
|
714
|
+
? str.toLowerCase() === safeQuery.toLowerCase()
|
|
715
|
+
: searchRegexp.test(str),
|
|
716
|
+
text: str,
|
|
717
|
+
}));
|
|
718
|
+
};
|
|
719
|
+
|
|
691
720
|
const allowedTypes = ['string', 'number'];
|
|
692
721
|
const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowIndex, table, }) => {
|
|
693
722
|
var _a, _b, _c;
|
|
@@ -731,7 +760,7 @@ const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowInde
|
|
|
731
760
|
(globalFilter &&
|
|
732
761
|
allowedTypes.includes(typeof globalFilter) &&
|
|
733
762
|
column.getCanGlobalFilter()))) {
|
|
734
|
-
const chunks = highlightWords
|
|
763
|
+
const chunks = highlightWords({
|
|
735
764
|
matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
|
736
765
|
query: ((_a = filterValue !== null && filterValue !== void 0 ? filterValue : globalFilter) !== null && _a !== void 0 ? _a : '').toString(),
|
|
737
766
|
text: renderedCellValue === null || renderedCellValue === void 0 ? void 0 : renderedCellValue.toString(),
|
|
@@ -3910,7 +3939,7 @@ const defaultRowsPerPage = [5, 10, 15, 20, 25, 30, 50, 100];
|
|
|
3910
3939
|
const MRT_TablePagination = (_a) => {
|
|
3911
3940
|
var { position = 'bottom', table } = _a, rest = __rest(_a, ["position", "table"]);
|
|
3912
3941
|
const theme = styles.useTheme();
|
|
3913
|
-
const isMobile = useMediaQuery('(max-width: 720px)');
|
|
3942
|
+
const isMobile = material.useMediaQuery('(max-width: 720px)');
|
|
3914
3943
|
const { getState, options: { enableToolbarInternalActions, icons: { ChevronLeftIcon, ChevronRightIcon, FirstPageIcon, LastPageIcon }, id, localization, muiPaginationProps, paginationDisplayMode, }, } = table;
|
|
3915
3944
|
const { pagination: { pageIndex = 0, pageSize = 10 }, } = getState();
|
|
3916
3945
|
const paginationProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiPaginationProps, {
|
|
@@ -3991,7 +4020,7 @@ const MRT_BottomToolbar = (_a) => {
|
|
|
3991
4020
|
var { table } = _a, rest = __rest(_a, ["table"]);
|
|
3992
4021
|
const { getState, options: { enablePagination, muiBottomToolbarProps, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderBottomToolbarCustomActions, }, refs: { bottomToolbarRef }, } = table;
|
|
3993
4022
|
const { isFullScreen } = getState();
|
|
3994
|
-
const isMobile = useMediaQuery('(max-width:720px)');
|
|
4023
|
+
const isMobile = material.useMediaQuery('(max-width:720px)');
|
|
3995
4024
|
const toolbarProps = Object.assign(Object.assign({}, parseFromValuesOrFunc(muiBottomToolbarProps, { table })), rest);
|
|
3996
4025
|
const stackAlertBanner = isMobile || !!renderBottomToolbarCustomActions;
|
|
3997
4026
|
return (jsxRuntime.jsxs(material.Box, Object.assign({}, toolbarProps, { ref: (node) => {
|
|
@@ -4036,8 +4065,8 @@ const MRT_TopToolbar = ({ table, }) => {
|
|
|
4036
4065
|
var _a;
|
|
4037
4066
|
const { getState, options: { enableGlobalFilter, enablePagination, enableToolbarInternalActions, muiTopToolbarProps, positionGlobalFilter, positionPagination, positionToolbarAlertBanner, positionToolbarDropZone, renderTopToolbarCustomActions, }, refs: { topToolbarRef }, } = table;
|
|
4038
4067
|
const { isFullScreen, showGlobalFilter } = getState();
|
|
4039
|
-
const isMobile = useMediaQuery('(max-width:720px)');
|
|
4040
|
-
const isTablet = useMediaQuery('(max-width:1024px)');
|
|
4068
|
+
const isMobile = material.useMediaQuery('(max-width:720px)');
|
|
4069
|
+
const isTablet = material.useMediaQuery('(max-width:1024px)');
|
|
4041
4070
|
const toolbarProps = parseFromValuesOrFunc(muiTopToolbarProps, { table });
|
|
4042
4071
|
const stackAlertBanner = isMobile ||
|
|
4043
4072
|
!!renderTopToolbarCustomActions ||
|