@hillac/mantine-react-table 1.0.5 → 1.1.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/README.md +24 -21
- package/UPSTREAM.md +7 -5
- package/dist/index.d.ts +37 -34
- package/dist/index.js +186 -66
- package/dist/index.js.map +1 -1
- package/package.json +45 -32
- package/styles.css +346 -365
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
2
2
|
import clsx from 'clsx';
|
|
3
|
-
import { useMemo, useCallback, useState, memo, useEffect, useRef, Fragment as Fragment$1, useReducer, createElement
|
|
3
|
+
import { useMemo, useCallback, useState, memo, useEffect, useRef, Fragment as Fragment$1, useLayoutEffect, useReducer, createElement } from 'react';
|
|
4
4
|
import { Select, MultiSelect, TextInput, TableTr, TableTd, Collapse, CopyButton, Tooltip, UnstyledButton, Highlight, useDirection, Skeleton, Box, ActionIcon, Text, TableTbody, Flex, Button, useMantineTheme, Menu, Switch, TableTh, TableTfoot, Radio, Checkbox, Badge, Alert, Stack, Autocomplete, RangeSlider, Popover, Transition, Indicator, TableThead, Progress, Group, Pagination, Modal, useMantineColorScheme, Table, lighten, darken, LoadingOverlay, Paper } from '@mantine/core';
|
|
5
5
|
import { compareItems, rankItem, rankings } from '@tanstack/match-sorter-utils';
|
|
6
6
|
import { sortFns, constructRow, filterFns, Subscribe, flexRender as flexRender$1, aggregationFns, stockFeatures, createFacetedUniqueValues, createFacetedMinMaxValues, createFacetedRowModel, createGroupedRowModel, createExpandedRowModel, createPaginatedRowModel, createSortedRowModel, createFilteredRowModel, useTable } from '@tanstack/react-table';
|
|
@@ -1658,6 +1658,19 @@ const contains = (row, id, filterValue) => row
|
|
|
1658
1658
|
.trim()
|
|
1659
1659
|
.includes(filterValue.toString().toLowerCase().trim());
|
|
1660
1660
|
contains.autoRemove = (val) => !val;
|
|
1661
|
+
const dateOnlyPattern = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
1662
|
+
const getDateFilterTimestamp = (value) => {
|
|
1663
|
+
if (value instanceof Date)
|
|
1664
|
+
return value.getTime();
|
|
1665
|
+
if (typeof value === 'string') {
|
|
1666
|
+
const dateOnly = dateOnlyPattern.exec(value);
|
|
1667
|
+
if (dateOnly) {
|
|
1668
|
+
return new Date(Number(dateOnly[1]), Number(dateOnly[2]) - 1, Number(dateOnly[3])).getTime();
|
|
1669
|
+
}
|
|
1670
|
+
return new Date(value).getTime();
|
|
1671
|
+
}
|
|
1672
|
+
return new Date(value).getTime();
|
|
1673
|
+
};
|
|
1661
1674
|
const startsWith = (row, id, filterValue) => row
|
|
1662
1675
|
.getValue(id)
|
|
1663
1676
|
?.toString()
|
|
@@ -1672,23 +1685,40 @@ const endsWith = (row, id, filterValue) => row
|
|
|
1672
1685
|
.trim()
|
|
1673
1686
|
.endsWith(filterValue.toString().toLowerCase().trim());
|
|
1674
1687
|
endsWith.autoRemove = (val) => !val;
|
|
1675
|
-
const equals = (row, id, filterValue) =>
|
|
1676
|
-
|
|
1688
|
+
const equals = (row, id, filterValue) => {
|
|
1689
|
+
const rowValue = row.getValue(id);
|
|
1690
|
+
if (rowValue instanceof Date) {
|
|
1691
|
+
return rowValue.getTime() === getDateFilterTimestamp(filterValue);
|
|
1692
|
+
}
|
|
1693
|
+
return (rowValue?.toString().toLowerCase().trim() ===
|
|
1694
|
+
filterValue?.toString().toLowerCase().trim());
|
|
1695
|
+
};
|
|
1677
1696
|
equals.autoRemove = (val) => !val;
|
|
1678
|
-
const notEquals = (row, id, filterValue) => row
|
|
1679
|
-
filterValue.toString().toLowerCase().trim();
|
|
1697
|
+
const notEquals = (row, id, filterValue) => !equals(row, id, filterValue);
|
|
1680
1698
|
notEquals.autoRemove = (val) => !val;
|
|
1681
|
-
const greaterThan = (row, id, filterValue) =>
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1699
|
+
const greaterThan = (row, id, filterValue) => {
|
|
1700
|
+
const rowValue = row.getValue(id);
|
|
1701
|
+
if (rowValue instanceof Date) {
|
|
1702
|
+
return rowValue.getTime() > getDateFilterTimestamp(filterValue);
|
|
1703
|
+
}
|
|
1704
|
+
return !isNaN(+filterValue) && !isNaN(+rowValue)
|
|
1705
|
+
? +rowValue > +filterValue
|
|
1706
|
+
: rowValue?.toString().toLowerCase().trim() >
|
|
1707
|
+
filterValue?.toString().toLowerCase().trim();
|
|
1708
|
+
};
|
|
1685
1709
|
greaterThan.autoRemove = (val) => !val;
|
|
1686
1710
|
const greaterThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
|
|
1687
1711
|
greaterThanOrEqualTo.autoRemove = (val) => !val;
|
|
1688
|
-
const lessThan = (row, id, filterValue) =>
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1712
|
+
const lessThan = (row, id, filterValue) => {
|
|
1713
|
+
const rowValue = row.getValue(id);
|
|
1714
|
+
if (rowValue instanceof Date) {
|
|
1715
|
+
return rowValue.getTime() < getDateFilterTimestamp(filterValue);
|
|
1716
|
+
}
|
|
1717
|
+
return !isNaN(+filterValue) && !isNaN(+rowValue)
|
|
1718
|
+
? +rowValue < +filterValue
|
|
1719
|
+
: rowValue?.toString().toLowerCase().trim() <
|
|
1720
|
+
filterValue?.toString().toLowerCase().trim();
|
|
1721
|
+
};
|
|
1692
1722
|
lessThan.autoRemove = (val) => !val;
|
|
1693
1723
|
const lessThanOrEqualTo = (row, id, filterValue) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
|
|
1694
1724
|
lessThanOrEqualTo.autoRemove = (val) => !val;
|
|
@@ -1700,13 +1730,30 @@ const between = (row, id, filterValues) => (['', undefined].includes(filterValue
|
|
|
1700
1730
|
['', undefined].includes(filterValues[1]) ||
|
|
1701
1731
|
lessThan(row, id, filterValues[1]));
|
|
1702
1732
|
between.autoRemove = (val) => !val;
|
|
1703
|
-
const betweenInclusive = (row, id, filterValues) =>
|
|
1704
|
-
|
|
1705
|
-
(
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1733
|
+
const betweenInclusive = (row, id, filterValues) => {
|
|
1734
|
+
const [lower, upper] = filterValues;
|
|
1735
|
+
const rowValue = row.getValue(id);
|
|
1736
|
+
if (rowValue instanceof Date) {
|
|
1737
|
+
const minimum = lower == null || lower === '' ? undefined : getDateFilterTimestamp(lower);
|
|
1738
|
+
let maximum = upper == null || upper === '' ? undefined : getDateFilterTimestamp(upper);
|
|
1739
|
+
// Mantine emits date-only strings. Include that whole local calendar day,
|
|
1740
|
+
// which can be 23 or 25 hours. Explicit timestamps remain exact bounds.
|
|
1741
|
+
if (typeof upper === 'string' && dateOnlyPattern.test(upper)) {
|
|
1742
|
+
const nextDay = new Date(getDateFilterTimestamp(upper));
|
|
1743
|
+
nextDay.setDate(nextDay.getDate() + 1);
|
|
1744
|
+
maximum = nextDay.getTime() - 1;
|
|
1745
|
+
}
|
|
1746
|
+
return ((minimum === undefined || rowValue.getTime() >= minimum) &&
|
|
1747
|
+
(maximum === undefined || rowValue.getTime() <= maximum));
|
|
1748
|
+
}
|
|
1749
|
+
return ((lower == null ||
|
|
1750
|
+
lower === '' ||
|
|
1751
|
+
greaterThanOrEqualTo(row, id, lower instanceof Date ? lower.getTime() : lower)) &&
|
|
1752
|
+
(upper == null ||
|
|
1753
|
+
upper === '' ||
|
|
1754
|
+
(lower != null && !isNaN(+lower) && !isNaN(+upper) && +lower > +upper) ||
|
|
1755
|
+
lessThanOrEqualTo(row, id, upper instanceof Date ? upper.getTime() : upper)));
|
|
1756
|
+
};
|
|
1710
1757
|
betweenInclusive.autoRemove = (val) => !val;
|
|
1711
1758
|
const empty = (row, id, _filterValue) => !row.getValue(id)?.toString().trim();
|
|
1712
1759
|
empty.autoRemove = (val) => !val;
|
|
@@ -1768,7 +1815,7 @@ var classes$k = {"root":"MRT_FilterRangeFields-module_root__KfCcg"};
|
|
|
1768
1815
|
|
|
1769
1816
|
var classes$j = {"root":"MRT_FilterTextInput-module_root__Ss8Ql","date-filter":"MRT_FilterTextInput-module_date-filter__jOBLB","range-filter":"MRT_FilterTextInput-module_range-filter__JQHAL","not-filter-chip":"MRT_FilterTextInput-module_not-filter-chip__u8b1y","filter-chip-badge":"MRT_FilterTextInput-module_filter-chip-badge__Sel2k"};
|
|
1770
1817
|
|
|
1771
|
-
const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
1818
|
+
const MRT_FilterTextInput = ({ header, onRangeFilterValueChange, rangeFilterIndex, rangeFilterValue, table, ...rest }) => {
|
|
1772
1819
|
const { options: { columnFilterDisplayMode, columnFilterModeOptions, icons: { IconX }, localization, mantineFilterAutocompleteProps, mantineFilterDateInputProps, mantineFilterMultiSelectProps = {
|
|
1773
1820
|
clearable: true,
|
|
1774
1821
|
}, mantineFilterSelectProps, mantineFilterTextInputProps, manualFiltering, }, refs: { filterInputRefs }, setColumnFilterFns, } = table;
|
|
@@ -1837,7 +1884,9 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1837
1884
|
multiSelectProps?.data,
|
|
1838
1885
|
selectProps?.data,
|
|
1839
1886
|
]);
|
|
1840
|
-
const
|
|
1887
|
+
const hasPendingEdit = useRef(false);
|
|
1888
|
+
const tableFilterValue = column.getFilterValue();
|
|
1889
|
+
const previousTableFilterValue = useRef(tableFilterValue);
|
|
1841
1890
|
const [filterValue, setFilterValue] = useState(() => isMultiSelectFilter
|
|
1842
1891
|
? column.getFilterValue() || []
|
|
1843
1892
|
: isRangeFilter
|
|
@@ -1846,11 +1895,12 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1846
1895
|
const [debouncedFilterValue] = useDebouncedValue(filterValue, manualFiltering ? 400 : 200);
|
|
1847
1896
|
// send debounced filterValue to table instance
|
|
1848
1897
|
useEffect(() => {
|
|
1849
|
-
if (!
|
|
1898
|
+
if (!hasPendingEdit.current || onRangeFilterValueChange)
|
|
1850
1899
|
return;
|
|
1900
|
+
hasPendingEdit.current = false;
|
|
1851
1901
|
if (isRangeFilter) {
|
|
1852
1902
|
column.setFilterValue((old) => {
|
|
1853
|
-
const newFilterValues = Array.isArray(old) ? old : ['', ''];
|
|
1903
|
+
const newFilterValues = Array.isArray(old) ? [...old] : ['', ''];
|
|
1854
1904
|
newFilterValues[rangeFilterIndex] =
|
|
1855
1905
|
debouncedFilterValue;
|
|
1856
1906
|
return newFilterValues;
|
|
@@ -1861,14 +1911,21 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1861
1911
|
}
|
|
1862
1912
|
}, [debouncedFilterValue]);
|
|
1863
1913
|
// receive table filter value and set it to local state
|
|
1864
|
-
|
|
1865
|
-
if (
|
|
1866
|
-
isMounted.current = true;
|
|
1914
|
+
useLayoutEffect(() => {
|
|
1915
|
+
if (onRangeFilterValueChange)
|
|
1867
1916
|
return;
|
|
1868
|
-
|
|
1869
|
-
const
|
|
1917
|
+
const previous = previousTableFilterValue.current;
|
|
1918
|
+
const unchanged = Object.is(previous, tableFilterValue) ||
|
|
1919
|
+
(Array.isArray(previous) &&
|
|
1920
|
+
Array.isArray(tableFilterValue) &&
|
|
1921
|
+
previous.length === tableFilterValue.length &&
|
|
1922
|
+
previous.every((value, index) => Object.is(value, tableFilterValue[index])));
|
|
1923
|
+
if (unchanged)
|
|
1924
|
+
return;
|
|
1925
|
+
previousTableFilterValue.current = tableFilterValue;
|
|
1926
|
+
hasPendingEdit.current = false;
|
|
1870
1927
|
if (tableFilterValue === undefined) {
|
|
1871
|
-
|
|
1928
|
+
setFilterValue(isMultiSelectFilter ? [] : '');
|
|
1872
1929
|
}
|
|
1873
1930
|
else if (isRangeFilter && rangeFilterIndex !== undefined) {
|
|
1874
1931
|
setFilterValue((tableFilterValue ?? ['', ''])[rangeFilterIndex]);
|
|
@@ -1876,16 +1933,21 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1876
1933
|
else {
|
|
1877
1934
|
setFilterValue(tableFilterValue ?? '');
|
|
1878
1935
|
}
|
|
1879
|
-
}, [
|
|
1936
|
+
}, [tableFilterValue]);
|
|
1880
1937
|
const handleClear = () => {
|
|
1938
|
+
hasPendingEdit.current = false;
|
|
1881
1939
|
if (isMultiSelectFilter) {
|
|
1882
1940
|
setFilterValue([]);
|
|
1883
1941
|
column.setFilterValue([]);
|
|
1884
1942
|
}
|
|
1885
1943
|
else if (isRangeFilter) {
|
|
1944
|
+
if (onRangeFilterValueChange) {
|
|
1945
|
+
onRangeFilterValueChange(undefined);
|
|
1946
|
+
return;
|
|
1947
|
+
}
|
|
1886
1948
|
setFilterValue('');
|
|
1887
1949
|
column.setFilterValue((old) => {
|
|
1888
|
-
const newFilterValues = Array.isArray(old) ? old : ['', ''];
|
|
1950
|
+
const newFilterValues = Array.isArray(old) ? [...old] : ['', ''];
|
|
1889
1951
|
newFilterValues[rangeFilterIndex] = undefined;
|
|
1890
1952
|
return newFilterValues;
|
|
1891
1953
|
});
|
|
@@ -1902,6 +1964,7 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1902
1964
|
}
|
|
1903
1965
|
};
|
|
1904
1966
|
const handleClearEmptyFilterChip = () => {
|
|
1967
|
+
hasPendingEdit.current = false;
|
|
1905
1968
|
if (isMultiSelectFilter) {
|
|
1906
1969
|
setFilterValue([]);
|
|
1907
1970
|
column.setFilterValue([]);
|
|
@@ -1915,6 +1978,18 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1915
1978
|
[header.id]: allowedColumnFilterOptions?.[0] ?? 'fuzzy',
|
|
1916
1979
|
}));
|
|
1917
1980
|
};
|
|
1981
|
+
const displayedFilterValue = onRangeFilterValueChange
|
|
1982
|
+
? (rangeFilterValue ?? '')
|
|
1983
|
+
: filterValue;
|
|
1984
|
+
const handleFilterValueChange = (value) => {
|
|
1985
|
+
if (onRangeFilterValueChange) {
|
|
1986
|
+
onRangeFilterValueChange(value);
|
|
1987
|
+
}
|
|
1988
|
+
else {
|
|
1989
|
+
hasPendingEdit.current = true;
|
|
1990
|
+
setFilterValue(value);
|
|
1991
|
+
}
|
|
1992
|
+
};
|
|
1918
1993
|
const { className, ...commonProps } = {
|
|
1919
1994
|
'aria-label': filterPlaceholder,
|
|
1920
1995
|
className: clsx('mrt-filter-text-input', classes$j.root, isDateFilter
|
|
@@ -1923,7 +1998,7 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1923
1998
|
? classes$j['range-filter']
|
|
1924
1999
|
: !filterChipLabel && classes$j['not-filter-chip']),
|
|
1925
2000
|
disabled: !!filterChipLabel,
|
|
1926
|
-
onChange:
|
|
2001
|
+
onChange: handleFilterValueChange,
|
|
1927
2002
|
onClick: (event) => event.stopPropagation(),
|
|
1928
2003
|
placeholder: filterPlaceholder,
|
|
1929
2004
|
style: {
|
|
@@ -1936,10 +2011,12 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1936
2011
|
: textInputProps?.style),
|
|
1937
2012
|
},
|
|
1938
2013
|
title: filterPlaceholder,
|
|
1939
|
-
value: isMultiSelectFilter && !Array.isArray(
|
|
2014
|
+
value: isMultiSelectFilter && !Array.isArray(displayedFilterValue)
|
|
2015
|
+
? []
|
|
2016
|
+
: displayedFilterValue,
|
|
1940
2017
|
variant: 'unstyled',
|
|
1941
2018
|
};
|
|
1942
|
-
const ClearButton =
|
|
2019
|
+
const ClearButton = displayedFilterValue ? (jsx(ActionIcon, { "aria-label": localization.clearFilter, color: "var(--mantine-color-gray-7)", onClick: handleClear, size: "sm", title: localization.clearFilter ?? '', variant: "transparent", children: jsx(IconX, {}) })) : null;
|
|
1943
2020
|
if (columnDef.Filter) {
|
|
1944
2021
|
return (jsx(Fragment, { children: columnDef.Filter?.({ column, header, rangeFilterIndex, table }) }));
|
|
1945
2022
|
}
|
|
@@ -1947,7 +2024,12 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1947
2024
|
return (jsx(Box, { style: commonProps.style, children: jsx(Badge, { className: classes$j['filter-chip-badge'], onClick: handleClearEmptyFilterChip, rightSection: ClearButton, size: "lg", children: filterChipLabel }) }));
|
|
1948
2025
|
}
|
|
1949
2026
|
if (isMultiSelectFilter) {
|
|
1950
|
-
return (jsx(MultiSelect, { ...commonProps, searchable: true, ...multiSelectProps,
|
|
2027
|
+
return (jsx(MultiSelect, { ...commonProps, searchable: true, ...multiSelectProps, clearButtonProps: {
|
|
2028
|
+
'aria-hidden': false,
|
|
2029
|
+
'aria-label': localization.clearFilter,
|
|
2030
|
+
tabIndex: 0,
|
|
2031
|
+
...multiSelectProps.clearButtonProps,
|
|
2032
|
+
}, className: clsx(className, multiSelectProps.className), data: filterSelectOptions, onChange: handleFilterValueChange, ref: (node) => {
|
|
1951
2033
|
if (node) {
|
|
1952
2034
|
filterInputRefs.current[`${column.id}-${rangeFilterIndex ?? 0}`] =
|
|
1953
2035
|
node;
|
|
@@ -1955,9 +2037,7 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1955
2037
|
multiSelectProps.ref.current = node;
|
|
1956
2038
|
}
|
|
1957
2039
|
}
|
|
1958
|
-
},
|
|
1959
|
-
? ClearButton
|
|
1960
|
-
: undefined, style: commonProps.style }));
|
|
2040
|
+
}, style: commonProps.style }));
|
|
1961
2041
|
}
|
|
1962
2042
|
if (isSelectFilter) {
|
|
1963
2043
|
return (jsx(Select, { ...commonProps, clearable: true, searchable: true, ...selectProps, className: clsx(className, selectProps.className), clearButtonProps: {
|
|
@@ -1984,7 +2064,7 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1984
2064
|
}, style: commonProps.style }));
|
|
1985
2065
|
}
|
|
1986
2066
|
if (isAutoCompleteFilter) {
|
|
1987
|
-
return (jsx(Autocomplete, { ...commonProps, onChange:
|
|
2067
|
+
return (jsx(Autocomplete, { ...commonProps, onChange: handleFilterValueChange, rightSection: filterValue?.toString()?.length ? ClearButton : undefined, ...autoCompleteProps, className: clsx(className, autoCompleteProps.className), data: filterSelectOptions, ref: (node) => {
|
|
1988
2068
|
if (node) {
|
|
1989
2069
|
filterInputRefs.current[`${column.id}-${rangeFilterIndex ?? 0}`] =
|
|
1990
2070
|
node;
|
|
@@ -1994,7 +2074,7 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
1994
2074
|
}
|
|
1995
2075
|
}, style: commonProps.style }));
|
|
1996
2076
|
}
|
|
1997
|
-
return (jsx(TextInput, { ...commonProps, onChange: (e) =>
|
|
2077
|
+
return (jsx(TextInput, { ...commonProps, onChange: (e) => handleFilterValueChange(e.target.value), rightSection: displayedFilterValue?.toString()?.length ? ClearButton : undefined, ...textInputProps, className: clsx(className, textInputProps.className), mt: 0, ref: (node) => {
|
|
1998
2078
|
if (node) {
|
|
1999
2079
|
filterInputRefs.current[`${column.id}-${rangeFilterIndex ?? 0}`] =
|
|
2000
2080
|
node;
|
|
@@ -2006,7 +2086,39 @@ const MRT_FilterTextInput = ({ header, rangeFilterIndex, table, ...rest }) => {
|
|
|
2006
2086
|
};
|
|
2007
2087
|
|
|
2008
2088
|
const MRT_FilterRangeFields = ({ header, table, ...rest }) => {
|
|
2009
|
-
|
|
2089
|
+
const { options: { manualFiltering }, } = table;
|
|
2090
|
+
const { column } = header;
|
|
2091
|
+
const columnFilterValue = column.getFilterValue();
|
|
2092
|
+
const minimum = Array.isArray(columnFilterValue) ? columnFilterValue[0] ?? '' : '';
|
|
2093
|
+
const maximum = Array.isArray(columnFilterValue) ? columnFilterValue[1] ?? '' : '';
|
|
2094
|
+
const [filterValues, setFilterValues] = useState([
|
|
2095
|
+
minimum,
|
|
2096
|
+
maximum,
|
|
2097
|
+
]);
|
|
2098
|
+
const filterValuesRef = useRef(filterValues);
|
|
2099
|
+
const timeoutRef = useRef(undefined);
|
|
2100
|
+
// A new array with identical bounds is not an external change. Real changes
|
|
2101
|
+
// replace the draft and cancel pending edits before they can overwrite a reset.
|
|
2102
|
+
useLayoutEffect(() => {
|
|
2103
|
+
const next = [minimum, maximum];
|
|
2104
|
+
filterValuesRef.current = next;
|
|
2105
|
+
setFilterValues(next);
|
|
2106
|
+
return () => clearTimeout(timeoutRef.current);
|
|
2107
|
+
}, [minimum, maximum]);
|
|
2108
|
+
const setRangeFilterValue = (index, value) => {
|
|
2109
|
+
const next = [...filterValuesRef.current];
|
|
2110
|
+
next[index] = value ?? '';
|
|
2111
|
+
filterValuesRef.current = next;
|
|
2112
|
+
setFilterValues(next);
|
|
2113
|
+
clearTimeout(timeoutRef.current);
|
|
2114
|
+
// Only user edits schedule writes: mounting and receiving external state
|
|
2115
|
+
// must not echo values back, including during Strict Mode effect replay.
|
|
2116
|
+
timeoutRef.current = setTimeout(() => {
|
|
2117
|
+
const hasFilterValue = next.some((bound) => bound !== '');
|
|
2118
|
+
column.setFilterValue(hasFilterValue ? [...next] : undefined);
|
|
2119
|
+
}, manualFiltering ? 400 : 200);
|
|
2120
|
+
};
|
|
2121
|
+
return (jsxs(Box, { ...rest, className: clsx('mrt-filter-range-fields', classes$k.root, rest.className), children: [jsx(MRT_FilterTextInput, { header: header, onRangeFilterValueChange: (value) => setRangeFilterValue(0, value), rangeFilterIndex: 0, rangeFilterValue: filterValues[0], table: table }), jsx(MRT_FilterTextInput, { header: header, onRangeFilterValueChange: (value) => setRangeFilterValue(1, value), rangeFilterIndex: 1, rangeFilterValue: filterValues[1], table: table })] }));
|
|
2010
2122
|
};
|
|
2011
2123
|
|
|
2012
2124
|
var classes$i = {"root":"MRT_FilterRangeSlider-module_root__uwYEk"};
|
|
@@ -2593,28 +2705,28 @@ const MRT_GlobalFilterTextInput = ({ table, ...rest }) => {
|
|
|
2593
2705
|
}),
|
|
2594
2706
|
...rest,
|
|
2595
2707
|
};
|
|
2596
|
-
const
|
|
2708
|
+
const hasPendingEdit = useRef(false);
|
|
2597
2709
|
const [searchValue, setSearchValue] = useState(globalFilter ?? '');
|
|
2598
2710
|
const [debouncedSearchValue] = useDebouncedValue(searchValue, manualFiltering ? 500 : 250);
|
|
2599
2711
|
useEffect(() => {
|
|
2712
|
+
if (!hasPendingEdit.current)
|
|
2713
|
+
return;
|
|
2714
|
+
hasPendingEdit.current = false;
|
|
2600
2715
|
setGlobalFilter(debouncedSearchValue || undefined);
|
|
2601
2716
|
}, [debouncedSearchValue]);
|
|
2602
2717
|
const handleClear = () => {
|
|
2718
|
+
hasPendingEdit.current = false;
|
|
2603
2719
|
setSearchValue('');
|
|
2604
2720
|
setGlobalFilter(undefined);
|
|
2605
2721
|
};
|
|
2606
|
-
|
|
2607
|
-
|
|
2608
|
-
|
|
2609
|
-
handleClear();
|
|
2610
|
-
}
|
|
2611
|
-
else {
|
|
2612
|
-
setSearchValue(globalFilter);
|
|
2613
|
-
}
|
|
2614
|
-
}
|
|
2615
|
-
isMounted.current = true;
|
|
2722
|
+
useLayoutEffect(() => {
|
|
2723
|
+
hasPendingEdit.current = false;
|
|
2724
|
+
setSearchValue(globalFilter ?? '');
|
|
2616
2725
|
}, [globalFilter]);
|
|
2617
|
-
return (jsxs(Collapse, { className: classes$9.collapse, expanded: showGlobalFilter, children: [enableGlobalFilterModes && (jsxs(Menu, { withinPortal: true, children: [jsx(Menu.Target, { children: jsx(ActionIcon, { "aria-label": localization.changeSearchMode, color: "gray", size: "sm", variant: "transparent", children: jsx(IconSearch, {}) }) }), jsx(MRT_FilterOptionMenu, { onSelect: handleClear, table: table })] })), jsx(TextInput, { leftSection: !enableGlobalFilterModes && jsx(IconSearch, {}), mt: 0, mx: positionGlobalFilter !== 'left' ? 'mx' : undefined, onChange: (event) =>
|
|
2726
|
+
return (jsxs(Collapse, { className: classes$9.collapse, expanded: showGlobalFilter, children: [enableGlobalFilterModes && (jsxs(Menu, { withinPortal: true, children: [jsx(Menu.Target, { children: jsx(ActionIcon, { "aria-label": localization.changeSearchMode, color: "gray", size: "sm", variant: "transparent", children: jsx(IconSearch, {}) }) }), jsx(MRT_FilterOptionMenu, { onSelect: handleClear, table: table })] })), jsx(TextInput, { leftSection: !enableGlobalFilterModes && jsx(IconSearch, {}), mt: 0, mx: positionGlobalFilter !== 'left' ? 'mx' : undefined, onChange: (event) => {
|
|
2727
|
+
hasPendingEdit.current = true;
|
|
2728
|
+
setSearchValue(event.target.value);
|
|
2729
|
+
}, placeholder: localization.search, rightSection: jsx(ActionIcon, { "aria-label": localization.clearSearch, color: "gray", disabled: !searchValue?.length, hidden: !searchValue, onClick: handleClear, size: "sm", style: {
|
|
2618
2730
|
visibility: !searchValue ? 'hidden' : undefined,
|
|
2619
2731
|
}, variant: "transparent", children: jsx(Tooltip, { label: localization.clearSearch, withinPortal: true, children: jsx(IconX, {}) }) }), value: searchValue ?? '', variant: "filled", ...textFieldProps, className: clsx('mrt-global-filter-text-input', classes$9.root, textFieldProps?.className), ref: (node) => {
|
|
2620
2732
|
if (node) {
|
|
@@ -3153,10 +3265,17 @@ const useMRT_Effects = (table) => {
|
|
|
3153
3265
|
if (!getCanRankRows(table))
|
|
3154
3266
|
return;
|
|
3155
3267
|
if (globalFilter) {
|
|
3156
|
-
|
|
3157
|
-
|
|
3158
|
-
|
|
3159
|
-
|
|
3268
|
+
if (sorting.length)
|
|
3269
|
+
table.setSorting([]);
|
|
3270
|
+
}
|
|
3271
|
+
else if (sorting.length !== appliedSort.current.length ||
|
|
3272
|
+
sorting.some((sort, index) => {
|
|
3273
|
+
const previous = appliedSort.current[index];
|
|
3274
|
+
return sort.id !== previous?.id || sort.desc !== previous.desc;
|
|
3275
|
+
})) {
|
|
3276
|
+
// Restoring the same sort on mount is not a user change. Consumers may
|
|
3277
|
+
// reset pagination or fetch data whenever onSortingChange is called.
|
|
3278
|
+
table.setSorting(appliedSort.current);
|
|
3160
3279
|
}
|
|
3161
3280
|
}, [globalFilter]);
|
|
3162
3281
|
// fix pinned row top style when density changes
|
|
@@ -3174,11 +3293,12 @@ const useMRT_Effects = (table) => {
|
|
|
3174
3293
|
* state, refs, and helpers. State management is built on top of TanStack
|
|
3175
3294
|
* Store atoms (`useCreateAtom` from `@tanstack/react-store`):
|
|
3176
3295
|
*
|
|
3177
|
-
* - **TanStack-aware slices** (`columnOrder`, `columnResizing`, `grouping
|
|
3178
|
-
*
|
|
3179
|
-
* writes (e.g. `table.setSorting(...)`, `table.firstPage()`) flow directly
|
|
3296
|
+
* - **TanStack-aware slices** (`columnOrder`, `columnResizing`, `grouping`)
|
|
3297
|
+
* are passed via the `atoms` option on `useTable`. Library writes flow directly
|
|
3180
3298
|
* through these atoms, and they're automatically tracked in
|
|
3181
3299
|
* `table.state` by the v9 store.
|
|
3300
|
+
* - Pagination uses `state` and `onPaginationChange`, with local React state
|
|
3301
|
+
* as the fallback when the consumer does not control it.
|
|
3182
3302
|
* - **MRT-only slices** (`density`, `isFullScreen`, `creatingRow`,
|
|
3183
3303
|
* `editingCell`, `editingRow`, `draggingColumn`, `draggingRow`,
|
|
3184
3304
|
* `hoveredColumn`, `hoveredRow`, `globalFilterFn`, `columnFilterFns`,
|
|
@@ -3225,14 +3345,14 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3225
3345
|
const columnOrderAtom = useCreateAtom(initialState.columnOrder ?? []);
|
|
3226
3346
|
const columnResizingAtom = useCreateAtom(initialState.columnResizing ?? {});
|
|
3227
3347
|
const groupingAtom = useCreateAtom(initialState.grouping ?? []);
|
|
3228
|
-
|
|
3348
|
+
// An external atom would take precedence over controlled state.pagination.
|
|
3349
|
+
const [pagination, setPagination] = useState(initialState?.pagination ?? { pageIndex: 0, pageSize: 10 });
|
|
3229
3350
|
// Subscribe so the consumer re-renders when these slices change. (The library
|
|
3230
3351
|
// also reads from these atoms internally; the subscriptions here are for the
|
|
3231
3352
|
// MRT component tree.)
|
|
3232
3353
|
const columnOrder = useSelector(columnOrderAtom);
|
|
3233
3354
|
const columnResizing = useSelector(columnResizingAtom);
|
|
3234
3355
|
const grouping = useSelector(groupingAtom);
|
|
3235
|
-
const pagination = useSelector(paginationAtom);
|
|
3236
3356
|
// ---------------------------------------------------------------------------
|
|
3237
3357
|
// MRT-only atoms — these slices aren't part of v9's `TableState` so they
|
|
3238
3358
|
// can't be passed via the `atoms` option. They're maintained as standalone
|
|
@@ -3399,14 +3519,14 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3399
3519
|
]);
|
|
3400
3520
|
const table = useTable({
|
|
3401
3521
|
...statefulTableOptions,
|
|
3522
|
+
onPaginationChange: statefulTableOptions.onPaginationChange ?? setPagination,
|
|
3402
3523
|
globalFilterFn: (globalFilterFn ?? 'fuzzy'),
|
|
3403
3524
|
// Hand TanStack-aware slices over to our external atoms — library writes
|
|
3404
|
-
// (e.g.
|
|
3525
|
+
// (e.g. drag-resize) flow straight into them.
|
|
3405
3526
|
atoms: {
|
|
3406
3527
|
columnOrder: columnOrderAtom,
|
|
3407
3528
|
columnResizing: columnResizingAtom,
|
|
3408
3529
|
grouping: groupingAtom,
|
|
3409
|
-
pagination: paginationAtom,
|
|
3410
3530
|
},
|
|
3411
3531
|
}, (state) => state);
|
|
3412
3532
|
// v9 spells the resize setter `setcolumnResizing` (lowercase 'c') because
|
|
@@ -3435,7 +3555,7 @@ const useMRT_TableInstance = (definedTableOptions) => {
|
|
|
3435
3555
|
showLoadingOverlay: statefulTableOptions.state.showLoadingOverlay ?? false,
|
|
3436
3556
|
showProgressBars: statefulTableOptions.state.showProgressBars ?? false,
|
|
3437
3557
|
showSkeletons: statefulTableOptions.state.showSkeletons,
|
|
3438
|
-
showAlertBanner,
|
|
3558
|
+
showAlertBanner: statefulTableOptions.state.showAlertBanner ?? showAlertBanner,
|
|
3439
3559
|
showColumnFilters,
|
|
3440
3560
|
showGlobalFilter,
|
|
3441
3561
|
showToolbarDropZone,
|