@tanstack/table-core 9.0.0-beta.48 → 9.0.0-beta.49
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/features/column-faceting/createFacetedMinMaxValues.cjs +7 -4
- package/dist/features/column-faceting/createFacetedMinMaxValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedMinMaxValues.js +8 -5
- package/dist/features/column-faceting/createFacetedMinMaxValues.js.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js +1 -1
- package/dist/features/column-faceting/createFacetedRowModel.js.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs +8 -4
- package/dist/features/column-faceting/createFacetedUniqueValues.cjs.map +1 -1
- package/dist/features/column-faceting/createFacetedUniqueValues.js +9 -5
- package/dist/features/column-faceting/createFacetedUniqueValues.js.map +1 -1
- package/package.json +1 -1
- package/skills/aggregation/SKILL.md +1 -1
- package/skills/api-not-found/SKILL.md +1 -1
- package/skills/client-vs-server/SKILL.md +1 -1
- package/skills/column-faceting/SKILL.md +1 -1
- package/skills/column-filtering/SKILL.md +1 -1
- package/skills/column-ordering/SKILL.md +1 -1
- package/skills/column-pinning/SKILL.md +1 -1
- package/skills/column-resizing/SKILL.md +1 -1
- package/skills/column-sizing/SKILL.md +1 -1
- package/skills/column-visibility/SKILL.md +1 -1
- package/skills/core/SKILL.md +1 -1
- package/skills/custom-features/SKILL.md +1 -1
- package/skills/expanding/SKILL.md +1 -1
- package/skills/global-filtering/SKILL.md +1 -1
- package/skills/grouping/SKILL.md +1 -1
- package/skills/migrate-v8-to-v9/SKILL.md +1 -1
- package/skills/pagination/SKILL.md +1 -1
- package/skills/row-pinning/SKILL.md +1 -1
- package/skills/row-selection/SKILL.md +1 -1
- package/skills/sorting/SKILL.md +1 -1
- package/skills/table-features/SKILL.md +1 -1
- package/skills/typescript/SKILL.md +1 -1
- package/src/features/column-faceting/createFacetedMinMaxValues.ts +33 -7
- package/src/features/column-faceting/createFacetedRowModel.ts +4 -1
- package/src/features/column-faceting/createFacetedUniqueValues.ts +45 -11
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_utils = require('../../utils.cjs');
|
|
2
2
|
const require_columnFacetingFeature_utils = require('./columnFacetingFeature.utils.cjs');
|
|
3
|
+
const require_globalFilteringFeature_utils = require('../global-filtering/globalFilteringFeature.utils.cjs');
|
|
3
4
|
|
|
4
5
|
//#region src/features/column-faceting/createFacetedMinMaxValues.ts
|
|
5
6
|
/**
|
|
@@ -12,9 +13,10 @@ function createFacetedMinMaxValues() {
|
|
|
12
13
|
const table = _table;
|
|
13
14
|
return require_utils.tableMemo({
|
|
14
15
|
feature: "columnFacetingFeature",
|
|
15
|
-
fn: (flatRows) => _createFacetedMinMaxValues(columnId, flatRows),
|
|
16
|
+
fn: (flatRows) => _createFacetedMinMaxValues(table, columnId, flatRows),
|
|
16
17
|
fnName: "table.getFacetedMinMaxValues",
|
|
17
18
|
memoDeps: () => {
|
|
19
|
+
if (columnId === "__global__") return [require_utils.callMemoOrStaticFn(table, "getGlobalFacetedRowModel", require_columnFacetingFeature_utils.table_getGlobalFacetedRowModel).flatRows];
|
|
18
20
|
const column = table.getColumn(columnId);
|
|
19
21
|
if (!column) return [table.getPreFilteredRowModel().flatRows];
|
|
20
22
|
return [require_utils.callMemoOrStaticFn(column, "getFacetedRowModel", require_columnFacetingFeature_utils.column_getFacetedRowModel, table).flatRows];
|
|
@@ -23,13 +25,14 @@ function createFacetedMinMaxValues() {
|
|
|
23
25
|
});
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
|
-
function _createFacetedMinMaxValues(columnId, flatRows) {
|
|
28
|
+
function _createFacetedMinMaxValues(table, columnId, flatRows) {
|
|
27
29
|
if (!flatRows.length) return void 0;
|
|
30
|
+
const columnIds = columnId === "__global__" ? table.getAllLeafColumns().filter((column) => require_globalFilteringFeature_utils.column_getCanGlobalFilter(column)).map((column) => column.id) : [columnId];
|
|
28
31
|
let facetedMinValue = Number.POSITIVE_INFINITY;
|
|
29
32
|
let facetedMaxValue = Number.NEGATIVE_INFINITY;
|
|
30
33
|
let foundAny = false;
|
|
31
|
-
for (let i = 0; i < flatRows.length; i++) {
|
|
32
|
-
const value = Number(flatRows[i].getValue(
|
|
34
|
+
for (let i = 0; i < flatRows.length; i++) for (let c = 0; c < columnIds.length; c++) {
|
|
35
|
+
const value = Number(flatRows[i].getValue(columnIds[c]));
|
|
33
36
|
if (Number.isNaN(value)) continue;
|
|
34
37
|
foundAny = true;
|
|
35
38
|
if (value < facetedMinValue) facetedMinValue = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFacetedMinMaxValues.cjs","names":["tableMemo","callMemoOrStaticFn","column_getFacetedRowModel"],"sources":["../../../src/features/column-faceting/createFacetedMinMaxValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport {
|
|
1
|
+
{"version":3,"file":"createFacetedMinMaxValues.cjs","names":["tableMemo","callMemoOrStaticFn","table_getGlobalFacetedRowModel","column_getFacetedRowModel","column_getCanGlobalFilter"],"sources":["../../../src/features/column-faceting/createFacetedMinMaxValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport { column_getCanGlobalFilter } from '../global-filtering/globalFilteringFeature.utils'\nimport {\n column_getFacetedRowModel,\n table_getGlobalFacetedRowModel,\n} from './columnFacetingFeature.utils'\nimport type { Row } from '../../types/Row'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted min max values helper for faceted filtering.\n *\n * The returned function derives facet data from the table row model and relevant filter state so filter UIs can display available values.\n */\nexport function createFacetedMinMaxValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number] {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n fn: (flatRows) => _createFacetedMinMaxValues(table, columnId, flatRows),\n fnName: 'table.getFacetedMinMaxValues',\n memoDeps: () => {\n if (columnId === '__global__') {\n return [\n callMemoOrStaticFn(\n table,\n 'getGlobalFacetedRowModel',\n table_getGlobalFacetedRowModel,\n ).flatRows,\n ]\n }\n const column = table.getColumn(columnId)\n if (!column) return [table.getPreFilteredRowModel().flatRows]\n return [\n callMemoOrStaticFn(\n column,\n 'getFacetedRowModel',\n column_getFacetedRowModel,\n table,\n ).flatRows,\n ]\n },\n table,\n })\n }\n}\n\nfunction _createFacetedMinMaxValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n flatRows: Array<Row<TFeatures, TData>>,\n): undefined | [number, number] {\n if (!flatRows.length) return undefined\n\n // The global context aggregates values across every column that\n // participates in global filtering\n const columnIds =\n columnId === '__global__'\n ? table\n .getAllLeafColumns()\n .filter((column) => column_getCanGlobalFilter(column))\n .map((column) => column.id)\n : [columnId]\n\n let facetedMinValue = Number.POSITIVE_INFINITY\n let facetedMaxValue = Number.NEGATIVE_INFINITY\n let foundAny = false\n\n for (let i = 0; i < flatRows.length; i++) {\n for (let c = 0; c < columnIds.length; c++) {\n const value = Number(flatRows[i]!.getValue(columnIds[c]!))\n if (Number.isNaN(value)) continue\n foundAny = true\n if (value < facetedMinValue) facetedMinValue = value\n if (value > facetedMaxValue) facetedMaxValue = value\n }\n }\n\n if (!foundAny) return undefined\n return [facetedMinValue, facetedMaxValue]\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,4BAMwB;CACtC,QAAQ,QAAQ,aAAa;EAC3B,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT,KAAK,aAAa,2BAA2B,OAAO,UAAU,QAAQ;GACtE,QAAQ;GACR,gBAAgB;IACd,IAAI,aAAa,cACf,OAAO,CACLC,iCACE,OACA,4BACAC,kEACF,CAAC,CAAC,QACJ;IAEF,MAAM,SAAS,MAAM,UAAU,QAAQ;IACvC,IAAI,CAAC,QAAQ,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC,QAAQ;IAC5D,OAAO,CACLD,iCACE,QACA,sBACAE,+DACA,KACF,CAAC,CAAC,QACJ;GACF;GACA;EACF,CAAC;CACH;AACF;AAEA,SAAS,2BAIP,OACA,UACA,UAC8B;CAC9B,IAAI,CAAC,SAAS,QAAQ,OAAO;CAI7B,MAAM,YACJ,aAAa,eACT,MACG,kBAAkB,CAAC,CACnB,QAAQ,WAAWC,+DAA0B,MAAM,CAAC,CAAC,CACrD,KAAK,WAAW,OAAO,EAAE,IAC5B,CAAC,QAAQ;CAEf,IAAI,kBAAkB,OAAO;CAC7B,IAAI,kBAAkB,OAAO;CAC7B,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,QAAQ,OAAO,SAAS,EAAE,CAAE,SAAS,UAAU,EAAG,CAAC;EACzD,IAAI,OAAO,MAAM,KAAK,GAAG;EACzB,WAAW;EACX,IAAI,QAAQ,iBAAiB,kBAAkB;EAC/C,IAAI,QAAQ,iBAAiB,kBAAkB;CACjD;CAGF,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO,CAAC,iBAAiB,eAAe;AAC1C"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { callMemoOrStaticFn, tableMemo } from "../../utils.js";
|
|
2
|
-
import { column_getFacetedRowModel } from "./columnFacetingFeature.utils.js";
|
|
2
|
+
import { column_getFacetedRowModel, table_getGlobalFacetedRowModel } from "./columnFacetingFeature.utils.js";
|
|
3
|
+
import { column_getCanGlobalFilter } from "../global-filtering/globalFilteringFeature.utils.js";
|
|
3
4
|
|
|
4
5
|
//#region src/features/column-faceting/createFacetedMinMaxValues.ts
|
|
5
6
|
/**
|
|
@@ -12,9 +13,10 @@ function createFacetedMinMaxValues() {
|
|
|
12
13
|
const table = _table;
|
|
13
14
|
return tableMemo({
|
|
14
15
|
feature: "columnFacetingFeature",
|
|
15
|
-
fn: (flatRows) => _createFacetedMinMaxValues(columnId, flatRows),
|
|
16
|
+
fn: (flatRows) => _createFacetedMinMaxValues(table, columnId, flatRows),
|
|
16
17
|
fnName: "table.getFacetedMinMaxValues",
|
|
17
18
|
memoDeps: () => {
|
|
19
|
+
if (columnId === "__global__") return [callMemoOrStaticFn(table, "getGlobalFacetedRowModel", table_getGlobalFacetedRowModel).flatRows];
|
|
18
20
|
const column = table.getColumn(columnId);
|
|
19
21
|
if (!column) return [table.getPreFilteredRowModel().flatRows];
|
|
20
22
|
return [callMemoOrStaticFn(column, "getFacetedRowModel", column_getFacetedRowModel, table).flatRows];
|
|
@@ -23,13 +25,14 @@ function createFacetedMinMaxValues() {
|
|
|
23
25
|
});
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
|
-
function _createFacetedMinMaxValues(columnId, flatRows) {
|
|
28
|
+
function _createFacetedMinMaxValues(table, columnId, flatRows) {
|
|
27
29
|
if (!flatRows.length) return void 0;
|
|
30
|
+
const columnIds = columnId === "__global__" ? table.getAllLeafColumns().filter((column) => column_getCanGlobalFilter(column)).map((column) => column.id) : [columnId];
|
|
28
31
|
let facetedMinValue = Number.POSITIVE_INFINITY;
|
|
29
32
|
let facetedMaxValue = Number.NEGATIVE_INFINITY;
|
|
30
33
|
let foundAny = false;
|
|
31
|
-
for (let i = 0; i < flatRows.length; i++) {
|
|
32
|
-
const value = Number(flatRows[i].getValue(
|
|
34
|
+
for (let i = 0; i < flatRows.length; i++) for (let c = 0; c < columnIds.length; c++) {
|
|
35
|
+
const value = Number(flatRows[i].getValue(columnIds[c]));
|
|
33
36
|
if (Number.isNaN(value)) continue;
|
|
34
37
|
foundAny = true;
|
|
35
38
|
if (value < facetedMinValue) facetedMinValue = value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFacetedMinMaxValues.js","names":[],"sources":["../../../src/features/column-faceting/createFacetedMinMaxValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport {
|
|
1
|
+
{"version":3,"file":"createFacetedMinMaxValues.js","names":[],"sources":["../../../src/features/column-faceting/createFacetedMinMaxValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport { column_getCanGlobalFilter } from '../global-filtering/globalFilteringFeature.utils'\nimport {\n column_getFacetedRowModel,\n table_getGlobalFacetedRowModel,\n} from './columnFacetingFeature.utils'\nimport type { Row } from '../../types/Row'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted min max values helper for faceted filtering.\n *\n * The returned function derives facet data from the table row model and relevant filter state so filter UIs can display available values.\n */\nexport function createFacetedMinMaxValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => undefined | [number, number] {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n fn: (flatRows) => _createFacetedMinMaxValues(table, columnId, flatRows),\n fnName: 'table.getFacetedMinMaxValues',\n memoDeps: () => {\n if (columnId === '__global__') {\n return [\n callMemoOrStaticFn(\n table,\n 'getGlobalFacetedRowModel',\n table_getGlobalFacetedRowModel,\n ).flatRows,\n ]\n }\n const column = table.getColumn(columnId)\n if (!column) return [table.getPreFilteredRowModel().flatRows]\n return [\n callMemoOrStaticFn(\n column,\n 'getFacetedRowModel',\n column_getFacetedRowModel,\n table,\n ).flatRows,\n ]\n },\n table,\n })\n }\n}\n\nfunction _createFacetedMinMaxValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n flatRows: Array<Row<TFeatures, TData>>,\n): undefined | [number, number] {\n if (!flatRows.length) return undefined\n\n // The global context aggregates values across every column that\n // participates in global filtering\n const columnIds =\n columnId === '__global__'\n ? table\n .getAllLeafColumns()\n .filter((column) => column_getCanGlobalFilter(column))\n .map((column) => column.id)\n : [columnId]\n\n let facetedMinValue = Number.POSITIVE_INFINITY\n let facetedMaxValue = Number.NEGATIVE_INFINITY\n let foundAny = false\n\n for (let i = 0; i < flatRows.length; i++) {\n for (let c = 0; c < columnIds.length; c++) {\n const value = Number(flatRows[i]!.getValue(columnIds[c]!))\n if (Number.isNaN(value)) continue\n foundAny = true\n if (value < facetedMinValue) facetedMinValue = value\n if (value > facetedMaxValue) facetedMaxValue = value\n }\n }\n\n if (!foundAny) return undefined\n return [facetedMinValue, facetedMaxValue]\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,4BAMwB;CACtC,QAAQ,QAAQ,aAAa;EAC3B,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT,KAAK,aAAa,2BAA2B,OAAO,UAAU,QAAQ;GACtE,QAAQ;GACR,gBAAgB;IACd,IAAI,aAAa,cACf,OAAO,CACL,mBACE,OACA,4BACA,8BACF,CAAC,CAAC,QACJ;IAEF,MAAM,SAAS,MAAM,UAAU,QAAQ;IACvC,IAAI,CAAC,QAAQ,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC,QAAQ;IAC5D,OAAO,CACL,mBACE,QACA,sBACA,2BACA,KACF,CAAC,CAAC,QACJ;GACF;GACA;EACF,CAAC;CACH;AACF;AAEA,SAAS,2BAIP,OACA,UACA,UAC8B;CAC9B,IAAI,CAAC,SAAS,QAAQ,OAAO;CAI7B,MAAM,YACJ,aAAa,eACT,MACG,kBAAkB,CAAC,CACnB,QAAQ,WAAW,0BAA0B,MAAM,CAAC,CAAC,CACrD,KAAK,WAAW,OAAO,EAAE,IAC5B,CAAC,QAAQ;CAEf,IAAI,kBAAkB,OAAO;CAC7B,IAAI,kBAAkB,OAAO;CAC7B,IAAI,WAAW;CAEf,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EACzC,MAAM,QAAQ,OAAO,SAAS,EAAE,CAAE,SAAS,UAAU,EAAG,CAAC;EACzD,IAAI,OAAO,MAAM,KAAK,GAAG;EACzB,WAAW;EACX,IAAI,QAAQ,iBAAiB,kBAAkB;EAC/C,IAAI,QAAQ,iBAAiB,kBAAkB;CACjD;CAGF,IAAI,CAAC,UAAU,OAAO;CACtB,OAAO,CAAC,iBAAiB,eAAe;AAC1C"}
|
|
@@ -31,7 +31,7 @@ function _createFacetedRowModel(table, columnId, preRowModel, columnFilters, glo
|
|
|
31
31
|
const id = columnFilters[i].id;
|
|
32
32
|
if (id !== columnId) filterableIds.push(id);
|
|
33
33
|
}
|
|
34
|
-
if (globalFilter) filterableIds.push("__global__");
|
|
34
|
+
if (globalFilter && columnId !== "__global__") filterableIds.push("__global__");
|
|
35
35
|
if (!filterableIds.length) return preRowModel;
|
|
36
36
|
const filterRowsImpl = (row) => {
|
|
37
37
|
for (let i = 0; i < filterableIds.length; i++) if (row.columnFilters?.[filterableIds[i]] === false) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFacetedRowModel.cjs","names":["tableMemo","filterRows"],"sources":["../../../src/features/column-faceting/createFacetedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { filterRows } from '../column-filtering/filterRowsUtils'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type {\n ColumnFiltersState,\n Row_ColumnFiltering,\n} from '../column-filtering/columnFilteringFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n */\nexport function createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => RowModel<TFeatures, TData> {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n table,\n fnName: 'createFacetedRowModel',\n memoDeps: () => [\n table.getPreFilteredRowModel(),\n table.atoms.columnFilters?.get(),\n table.atoms.globalFilter?.get(),\n table.getFilteredRowModel(),\n ],\n fn: (preRowModel, columnFilters, globalFilter) =>\n _createFacetedRowModel(\n table,\n columnId,\n preRowModel,\n columnFilters,\n globalFilter,\n ),\n })\n }\n}\n\nfunction _createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n preRowModel: RowModel<TFeatures, TData>,\n columnFilters?: ColumnFiltersState,\n globalFilter?: string,\n) {\n if (!preRowModel.rows.length || (!columnFilters?.length && !globalFilter)) {\n return preRowModel\n }\n\n const filterableIds: Array<string> = []\n if (columnFilters) {\n for (let i = 0; i < columnFilters.length; i++) {\n const id = columnFilters[i]!.id\n if (id !== columnId) filterableIds.push(id)\n }\n }\n if (globalFilter)
|
|
1
|
+
{"version":3,"file":"createFacetedRowModel.cjs","names":["tableMemo","filterRows"],"sources":["../../../src/features/column-faceting/createFacetedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { filterRows } from '../column-filtering/filterRowsUtils'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type {\n ColumnFiltersState,\n Row_ColumnFiltering,\n} from '../column-filtering/columnFilteringFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n */\nexport function createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => RowModel<TFeatures, TData> {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n table,\n fnName: 'createFacetedRowModel',\n memoDeps: () => [\n table.getPreFilteredRowModel(),\n table.atoms.columnFilters?.get(),\n table.atoms.globalFilter?.get(),\n table.getFilteredRowModel(),\n ],\n fn: (preRowModel, columnFilters, globalFilter) =>\n _createFacetedRowModel(\n table,\n columnId,\n preRowModel,\n columnFilters,\n globalFilter,\n ),\n })\n }\n}\n\nfunction _createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n preRowModel: RowModel<TFeatures, TData>,\n columnFilters?: ColumnFiltersState,\n globalFilter?: string,\n) {\n if (!preRowModel.rows.length || (!columnFilters?.length && !globalFilter)) {\n return preRowModel\n }\n\n const filterableIds: Array<string> = []\n if (columnFilters) {\n for (let i = 0; i < columnFilters.length; i++) {\n const id = columnFilters[i]!.id\n if (id !== columnId) filterableIds.push(id)\n }\n }\n // The global context excludes the global filter itself, mirroring how a\n // column's faceted model excludes that column's own filter\n if (globalFilter && columnId !== '__global__')\n filterableIds.push('__global__')\n\n if (!filterableIds.length) {\n return preRowModel\n }\n\n const filterRowsImpl = (\n row: Row<TFeatures, TData> & Partial<Row_ColumnFiltering<TFeatures, TData>>,\n ) => {\n // Horizontally filter rows through each column\n for (let i = 0; i < filterableIds.length; i++) {\n if (row.columnFilters?.[filterableIds[i]!] === false) {\n return false\n }\n }\n return true\n }\n\n return filterRows(preRowModel.rows, filterRowsImpl, table)\n}\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,wBAMsB;CACpC,QAAQ,QAAQ,aAAa;EAC3B,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;IACd,MAAM,uBAAuB;IAC7B,MAAM,MAAM,eAAe,IAAI;IAC/B,MAAM,MAAM,cAAc,IAAI;IAC9B,MAAM,oBAAoB;GAC5B;GACA,KAAK,aAAa,eAAe,iBAC/B,uBACE,OACA,UACA,aACA,eACA,YACF;EACJ,CAAC;CACH;AACF;AAEA,SAAS,uBAIP,OACA,UACA,aACA,eACA,cACA;CACA,IAAI,CAAC,YAAY,KAAK,UAAW,CAAC,eAAe,UAAU,CAAC,cAC1D,OAAO;CAGT,MAAM,gBAA+B,CAAC;CACtC,IAAI,eACF,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;EAC7C,MAAM,KAAK,cAAc,EAAE,CAAE;EAC7B,IAAI,OAAO,UAAU,cAAc,KAAK,EAAE;CAC5C;CAIF,IAAI,gBAAgB,aAAa,cAC/B,cAAc,KAAK,YAAY;CAEjC,IAAI,CAAC,cAAc,QACjB,OAAO;CAGT,MAAM,kBACJ,QACG;EAEH,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KACxC,IAAI,IAAI,gBAAgB,cAAc,QAAS,OAC7C,OAAO;EAGX,OAAO;CACT;CAEA,OAAOC,mCAAW,YAAY,MAAM,gBAAgB,KAAK;AAC3D"}
|
|
@@ -31,7 +31,7 @@ function _createFacetedRowModel(table, columnId, preRowModel, columnFilters, glo
|
|
|
31
31
|
const id = columnFilters[i].id;
|
|
32
32
|
if (id !== columnId) filterableIds.push(id);
|
|
33
33
|
}
|
|
34
|
-
if (globalFilter) filterableIds.push("__global__");
|
|
34
|
+
if (globalFilter && columnId !== "__global__") filterableIds.push("__global__");
|
|
35
35
|
if (!filterableIds.length) return preRowModel;
|
|
36
36
|
const filterRowsImpl = (row) => {
|
|
37
37
|
for (let i = 0; i < filterableIds.length; i++) if (row.columnFilters?.[filterableIds[i]] === false) return false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFacetedRowModel.js","names":[],"sources":["../../../src/features/column-faceting/createFacetedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { filterRows } from '../column-filtering/filterRowsUtils'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type {\n ColumnFiltersState,\n Row_ColumnFiltering,\n} from '../column-filtering/columnFilteringFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n */\nexport function createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => RowModel<TFeatures, TData> {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n table,\n fnName: 'createFacetedRowModel',\n memoDeps: () => [\n table.getPreFilteredRowModel(),\n table.atoms.columnFilters?.get(),\n table.atoms.globalFilter?.get(),\n table.getFilteredRowModel(),\n ],\n fn: (preRowModel, columnFilters, globalFilter) =>\n _createFacetedRowModel(\n table,\n columnId,\n preRowModel,\n columnFilters,\n globalFilter,\n ),\n })\n }\n}\n\nfunction _createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n preRowModel: RowModel<TFeatures, TData>,\n columnFilters?: ColumnFiltersState,\n globalFilter?: string,\n) {\n if (!preRowModel.rows.length || (!columnFilters?.length && !globalFilter)) {\n return preRowModel\n }\n\n const filterableIds: Array<string> = []\n if (columnFilters) {\n for (let i = 0; i < columnFilters.length; i++) {\n const id = columnFilters[i]!.id\n if (id !== columnId) filterableIds.push(id)\n }\n }\n if (globalFilter)
|
|
1
|
+
{"version":3,"file":"createFacetedRowModel.js","names":[],"sources":["../../../src/features/column-faceting/createFacetedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { filterRows } from '../column-filtering/filterRowsUtils'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type {\n ColumnFiltersState,\n Row_ColumnFiltering,\n} from '../column-filtering/columnFilteringFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted row model factory.\n *\n * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.\n */\nexport function createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => RowModel<TFeatures, TData> {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n table,\n fnName: 'createFacetedRowModel',\n memoDeps: () => [\n table.getPreFilteredRowModel(),\n table.atoms.columnFilters?.get(),\n table.atoms.globalFilter?.get(),\n table.getFilteredRowModel(),\n ],\n fn: (preRowModel, columnFilters, globalFilter) =>\n _createFacetedRowModel(\n table,\n columnId,\n preRowModel,\n columnFilters,\n globalFilter,\n ),\n })\n }\n}\n\nfunction _createFacetedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n preRowModel: RowModel<TFeatures, TData>,\n columnFilters?: ColumnFiltersState,\n globalFilter?: string,\n) {\n if (!preRowModel.rows.length || (!columnFilters?.length && !globalFilter)) {\n return preRowModel\n }\n\n const filterableIds: Array<string> = []\n if (columnFilters) {\n for (let i = 0; i < columnFilters.length; i++) {\n const id = columnFilters[i]!.id\n if (id !== columnId) filterableIds.push(id)\n }\n }\n // The global context excludes the global filter itself, mirroring how a\n // column's faceted model excludes that column's own filter\n if (globalFilter && columnId !== '__global__')\n filterableIds.push('__global__')\n\n if (!filterableIds.length) {\n return preRowModel\n }\n\n const filterRowsImpl = (\n row: Row<TFeatures, TData> & Partial<Row_ColumnFiltering<TFeatures, TData>>,\n ) => {\n // Horizontally filter rows through each column\n for (let i = 0; i < filterableIds.length; i++) {\n if (row.columnFilters?.[filterableIds[i]!] === false) {\n return false\n }\n }\n return true\n }\n\n return filterRows(preRowModel.rows, filterRowsImpl, table)\n}\n"],"mappings":";;;;;;;;;AAiBA,SAAgB,wBAMsB;CACpC,QAAQ,QAAQ,aAAa;EAC3B,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;IACd,MAAM,uBAAuB;IAC7B,MAAM,MAAM,eAAe,IAAI;IAC/B,MAAM,MAAM,cAAc,IAAI;IAC9B,MAAM,oBAAoB;GAC5B;GACA,KAAK,aAAa,eAAe,iBAC/B,uBACE,OACA,UACA,aACA,eACA,YACF;EACJ,CAAC;CACH;AACF;AAEA,SAAS,uBAIP,OACA,UACA,aACA,eACA,cACA;CACA,IAAI,CAAC,YAAY,KAAK,UAAW,CAAC,eAAe,UAAU,CAAC,cAC1D,OAAO;CAGT,MAAM,gBAA+B,CAAC;CACtC,IAAI,eACF,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KAAK;EAC7C,MAAM,KAAK,cAAc,EAAE,CAAE;EAC7B,IAAI,OAAO,UAAU,cAAc,KAAK,EAAE;CAC5C;CAIF,IAAI,gBAAgB,aAAa,cAC/B,cAAc,KAAK,YAAY;CAEjC,IAAI,CAAC,cAAc,QACjB,OAAO;CAGT,MAAM,kBACJ,QACG;EAEH,KAAK,IAAI,IAAI,GAAG,IAAI,cAAc,QAAQ,KACxC,IAAI,IAAI,gBAAgB,cAAc,QAAS,OAC7C,OAAO;EAGX,OAAO;CACT;CAEA,OAAO,WAAW,YAAY,MAAM,gBAAgB,KAAK;AAC3D"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const require_utils = require('../../utils.cjs');
|
|
2
2
|
const require_columnFacetingFeature_utils = require('./columnFacetingFeature.utils.cjs');
|
|
3
|
+
const require_globalFilteringFeature_utils = require('../global-filtering/globalFilteringFeature.utils.cjs');
|
|
3
4
|
|
|
4
5
|
//#region src/features/column-faceting/createFacetedUniqueValues.ts
|
|
5
6
|
/**
|
|
@@ -15,18 +16,21 @@ function createFacetedUniqueValues() {
|
|
|
15
16
|
table,
|
|
16
17
|
fnName: "table.getFacetedUniqueValues",
|
|
17
18
|
memoDeps: () => {
|
|
19
|
+
if (columnId === "__global__") return [require_utils.callMemoOrStaticFn(table, "getGlobalFacetedRowModel", require_columnFacetingFeature_utils.table_getGlobalFacetedRowModel).flatRows];
|
|
18
20
|
const column = table.getColumn(columnId);
|
|
19
21
|
if (!column) return [table.getPreFilteredRowModel().flatRows];
|
|
20
22
|
return [require_utils.callMemoOrStaticFn(column, "getFacetedRowModel", require_columnFacetingFeature_utils.column_getFacetedRowModel, table).flatRows];
|
|
21
23
|
},
|
|
22
|
-
fn: (flatRows) => _createFacetedUniqueValues(columnId, flatRows)
|
|
24
|
+
fn: (flatRows) => _createFacetedUniqueValues(table, columnId, flatRows)
|
|
23
25
|
});
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
|
-
function _createFacetedUniqueValues(columnId, flatRows) {
|
|
28
|
+
function _createFacetedUniqueValues(table, columnId, flatRows) {
|
|
29
|
+
const columnIds = columnId === "__global__" ? table.getAllLeafColumns().filter((column) => require_globalFilteringFeature_utils.column_getCanGlobalFilter(column)).map((column) => column.id) : [columnId];
|
|
27
30
|
const facetedUniqueValues = /* @__PURE__ */ new Map();
|
|
28
|
-
for (let i = 0; i < flatRows.length; i++) {
|
|
29
|
-
const values = flatRows[i].getUniqueValues(
|
|
31
|
+
for (let i = 0; i < flatRows.length; i++) for (let c = 0; c < columnIds.length; c++) {
|
|
32
|
+
const values = flatRows[i].getUniqueValues(columnIds[c]);
|
|
33
|
+
if (!values) continue;
|
|
30
34
|
for (let j = 0; j < values.length; j++) {
|
|
31
35
|
const value = values[j];
|
|
32
36
|
const previousValue = facetedUniqueValues.get(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFacetedUniqueValues.cjs","names":["tableMemo","callMemoOrStaticFn","column_getFacetedRowModel"],"sources":["../../../src/features/column-faceting/createFacetedUniqueValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport {
|
|
1
|
+
{"version":3,"file":"createFacetedUniqueValues.cjs","names":["tableMemo","callMemoOrStaticFn","table_getGlobalFacetedRowModel","column_getFacetedRowModel","column_getCanGlobalFilter"],"sources":["../../../src/features/column-faceting/createFacetedUniqueValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport { column_getCanGlobalFilter } from '../global-filtering/globalFilteringFeature.utils'\nimport {\n column_getFacetedRowModel,\n table_getGlobalFacetedRowModel,\n} from './columnFacetingFeature.utils'\nimport type { Row } from '../../types/Row'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted unique values helper for faceted filtering.\n *\n * The returned function derives facet data from the table row model and relevant filter state so filter UIs can display available values.\n */\nexport function createFacetedUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => Map<any, number> {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n table,\n fnName: 'table.getFacetedUniqueValues',\n memoDeps: () => {\n if (columnId === '__global__') {\n return [\n callMemoOrStaticFn(\n table,\n 'getGlobalFacetedRowModel',\n table_getGlobalFacetedRowModel,\n ).flatRows,\n ]\n }\n const column = table.getColumn(columnId)\n if (!column) return [table.getPreFilteredRowModel().flatRows]\n return [\n callMemoOrStaticFn(\n column,\n 'getFacetedRowModel',\n column_getFacetedRowModel,\n table,\n ).flatRows,\n ]\n },\n fn: (flatRows) => _createFacetedUniqueValues(table, columnId, flatRows),\n })\n }\n}\n\nfunction _createFacetedUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n flatRows: Array<Row<TFeatures, TData>>,\n): Map<any, number> {\n // The global context aggregates unique values across every column that\n // participates in global filtering\n const columnIds =\n columnId === '__global__'\n ? table\n .getAllLeafColumns()\n .filter((column) => column_getCanGlobalFilter(column))\n .map((column) => column.id)\n : [columnId]\n\n const facetedUniqueValues = new Map<any, number>()\n\n for (let i = 0; i < flatRows.length; i++) {\n for (let c = 0; c < columnIds.length; c++) {\n // the declared return type is Array, but rows return undefined for\n // columns without an accessor (e.g. display columns)\n const values = flatRows[i]!.getUniqueValues(columnIds[c]!) as\n | Array<unknown>\n | undefined\n if (!values) continue\n\n for (let j = 0; j < values.length; j++) {\n const value = values[j]\n const previousValue = facetedUniqueValues.get(value)\n facetedUniqueValues.set(\n value,\n previousValue === undefined ? 1 : previousValue + 1,\n )\n }\n }\n }\n\n return facetedUniqueValues\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,4BAMY;CAC1B,QAAQ,QAAQ,aAAa;EAC3B,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;IACd,IAAI,aAAa,cACf,OAAO,CACLC,iCACE,OACA,4BACAC,kEACF,CAAC,CAAC,QACJ;IAEF,MAAM,SAAS,MAAM,UAAU,QAAQ;IACvC,IAAI,CAAC,QAAQ,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC,QAAQ;IAC5D,OAAO,CACLD,iCACE,QACA,sBACAE,+DACA,KACF,CAAC,CAAC,QACJ;GACF;GACA,KAAK,aAAa,2BAA2B,OAAO,UAAU,QAAQ;EACxE,CAAC;CACH;AACF;AAEA,SAAS,2BAIP,OACA,UACA,UACkB;CAGlB,MAAM,YACJ,aAAa,eACT,MACG,kBAAkB,CAAC,CACnB,QAAQ,WAAWC,+DAA0B,MAAM,CAAC,CAAC,CACrD,KAAK,WAAW,OAAO,EAAE,IAC5B,CAAC,QAAQ;CAEf,MAAM,sCAAsB,IAAI,IAAiB;CAEjD,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EAGzC,MAAM,SAAS,SAAS,EAAE,CAAE,gBAAgB,UAAU,EAAG;EAGzD,IAAI,CAAC,QAAQ;EAEb,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;GACtC,MAAM,QAAQ,OAAO;GACrB,MAAM,gBAAgB,oBAAoB,IAAI,KAAK;GACnD,oBAAoB,IAClB,OACA,kBAAkB,SAAY,IAAI,gBAAgB,CACpD;EACF;CACF;CAGF,OAAO;AACT"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { callMemoOrStaticFn, tableMemo } from "../../utils.js";
|
|
2
|
-
import { column_getFacetedRowModel } from "./columnFacetingFeature.utils.js";
|
|
2
|
+
import { column_getFacetedRowModel, table_getGlobalFacetedRowModel } from "./columnFacetingFeature.utils.js";
|
|
3
|
+
import { column_getCanGlobalFilter } from "../global-filtering/globalFilteringFeature.utils.js";
|
|
3
4
|
|
|
4
5
|
//#region src/features/column-faceting/createFacetedUniqueValues.ts
|
|
5
6
|
/**
|
|
@@ -15,18 +16,21 @@ function createFacetedUniqueValues() {
|
|
|
15
16
|
table,
|
|
16
17
|
fnName: "table.getFacetedUniqueValues",
|
|
17
18
|
memoDeps: () => {
|
|
19
|
+
if (columnId === "__global__") return [callMemoOrStaticFn(table, "getGlobalFacetedRowModel", table_getGlobalFacetedRowModel).flatRows];
|
|
18
20
|
const column = table.getColumn(columnId);
|
|
19
21
|
if (!column) return [table.getPreFilteredRowModel().flatRows];
|
|
20
22
|
return [callMemoOrStaticFn(column, "getFacetedRowModel", column_getFacetedRowModel, table).flatRows];
|
|
21
23
|
},
|
|
22
|
-
fn: (flatRows) => _createFacetedUniqueValues(columnId, flatRows)
|
|
24
|
+
fn: (flatRows) => _createFacetedUniqueValues(table, columnId, flatRows)
|
|
23
25
|
});
|
|
24
26
|
};
|
|
25
27
|
}
|
|
26
|
-
function _createFacetedUniqueValues(columnId, flatRows) {
|
|
28
|
+
function _createFacetedUniqueValues(table, columnId, flatRows) {
|
|
29
|
+
const columnIds = columnId === "__global__" ? table.getAllLeafColumns().filter((column) => column_getCanGlobalFilter(column)).map((column) => column.id) : [columnId];
|
|
27
30
|
const facetedUniqueValues = /* @__PURE__ */ new Map();
|
|
28
|
-
for (let i = 0; i < flatRows.length; i++) {
|
|
29
|
-
const values = flatRows[i].getUniqueValues(
|
|
31
|
+
for (let i = 0; i < flatRows.length; i++) for (let c = 0; c < columnIds.length; c++) {
|
|
32
|
+
const values = flatRows[i].getUniqueValues(columnIds[c]);
|
|
33
|
+
if (!values) continue;
|
|
30
34
|
for (let j = 0; j < values.length; j++) {
|
|
31
35
|
const value = values[j];
|
|
32
36
|
const previousValue = facetedUniqueValues.get(value);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createFacetedUniqueValues.js","names":[],"sources":["../../../src/features/column-faceting/createFacetedUniqueValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport {
|
|
1
|
+
{"version":3,"file":"createFacetedUniqueValues.js","names":[],"sources":["../../../src/features/column-faceting/createFacetedUniqueValues.ts"],"sourcesContent":["import { callMemoOrStaticFn, tableMemo } from '../../utils'\nimport { column_getCanGlobalFilter } from '../global-filtering/globalFilteringFeature.utils'\nimport {\n column_getFacetedRowModel,\n table_getGlobalFacetedRowModel,\n} from './columnFacetingFeature.utils'\nimport type { Row } from '../../types/Row'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized faceted unique values helper for faceted filtering.\n *\n * The returned function derives facet data from the table row model and relevant filter state so filter UIs can display available values.\n */\nexport function createFacetedUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (\n table: Table<TFeatures, TData>,\n columnId: string,\n) => () => Map<any, number> {\n return (_table, columnId) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnFacetingFeature',\n table,\n fnName: 'table.getFacetedUniqueValues',\n memoDeps: () => {\n if (columnId === '__global__') {\n return [\n callMemoOrStaticFn(\n table,\n 'getGlobalFacetedRowModel',\n table_getGlobalFacetedRowModel,\n ).flatRows,\n ]\n }\n const column = table.getColumn(columnId)\n if (!column) return [table.getPreFilteredRowModel().flatRows]\n return [\n callMemoOrStaticFn(\n column,\n 'getFacetedRowModel',\n column_getFacetedRowModel,\n table,\n ).flatRows,\n ]\n },\n fn: (flatRows) => _createFacetedUniqueValues(table, columnId, flatRows),\n })\n }\n}\n\nfunction _createFacetedUniqueValues<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(\n table: Table_Internal<TFeatures, TData>,\n columnId: string,\n flatRows: Array<Row<TFeatures, TData>>,\n): Map<any, number> {\n // The global context aggregates unique values across every column that\n // participates in global filtering\n const columnIds =\n columnId === '__global__'\n ? table\n .getAllLeafColumns()\n .filter((column) => column_getCanGlobalFilter(column))\n .map((column) => column.id)\n : [columnId]\n\n const facetedUniqueValues = new Map<any, number>()\n\n for (let i = 0; i < flatRows.length; i++) {\n for (let c = 0; c < columnIds.length; c++) {\n // the declared return type is Array, but rows return undefined for\n // columns without an accessor (e.g. display columns)\n const values = flatRows[i]!.getUniqueValues(columnIds[c]!) as\n | Array<unknown>\n | undefined\n if (!values) continue\n\n for (let j = 0; j < values.length; j++) {\n const value = values[j]\n const previousValue = facetedUniqueValues.get(value)\n facetedUniqueValues.set(\n value,\n previousValue === undefined ? 1 : previousValue + 1,\n )\n }\n }\n }\n\n return facetedUniqueValues\n}\n"],"mappings":";;;;;;;;;;AAgBA,SAAgB,4BAMY;CAC1B,QAAQ,QAAQ,aAAa;EAC3B,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;IACd,IAAI,aAAa,cACf,OAAO,CACL,mBACE,OACA,4BACA,8BACF,CAAC,CAAC,QACJ;IAEF,MAAM,SAAS,MAAM,UAAU,QAAQ;IACvC,IAAI,CAAC,QAAQ,OAAO,CAAC,MAAM,uBAAuB,CAAC,CAAC,QAAQ;IAC5D,OAAO,CACL,mBACE,QACA,sBACA,2BACA,KACF,CAAC,CAAC,QACJ;GACF;GACA,KAAK,aAAa,2BAA2B,OAAO,UAAU,QAAQ;EACxE,CAAC;CACH;AACF;AAEA,SAAS,2BAIP,OACA,UACA,UACkB;CAGlB,MAAM,YACJ,aAAa,eACT,MACG,kBAAkB,CAAC,CACnB,QAAQ,WAAW,0BAA0B,MAAM,CAAC,CAAC,CACrD,KAAK,WAAW,OAAO,EAAE,IAC5B,CAAC,QAAQ;CAEf,MAAM,sCAAsB,IAAI,IAAiB;CAEjD,KAAK,IAAI,IAAI,GAAG,IAAI,SAAS,QAAQ,KACnC,KAAK,IAAI,IAAI,GAAG,IAAI,UAAU,QAAQ,KAAK;EAGzC,MAAM,SAAS,SAAS,EAAE,CAAE,gBAAgB,UAAU,EAAG;EAGzD,IAAI,CAAC,QAAQ;EAEb,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;GACtC,MAAM,QAAQ,OAAO;GACrB,MAAM,gBAAgB,oBAAoB,IAAI,KAAK;GACnD,oBAAoB,IAClB,OACA,kBAAkB,SAAY,IAAI,gBAAgB,CACpD;EACF;CACF;CAGF,OAAO;AACT"}
|
package/package.json
CHANGED
package/skills/core/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: sub-skill
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.49'
|
|
9
9
|
requires: ['core', 'table-features', 'typescript']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/framework/react/guide/custom-features.md'
|
package/skills/grouping/SKILL.md
CHANGED
|
@@ -5,7 +5,7 @@ description: >
|
|
|
5
5
|
metadata:
|
|
6
6
|
type: lifecycle
|
|
7
7
|
library: '@tanstack/table-core'
|
|
8
|
-
library_version: '9.0.0-beta.
|
|
8
|
+
library_version: '9.0.0-beta.49'
|
|
9
9
|
requires: ['core', 'table-features', 'typescript']
|
|
10
10
|
sources:
|
|
11
11
|
- 'TanStack/table:docs/framework/react/guide/migrating.md'
|
package/skills/sorting/SKILL.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { callMemoOrStaticFn, tableMemo } from '../../utils'
|
|
2
|
-
import {
|
|
2
|
+
import { column_getCanGlobalFilter } from '../global-filtering/globalFilteringFeature.utils'
|
|
3
|
+
import {
|
|
4
|
+
column_getFacetedRowModel,
|
|
5
|
+
table_getGlobalFacetedRowModel,
|
|
6
|
+
} from './columnFacetingFeature.utils'
|
|
3
7
|
import type { Row } from '../../types/Row'
|
|
4
8
|
import type { Table, Table_Internal } from '../../types/Table'
|
|
5
9
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
@@ -21,9 +25,18 @@ export function createFacetedMinMaxValues<
|
|
|
21
25
|
const table = _table as unknown as Table_Internal<TFeatures, TData>
|
|
22
26
|
return tableMemo({
|
|
23
27
|
feature: 'columnFacetingFeature',
|
|
24
|
-
fn: (flatRows) => _createFacetedMinMaxValues(columnId, flatRows),
|
|
28
|
+
fn: (flatRows) => _createFacetedMinMaxValues(table, columnId, flatRows),
|
|
25
29
|
fnName: 'table.getFacetedMinMaxValues',
|
|
26
30
|
memoDeps: () => {
|
|
31
|
+
if (columnId === '__global__') {
|
|
32
|
+
return [
|
|
33
|
+
callMemoOrStaticFn(
|
|
34
|
+
table,
|
|
35
|
+
'getGlobalFacetedRowModel',
|
|
36
|
+
table_getGlobalFacetedRowModel,
|
|
37
|
+
).flatRows,
|
|
38
|
+
]
|
|
39
|
+
}
|
|
27
40
|
const column = table.getColumn(columnId)
|
|
28
41
|
if (!column) return [table.getPreFilteredRowModel().flatRows]
|
|
29
42
|
return [
|
|
@@ -44,21 +57,34 @@ function _createFacetedMinMaxValues<
|
|
|
44
57
|
TFeatures extends TableFeatures,
|
|
45
58
|
TData extends RowData = any,
|
|
46
59
|
>(
|
|
60
|
+
table: Table_Internal<TFeatures, TData>,
|
|
47
61
|
columnId: string,
|
|
48
62
|
flatRows: Array<Row<TFeatures, TData>>,
|
|
49
63
|
): undefined | [number, number] {
|
|
50
64
|
if (!flatRows.length) return undefined
|
|
51
65
|
|
|
66
|
+
// The global context aggregates values across every column that
|
|
67
|
+
// participates in global filtering
|
|
68
|
+
const columnIds =
|
|
69
|
+
columnId === '__global__'
|
|
70
|
+
? table
|
|
71
|
+
.getAllLeafColumns()
|
|
72
|
+
.filter((column) => column_getCanGlobalFilter(column))
|
|
73
|
+
.map((column) => column.id)
|
|
74
|
+
: [columnId]
|
|
75
|
+
|
|
52
76
|
let facetedMinValue = Number.POSITIVE_INFINITY
|
|
53
77
|
let facetedMaxValue = Number.NEGATIVE_INFINITY
|
|
54
78
|
let foundAny = false
|
|
55
79
|
|
|
56
80
|
for (let i = 0; i < flatRows.length; i++) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
81
|
+
for (let c = 0; c < columnIds.length; c++) {
|
|
82
|
+
const value = Number(flatRows[i]!.getValue(columnIds[c]!))
|
|
83
|
+
if (Number.isNaN(value)) continue
|
|
84
|
+
foundAny = true
|
|
85
|
+
if (value < facetedMinValue) facetedMinValue = value
|
|
86
|
+
if (value > facetedMaxValue) facetedMaxValue = value
|
|
87
|
+
}
|
|
62
88
|
}
|
|
63
89
|
|
|
64
90
|
if (!foundAny) return undefined
|
|
@@ -67,7 +67,10 @@ function _createFacetedRowModel<
|
|
|
67
67
|
if (id !== columnId) filterableIds.push(id)
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
|
|
70
|
+
// The global context excludes the global filter itself, mirroring how a
|
|
71
|
+
// column's faceted model excludes that column's own filter
|
|
72
|
+
if (globalFilter && columnId !== '__global__')
|
|
73
|
+
filterableIds.push('__global__')
|
|
71
74
|
|
|
72
75
|
if (!filterableIds.length) {
|
|
73
76
|
return preRowModel
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { callMemoOrStaticFn, tableMemo } from '../../utils'
|
|
2
|
-
import {
|
|
2
|
+
import { column_getCanGlobalFilter } from '../global-filtering/globalFilteringFeature.utils'
|
|
3
|
+
import {
|
|
4
|
+
column_getFacetedRowModel,
|
|
5
|
+
table_getGlobalFacetedRowModel,
|
|
6
|
+
} from './columnFacetingFeature.utils'
|
|
3
7
|
import type { Row } from '../../types/Row'
|
|
4
8
|
import type { Table, Table_Internal } from '../../types/Table'
|
|
5
9
|
import type { TableFeatures } from '../../types/TableFeatures'
|
|
@@ -24,6 +28,15 @@ export function createFacetedUniqueValues<
|
|
|
24
28
|
table,
|
|
25
29
|
fnName: 'table.getFacetedUniqueValues',
|
|
26
30
|
memoDeps: () => {
|
|
31
|
+
if (columnId === '__global__') {
|
|
32
|
+
return [
|
|
33
|
+
callMemoOrStaticFn(
|
|
34
|
+
table,
|
|
35
|
+
'getGlobalFacetedRowModel',
|
|
36
|
+
table_getGlobalFacetedRowModel,
|
|
37
|
+
).flatRows,
|
|
38
|
+
]
|
|
39
|
+
}
|
|
27
40
|
const column = table.getColumn(columnId)
|
|
28
41
|
if (!column) return [table.getPreFilteredRowModel().flatRows]
|
|
29
42
|
return [
|
|
@@ -35,7 +48,7 @@ export function createFacetedUniqueValues<
|
|
|
35
48
|
).flatRows,
|
|
36
49
|
]
|
|
37
50
|
},
|
|
38
|
-
fn: (flatRows) => _createFacetedUniqueValues(columnId, flatRows),
|
|
51
|
+
fn: (flatRows) => _createFacetedUniqueValues(table, columnId, flatRows),
|
|
39
52
|
})
|
|
40
53
|
}
|
|
41
54
|
}
|
|
@@ -43,19 +56,40 @@ export function createFacetedUniqueValues<
|
|
|
43
56
|
function _createFacetedUniqueValues<
|
|
44
57
|
TFeatures extends TableFeatures,
|
|
45
58
|
TData extends RowData = any,
|
|
46
|
-
>(
|
|
59
|
+
>(
|
|
60
|
+
table: Table_Internal<TFeatures, TData>,
|
|
61
|
+
columnId: string,
|
|
62
|
+
flatRows: Array<Row<TFeatures, TData>>,
|
|
63
|
+
): Map<any, number> {
|
|
64
|
+
// The global context aggregates unique values across every column that
|
|
65
|
+
// participates in global filtering
|
|
66
|
+
const columnIds =
|
|
67
|
+
columnId === '__global__'
|
|
68
|
+
? table
|
|
69
|
+
.getAllLeafColumns()
|
|
70
|
+
.filter((column) => column_getCanGlobalFilter(column))
|
|
71
|
+
.map((column) => column.id)
|
|
72
|
+
: [columnId]
|
|
73
|
+
|
|
47
74
|
const facetedUniqueValues = new Map<any, number>()
|
|
48
75
|
|
|
49
76
|
for (let i = 0; i < flatRows.length; i++) {
|
|
50
|
-
|
|
77
|
+
for (let c = 0; c < columnIds.length; c++) {
|
|
78
|
+
// the declared return type is Array, but rows return undefined for
|
|
79
|
+
// columns without an accessor (e.g. display columns)
|
|
80
|
+
const values = flatRows[i]!.getUniqueValues(columnIds[c]!) as
|
|
81
|
+
| Array<unknown>
|
|
82
|
+
| undefined
|
|
83
|
+
if (!values) continue
|
|
51
84
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
85
|
+
for (let j = 0; j < values.length; j++) {
|
|
86
|
+
const value = values[j]
|
|
87
|
+
const previousValue = facetedUniqueValues.get(value)
|
|
88
|
+
facetedUniqueValues.set(
|
|
89
|
+
value,
|
|
90
|
+
previousValue === undefined ? 1 : previousValue + 1,
|
|
91
|
+
)
|
|
92
|
+
}
|
|
59
93
|
}
|
|
60
94
|
}
|
|
61
95
|
|