@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.js
CHANGED
|
@@ -7,7 +7,6 @@ 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');
|
|
@@ -687,6 +686,37 @@ const MRT_EditCellTextField = (_a) => {
|
|
|
687
686
|
}) })));
|
|
688
687
|
};
|
|
689
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
|
+
|
|
690
720
|
const allowedTypes = ['string', 'number'];
|
|
691
721
|
const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowIndex, table, }) => {
|
|
692
722
|
var _a, _b, _c;
|
|
@@ -730,7 +760,7 @@ const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowInde
|
|
|
730
760
|
(globalFilter &&
|
|
731
761
|
allowedTypes.includes(typeof globalFilter) &&
|
|
732
762
|
column.getCanGlobalFilter()))) {
|
|
733
|
-
const chunks = highlightWords
|
|
763
|
+
const chunks = highlightWords({
|
|
734
764
|
matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
|
735
765
|
query: ((_a = filterValue !== null && filterValue !== void 0 ? filterValue : globalFilter) !== null && _a !== void 0 ? _a : '').toString(),
|
|
736
766
|
text: renderedCellValue === null || renderedCellValue === void 0 ? void 0 : renderedCellValue.toString(),
|