@tanstack/svelte-table 8.5.17 → 8.5.18

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.
@@ -2673,6 +2673,7 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
2673
2673
  original,
2674
2674
  depth,
2675
2675
  _valuesCache: {},
2676
+ _uniqueValuesCache: {},
2676
2677
  getValue: columnId => {
2677
2678
  if (row._valuesCache.hasOwnProperty(columnId)) {
2678
2679
  return row._valuesCache[columnId];
@@ -2684,6 +2685,21 @@ const createRow = (table, id, original, rowIndex, depth, subRows) => {
2684
2685
  row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
2685
2686
  return row._valuesCache[columnId];
2686
2687
  },
2688
+ getUniqueValues: columnId => {
2689
+ if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
2690
+ return row._uniqueValuesCache[columnId];
2691
+ }
2692
+ const column = table.getColumn(columnId);
2693
+ if (!column.accessorFn) {
2694
+ return undefined;
2695
+ }
2696
+ if (!column.columnDef.getUniqueValues) {
2697
+ row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
2698
+ return row._uniqueValuesCache[columnId];
2699
+ }
2700
+ row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
2701
+ return row._uniqueValuesCache[columnId];
2702
+ },
2687
2703
  renderValue: columnId => row.getValue(columnId) ?? table.options.renderFallbackValue,
2688
2704
  subRows: subRows ?? [],
2689
2705
  getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
@@ -3024,12 +3040,14 @@ function getFacetedUniqueValues() {
3024
3040
  return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3025
3041
  let facetedUniqueValues = new Map();
3026
3042
  for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3027
- var _facetedRowModel$flat;
3028
- const value = (_facetedRowModel$flat = facetedRowModel.flatRows[i]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3029
- if (facetedUniqueValues.has(value)) {
3030
- facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3031
- } else {
3032
- facetedUniqueValues.set(value, 1);
3043
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3044
+ for (let j = 0; j < values.length; j++) {
3045
+ const value = values[j];
3046
+ if (facetedUniqueValues.has(value)) {
3047
+ facetedUniqueValues.set(value, (facetedUniqueValues.get(value) ?? 0) + 1);
3048
+ } else {
3049
+ facetedUniqueValues.set(value, 1);
3050
+ }
3033
3051
  }
3034
3052
  }
3035
3053
  return facetedUniqueValues;
@@ -3043,17 +3061,20 @@ function getFacetedUniqueValues() {
3043
3061
  function getFacetedMinMaxValues() {
3044
3062
  return (table, columnId) => memo(() => [table.getColumn(columnId).getFacetedRowModel()], facetedRowModel => {
3045
3063
  var _facetedRowModel$flat;
3046
- const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getValue(columnId);
3064
+ const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3047
3065
  if (typeof firstValue === 'undefined') {
3048
3066
  return undefined;
3049
3067
  }
3050
3068
  let facetedMinMaxValues = [firstValue, firstValue];
3051
3069
  for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3052
- const value = facetedRowModel.flatRows[i].getValue(columnId);
3053
- if (value < facetedMinMaxValues[0]) {
3054
- facetedMinMaxValues[0] = value;
3055
- } else if (value > facetedMinMaxValues[1]) {
3056
- facetedMinMaxValues[1] = value;
3070
+ const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3071
+ for (let j = 0; j < values.length; j++) {
3072
+ const value = values[j];
3073
+ if (value < facetedMinMaxValues[0]) {
3074
+ facetedMinMaxValues[0] = value;
3075
+ } else if (value > facetedMinMaxValues[1]) {
3076
+ facetedMinMaxValues[1] = value;
3077
+ }
3057
3078
  }
3058
3079
  }
3059
3080
  return facetedMinMaxValues;