@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.esm.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
|
-
import { Tooltip, Button, TextField, MenuItem, Box, TableCell, Skeleton, TableRow, Collapse, TableBody, Typography, IconButton, CircularProgress, FormControlLabel, Switch, Menu, Divider, ListItemIcon, TableFooter, Radio, Checkbox, Stack, Chip, Alert, AlertTitle, InputAdornment, Autocomplete, Slider, FormHelperText, Grow, Popover, Badge, TableSortLabel, TableHead, LinearProgress, InputLabel, Select, Pagination, PaginationItem, Fade, Dialog, DialogTitle, DialogContent, DialogActions, Table, TableContainer, Paper } from '@mui/material';
|
|
2
|
+
import { Tooltip, Button, TextField, MenuItem, Box, TableCell, Skeleton, TableRow, Collapse, TableBody, Typography, IconButton, CircularProgress, FormControlLabel, Switch, Menu, Divider, ListItemIcon, TableFooter, Radio, Checkbox, Stack, Chip, Alert, AlertTitle, InputAdornment, Autocomplete, Slider, FormHelperText, Grow, Popover, Badge, TableSortLabel, TableHead, LinearProgress, useMediaQuery, InputLabel, Select, Pagination, PaginationItem, Fade, Dialog, DialogTitle, DialogContent, DialogActions, Table, TableContainer, Paper } from '@mui/material';
|
|
3
3
|
import { useMemo, useCallback, useState, memo, useEffect, useRef, Fragment as Fragment$1, useId, useReducer, useLayoutEffect } from 'react';
|
|
4
4
|
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';
|
|
12
11
|
import { TimePicker } from '@mui/x-date-pickers/TimePicker';
|
|
13
12
|
import { VisibilityOff, ViewColumn, SyncAlt, Sort, SearchOff, Search, Save, RestartAlt, PushPin, MoreVert, MoreHoriz, LastPage, KeyboardDoubleArrowDown, Fullscreen, FullscreenExit, FirstPage, FilterListOff, FilterList, FilterAlt, ExpandMore, Edit, DynamicFeed, DragHandle, DensitySmall, DensityMedium, DensityLarge, ContentCopy, Close, ClearAll, ChevronRight, ChevronLeft, Cancel, ArrowRight, ArrowDownward } from '@mui/icons-material';
|
|
14
|
-
import useMediaQuery from '@mui/material/useMediaQuery';
|
|
15
13
|
|
|
16
14
|
/******************************************************************************
|
|
17
15
|
Copyright (c) Microsoft Corporation.
|
|
@@ -686,6 +684,37 @@ const MRT_EditCellTextField = (_a) => {
|
|
|
686
684
|
}) })));
|
|
687
685
|
};
|
|
688
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
|
+
|
|
689
718
|
const allowedTypes = ['string', 'number'];
|
|
690
719
|
const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowIndex, table, }) => {
|
|
691
720
|
var _a, _b, _c;
|
|
@@ -729,7 +758,7 @@ const MRT_TableBodyCellValue = ({ cell, rowRef, staticColumnIndex, staticRowInde
|
|
|
729
758
|
(globalFilter &&
|
|
730
759
|
allowedTypes.includes(typeof globalFilter) &&
|
|
731
760
|
column.getCanGlobalFilter()))) {
|
|
732
|
-
const chunks = highlightWords
|
|
761
|
+
const chunks = highlightWords({
|
|
733
762
|
matchExactly: (filterValue ? columnDef._filterFn : globalFilterFn) !== 'fuzzy',
|
|
734
763
|
query: ((_a = filterValue !== null && filterValue !== void 0 ? filterValue : globalFilter) !== null && _a !== void 0 ? _a : '').toString(),
|
|
735
764
|
text: renderedCellValue === null || renderedCellValue === void 0 ? void 0 : renderedCellValue.toString(),
|