@tanstack/react-table 8.5.17 → 8.5.19

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.
@@ -2674,6 +2674,7 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
2674
2674
  original,
2675
2675
  depth,
2676
2676
  _valuesCache: {},
2677
+ _uniqueValuesCache: {},
2677
2678
  getValue: columnId => {
2678
2679
  if (row._valuesCache.hasOwnProperty(columnId)) {
2679
2680
  return row._valuesCache[columnId];
@@ -2685,6 +2686,21 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
2685
2686
  row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
2686
2687
  return row._valuesCache[columnId];
2687
2688
  },
2689
+ getUniqueValues: columnId => {
2690
+ if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
2691
+ return row._uniqueValuesCache[columnId];
2692
+ }
2693
+ const column = table.getColumn(columnId);
2694
+ if (!column.accessorFn) {
2695
+ return undefined;
2696
+ }
2697
+ if (!column.columnDef.getUniqueValues) {
2698
+ row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
2699
+ return row._uniqueValuesCache[columnId];
2700
+ }
2701
+ row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
2702
+ return row._uniqueValuesCache[columnId];
2703
+ },
2688
2704
  renderValue: columnId => row.getValue(columnId) ?? table.options.renderFallbackValue,
2689
2705
  subRows: subRows ?? [],
2690
2706
  getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
@@ -3025,12 +3041,14 @@ function getFacetedUniqueValues() {
3025
3041
  return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3026
3042
  let facetedUniqueValues = new Map();
3027
3043
  for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3028
- var _facetedRowModel$flat;
3029
- const value = (_facetedRowModel$flat = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3030
- if (facetedUniqueValues.has(value)) {
3031
- facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3032
- } else {
3033
- facetedUniqueValues.set(value, 1);
3044
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3045
+ for (let j = 0; j < values.length; j++) {
3046
+ const value = values[j];
3047
+ if (facetedUniqueValues.has(value)) {
3048
+ facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3049
+ } else {
3050
+ facetedUniqueValues.set(value, 1);
3051
+ }
3034
3052
  }
3035
3053
  }
3036
3054
  return facetedUniqueValues;
@@ -3044,17 +3062,20 @@ function getFacetedUniqueValues() {
3044
3062
  function getFacetedMinMaxValues() {
3045
3063
  return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3046
3064
  var _facetedRowModel$flat;
3047
- const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3065
+ const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3048
3066
  if (typeof firstValue === 'undefined') {
3049
3067
  return undefined;
3050
3068
  }
3051
3069
  let facetedMinMaxValues = [firstValue, firstValue];
3052
3070
  for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3053
- const value = facetedRowModel.flatRows[i].getValue(columnId);
3054
- if (value < facetedMinMaxValues[0]) {
3055
- facetedMinMaxValues[0] = value;
3056
- } else if (value > facetedMinMaxValues[1]) {
3057
- facetedMinMaxValues[1] = value;
3071
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3072
+ for (let j = 0; j < values.length; j++) {
3073
+ const value = values[j];
3074
+ if (value < facetedMinMaxValues[0]) {
3075
+ facetedMinMaxValues[0] = value;
3076
+ } else if (value > facetedMinMaxValues[1]) {
3077
+ facetedMinMaxValues[1] = value;
3078
+ }
3058
3079
  }
3059
3080
  }
3060
3081
  return facetedMinMaxValues;
@@ -3087,7 +3108,7 @@ function getSortedRowModel() {
3087
3108
  const sortData = rows => {
3088
3109
  // This will also perform a stable sorting using the row index
3089
3110
  // if needed.
3090
- const sortedData = rows.slice();
3111
+ const sortedData = [...rows];
3091
3112
  sortedData.sort((rowA, rowB) => {
3092
3113
  for (let i = 0; i < availableSorting.length; i += 1) {
3093
3114
  const sortEntry = availableSorting[i];