@cutting/material-react-table 4.0.3 → 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 +32 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +32 -2
- 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/utils/highlight.utils.ts +52 -0
package/dist/index.esm.js
CHANGED
|
@@ -5,7 +5,6 @@ import { compareItems, rankItem, rankings } from '@tanstack/match-sorter-utils';
|
|
|
5
5
|
import { sortingFns, flexRender as flexRender$1, createRow as createRow$1, aggregationFns, filterFns, getSortedRowModel, getPaginationRowModel, getGroupedRowModel, getFilteredRowModel, getFacetedUniqueValues, getFacetedRowModel, getFacetedMinMaxValues, getExpandedRowModel, getCoreRowModel, useReactTable } from '@tanstack/react-table';
|
|
6
6
|
import { defaultRangeExtractor, useVirtualizer } from '@tanstack/react-virtual';
|
|
7
7
|
import { alpha, darken, lighten, useTheme } from '@mui/material/styles';
|
|
8
|
-
import highlightWords from 'highlight-words';
|
|
9
8
|
import { debounce } from '@mui/material/utils';
|
|
10
9
|
import { DatePicker } from '@mui/x-date-pickers/DatePicker';
|
|
11
10
|
import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
|
|
@@ -685,6 +684,37 @@ const MRT_EditCellTextField = (_a) => {
|
|
|
685
684
|
}) })));
|
|
686
685
|
};
|
|
687
686
|
|
|
687
|
+
const escapeRegExp = (term) => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
|
|
688
|
+
const termsToRegExpString = (terms) => terms.replace(/\s{2,}/g, ' ').split(' ').join('|');
|
|
689
|
+
const buildRegExp = (terms, matchExactly) => {
|
|
690
|
+
const fromString = /^([/~@;%#'])(.*?)\1([gimsuy]*)$/.exec(terms);
|
|
691
|
+
if (fromString) {
|
|
692
|
+
return new RegExp(fromString[2], fromString[3]);
|
|
693
|
+
}
|
|
694
|
+
const escaped = escapeRegExp(terms.trim());
|
|
695
|
+
const pattern = matchExactly ? escaped : termsToRegExpString(escaped);
|
|
696
|
+
return new RegExp(`(${pattern})`, 'ig');
|
|
697
|
+
};
|
|
698
|
+
let uidCounter = 0;
|
|
699
|
+
const uid = () => `mrt-hl-${(uidCounter += 1).toString(36)}`;
|
|
700
|
+
const highlightWords = ({ matchExactly = false, query, text, }) => {
|
|
701
|
+
const safeQuery = typeof query === 'string' ? query.trim() : query;
|
|
702
|
+
if (safeQuery === '') {
|
|
703
|
+
return [{ key: uid(), match: false, text }];
|
|
704
|
+
}
|
|
705
|
+
const searchRegexp = buildRegExp(query, matchExactly);
|
|
706
|
+
return text
|
|
707
|
+
.split(searchRegexp)
|
|
708
|
+
.filter((str) => str.length > 0)
|
|
709
|
+
.map((str) => ({
|
|
710
|
+
key: uid(),
|
|
711
|
+
match: matchExactly
|
|
712
|
+
? str.toLowerCase() === safeQuery.toLowerCase()
|
|
713
|
+
: searchRegexp.test(str),
|
|
714
|
+
text: str,
|
|
715
|
+
}));
|
|
716
|
+
};
|
|
717
|
+
|
|
688
718
|
const allowedTypes = ['string', 'number'];
|
|
689
719
|
const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowIndex, table, }) => {
|
|
690
720
|
var _a, _b, _c;
|
|
@@ -728,7 +758,7 @@ const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowInde
|
|
|
728
758
|
(globalFilter &&
|
|
729
759
|
allowedTypes.includes(typeof globalFilter) &&
|
|
730
760
|
column.getCanGlobalFilter()))) {
|
|
731
|
-
const chunks = highlightWords
|
|
761
|
+
const chunks = highlightWords({
|
|
732
762
|
matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
|
733
763
|
query: ((_a = filterValue !== null && filterValue !== void 0 ? filterValue : globalFilter) !== null && _a !== void 0 ? _a : '').toString(),
|
|
734
764
|
text: renderedCellValue === null || renderedCellValue === void 0 ? void 0 : renderedCellValue.toString(),
|