@tanstack/table-core 9.0.0-beta.29 → 9.0.0-beta.31

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.
@@ -51,9 +51,14 @@ function _createGroupedRowModel(table) {
51
51
  const groupUpRecursively = (rows, depth = 0, parentId) => {
52
52
  if (depth >= existingGrouping.length) return rows.map((row) => {
53
53
  row.depth = depth;
54
- groupedFlatRows.push(row);
55
- groupedRowsById[row.id] = row;
56
- if (row.subRows.length) row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id);
54
+ if (row.subRows.length) {
55
+ row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id);
56
+ for (let i = 0; i < row.subRows.length; i++) {
57
+ const subRow = row.subRows[i];
58
+ groupedFlatRows.push(subRow);
59
+ groupedRowsById[subRow.id] = subRow;
60
+ }
61
+ }
57
62
  return row;
58
63
  });
59
64
  const columnId = existingGrouping[depth];
@@ -1 +1 @@
1
- {"version":3,"file":"createGroupedRowModel.cjs","names":["tableMemo","table_getColumn","makeObjectMap","flattenBy","constructRow","hasOwn","column_getAggregationFn","row_getGroupingValue"],"sources":["../../../src/features/column-grouping/createGroupedRowModel.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap, tableMemo } from '../../utils'\nimport { constructRow } from '../../core/rows/constructRow'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport { table_autoResetExpanded } from '../row-expanding/rowExpandingFeature.utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport {\n column_getAggregationFn,\n row_getGroupingValue,\n} from './columnGroupingFeature.utils'\nimport type { Column } from '../../types/Column'\nimport type { Row_ColumnGrouping } from './columnGroupingFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized grouped 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 *\n * Register aggregation functions with the `aggregationFns` slot on the\n * `features` option:\n * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.\n */\nexport function createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnGroupingFeature',\n table,\n fnName: 'table.getGroupedRowModel',\n memoDeps: () => [\n table.atoms.grouping?.get(),\n table.getPreGroupedRowModel(),\n ],\n fn: () => _createGroupedRowModel(table),\n onAfterUpdate: () => {\n table_autoResetExpanded(table)\n table_autoResetPageIndex(table)\n },\n })\n }\n}\n\nfunction _createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const rowModel = table.getPreGroupedRowModel()\n const grouping = table.atoms.grouping?.get()\n\n if (!rowModel.rows.length || !grouping?.length) {\n rowModel.rows.forEach((row) => {\n row.depth = 0\n row.parentId = undefined\n })\n return rowModel\n }\n\n // Filter the grouping list down to columns that exist\n const existingGrouping = grouping.filter((columnId) =>\n table_getColumn(table, columnId),\n )\n\n const groupedFlatRows: Array<Row<TFeatures, TData>> &\n Partial<Row_ColumnGrouping> = []\n const groupedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n\n // Recursively group the data\n const groupUpRecursively = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n parentId?: string,\n ) => {\n // Grouping depth has been been met\n // Stop grouping and simply rewrite thd depth and row relationships\n if (depth >= existingGrouping.length) {\n return rows.map((row) => {\n row.depth = depth\n\n groupedFlatRows.push(row)\n groupedRowsById[row.id] = row\n\n if (row.subRows.length) {\n row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)\n }\n\n return row\n })\n }\n\n const columnId = existingGrouping[depth] as string\n\n // Group the rows together for this level\n const rowGroupsMap = groupBy(rows, columnId)\n\n // Perform aggregations for each group\n const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(\n ([groupingValue, groupedRows], index) => {\n let id = `${columnId}:${groupingValue}`\n id = parentId ? `${parentId}>${id}` : id\n\n // First, Recurse to group sub rows before aggregation\n const subRows = groupUpRecursively(groupedRows, depth + 1, id)\n\n subRows.forEach((subRow) => {\n subRow.parentId = id\n })\n\n // Flatten the leaf rows of the rows in this group\n const leafRows = depth\n ? flattenBy(groupedRows, (row) => row.subRows)\n : groupedRows\n\n const row = constructRow(\n table,\n id,\n leafRows[0]!.original,\n index,\n depth,\n undefined,\n parentId,\n ) as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n\n Object.assign(row, {\n groupingColumnId: columnId,\n groupingValue,\n subRows,\n leafRows,\n getValue: (colId: string) => {\n // Don't aggregate columns that are in the grouping\n if (existingGrouping.includes(colId)) {\n if (hasOwn(row._valuesCache, colId)) {\n return row._valuesCache[colId]\n }\n\n if (groupedRows[0]) {\n row._valuesCache[colId] =\n groupedRows[0].getValue(colId) ?? undefined\n }\n\n return row._valuesCache[colId]\n }\n\n if (\n row._groupingValuesCache &&\n hasOwn(row._groupingValuesCache, colId)\n ) {\n return row._groupingValuesCache[colId]\n }\n\n // Aggregate the values\n const column = table.getColumn(colId)\n const aggregateFn = column_getAggregationFn(\n column as Column<TFeatures, TData, unknown>,\n )\n\n if (!row._groupingValuesCache) {\n row._groupingValuesCache = makeObjectMap()\n }\n\n if (aggregateFn) {\n row._groupingValuesCache[colId] = aggregateFn(\n colId,\n leafRows,\n groupedRows,\n )\n\n return row._groupingValuesCache[colId]\n }\n },\n })\n\n subRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return row\n },\n )\n\n return aggregatedGroupedRows\n }\n\n const groupedRows = groupUpRecursively(rowModel.rows, 0)\n\n groupedRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return {\n rows: groupedRows,\n flatRows: groupedFlatRows,\n rowsById: groupedRowsById,\n }\n}\n\nfunction groupBy<TFeatures extends TableFeatures, TData extends RowData = any>(\n rows: Array<Row<TFeatures, TData>>,\n columnId: string,\n) {\n const groupMap = new Map<any, Array<Row<TFeatures, TData>>>()\n\n return rows.reduce((map, row) => {\n const resKey = `${row_getGroupingValue(row, columnId)}`\n const previous = map.get(resKey)\n if (!previous) {\n map.set(resKey, [row])\n } else {\n previous.push(row)\n }\n return map\n }, groupMap)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAgB,wBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;qCACd,MAAM,MAAM,wFAAU,IAAI,GAC1B,MAAM,sBAAsB,CAC9B;;GACA,UAAU,uBAAuB,KAAK;GACtC,qBAAqB;IACnB,0DAAwB,KAAK;IAC7B,4DAAyB,KAAK;GAChC;EACF,CAAC;CACH;AACF;AAEA,SAAS,uBAGP,OAAqE;;CACrE,MAAM,WAAW,MAAM,sBAAsB;CAC7C,MAAM,qCAAW,MAAM,MAAM,0FAAU,IAAI;CAE3C,IAAI,CAAC,SAAS,KAAK,UAAU,sDAAC,SAAU,SAAQ;EAC9C,SAAS,KAAK,SAAS,QAAQ;GAC7B,IAAI,QAAQ;GACZ,IAAI,WAAW;EACjB,CAAC;EACD,OAAO;CACT;CAGA,MAAM,mBAAmB,SAAS,QAAQ,aACxCC,iDAAgB,OAAO,QAAQ,CACjC;CAEA,MAAM,kBAC0B,CAAC;CACjC,MAAM,kBAAkBC,4BAAqC;CAG7D,MAAM,sBACJ,MACA,QAAQ,GACR,aACG;EAGH,IAAI,SAAS,iBAAiB,QAC5B,OAAO,KAAK,KAAK,QAAQ;GACvB,IAAI,QAAQ;GAEZ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ED,QAAQ,SAAS,WAAW;IAC1B,gBAAgB,KAAK,MAAM;IAC3B,gBAAgB,OAAO,MAAM;GAC/B,CAAC;GAED,OAAO;EACT,CAGyB;CAC7B;CAEA,MAAM,cAAc,mBAAmB,SAAS,MAAM,CAAC;CAEvD,YAAY,SAAS,WAAW;EAC9B,gBAAgB,KAAK,MAAM;EAC3B,gBAAgB,OAAO,MAAM;CAC/B,CAAC;CAED,OAAO;EACL,MAAM;EACN,UAAU;EACV,UAAU;CACZ;AACF;AAEA,SAAS,QACP,MACA,UACA;CACA,MAAM,2BAAW,IAAI,IAAuC;CAE5D,OAAO,KAAK,QAAQ,KAAK,QAAQ;EAC/B,MAAM,SAAS,GAAGK,yDAAqB,KAAK,QAAQ;EACpD,MAAM,WAAW,IAAI,IAAI,MAAM;EAC/B,IAAI,CAAC,UACH,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC;OAErB,SAAS,KAAK,GAAG;EAEnB,OAAO;CACT,GAAG,QAAQ;AACb"}
1
+ {"version":3,"file":"createGroupedRowModel.cjs","names":["tableMemo","table_getColumn","makeObjectMap","flattenBy","constructRow","hasOwn","column_getAggregationFn","row_getGroupingValue"],"sources":["../../../src/features/column-grouping/createGroupedRowModel.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap, tableMemo } from '../../utils'\nimport { constructRow } from '../../core/rows/constructRow'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport { table_autoResetExpanded } from '../row-expanding/rowExpandingFeature.utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport {\n column_getAggregationFn,\n row_getGroupingValue,\n} from './columnGroupingFeature.utils'\nimport type { Column } from '../../types/Column'\nimport type { Row_ColumnGrouping } from './columnGroupingFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized grouped 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 *\n * Register aggregation functions with the `aggregationFns` slot on the\n * `features` option:\n * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.\n */\nexport function createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnGroupingFeature',\n table,\n fnName: 'table.getGroupedRowModel',\n memoDeps: () => [\n table.atoms.grouping?.get(),\n table.getPreGroupedRowModel(),\n ],\n fn: () => _createGroupedRowModel(table),\n onAfterUpdate: () => {\n table_autoResetExpanded(table)\n table_autoResetPageIndex(table)\n },\n })\n }\n}\n\nfunction _createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const rowModel = table.getPreGroupedRowModel()\n const grouping = table.atoms.grouping?.get()\n\n if (!rowModel.rows.length || !grouping?.length) {\n rowModel.rows.forEach((row) => {\n row.depth = 0\n row.parentId = undefined\n })\n return rowModel\n }\n\n // Filter the grouping list down to columns that exist\n const existingGrouping = grouping.filter((columnId) =>\n table_getColumn(table, columnId),\n )\n\n const groupedFlatRows: Array<Row<TFeatures, TData>> &\n Partial<Row_ColumnGrouping> = []\n const groupedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n\n // Recursively group the data\n const groupUpRecursively = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n parentId?: string,\n ) => {\n // Grouping depth has been been met\n // Stop grouping and simply rewrite thd depth and row relationships\n if (depth >= existingGrouping.length) {\n return rows.map((row) => {\n row.depth = depth\n\n // Every row is pushed into flatRows/rowsById exactly once, by its\n // parent frame: rows returned here are pushed by the caller (the\n // parent group's loop or the root loop), so only descendants below\n // the terminal depth are pushed here.\n if (row.subRows.length) {\n row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n }\n }\n\n return row\n })\n }\n\n const columnId = existingGrouping[depth] as string\n\n // Group the rows together for this level\n const rowGroupsMap = groupBy(rows, columnId)\n\n // Perform aggregations for each group\n const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(\n ([groupingValue, groupedRows], index) => {\n let id = `${columnId}:${groupingValue}`\n id = parentId ? `${parentId}>${id}` : id\n\n // First, Recurse to group sub rows before aggregation\n const subRows = groupUpRecursively(groupedRows, depth + 1, id)\n\n subRows.forEach((subRow) => {\n subRow.parentId = id\n })\n\n // Flatten the leaf rows of the rows in this group\n const leafRows = depth\n ? flattenBy(groupedRows, (row) => row.subRows)\n : groupedRows\n\n const row = constructRow(\n table,\n id,\n leafRows[0]!.original,\n index,\n depth,\n undefined,\n parentId,\n ) as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n\n Object.assign(row, {\n groupingColumnId: columnId,\n groupingValue,\n subRows,\n leafRows,\n getValue: (colId: string) => {\n // Don't aggregate columns that are in the grouping\n if (existingGrouping.includes(colId)) {\n if (hasOwn(row._valuesCache, colId)) {\n return row._valuesCache[colId]\n }\n\n if (groupedRows[0]) {\n row._valuesCache[colId] =\n groupedRows[0].getValue(colId) ?? undefined\n }\n\n return row._valuesCache[colId]\n }\n\n if (\n row._groupingValuesCache &&\n hasOwn(row._groupingValuesCache, colId)\n ) {\n return row._groupingValuesCache[colId]\n }\n\n // Aggregate the values\n const column = table.getColumn(colId)\n const aggregateFn = column_getAggregationFn(\n column as Column<TFeatures, TData, unknown>,\n )\n\n if (!row._groupingValuesCache) {\n row._groupingValuesCache = makeObjectMap()\n }\n\n if (aggregateFn) {\n row._groupingValuesCache[colId] = aggregateFn(\n colId,\n leafRows,\n groupedRows,\n )\n\n return row._groupingValuesCache[colId]\n }\n },\n })\n\n subRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return row\n },\n )\n\n return aggregatedGroupedRows\n }\n\n const groupedRows = groupUpRecursively(rowModel.rows, 0)\n\n groupedRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return {\n rows: groupedRows,\n flatRows: groupedFlatRows,\n rowsById: groupedRowsById,\n }\n}\n\nfunction groupBy<TFeatures extends TableFeatures, TData extends RowData = any>(\n rows: Array<Row<TFeatures, TData>>,\n columnId: string,\n) {\n const groupMap = new Map<any, Array<Row<TFeatures, TData>>>()\n\n return rows.reduce((map, row) => {\n const resKey = `${row_getGroupingValue(row, columnId)}`\n const previous = map.get(resKey)\n if (!previous) {\n map.set(resKey, [row])\n } else {\n previous.push(row)\n }\n return map\n }, groupMap)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAgB,wBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;qCACd,MAAM,MAAM,wFAAU,IAAI,GAC1B,MAAM,sBAAsB,CAC9B;;GACA,UAAU,uBAAuB,KAAK;GACtC,qBAAqB;IACnB,0DAAwB,KAAK;IAC7B,4DAAyB,KAAK;GAChC;EACF,CAAC;CACH;AACF;AAEA,SAAS,uBAGP,OAAqE;;CACrE,MAAM,WAAW,MAAM,sBAAsB;CAC7C,MAAM,qCAAW,MAAM,MAAM,0FAAU,IAAI;CAE3C,IAAI,CAAC,SAAS,KAAK,UAAU,sDAAC,SAAU,SAAQ;EAC9C,SAAS,KAAK,SAAS,QAAQ;GAC7B,IAAI,QAAQ;GACZ,IAAI,WAAW;EACjB,CAAC;EACD,OAAO;CACT;CAGA,MAAM,mBAAmB,SAAS,QAAQ,aACxCC,iDAAgB,OAAO,QAAQ,CACj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B;KAEA,IACE,IAAI,wBACJA,qBAAO,IAAI,sBAAsB,KAAK,GAEtC,OAAO,IAAI,qBAAqB;KAKlC,MAAM,cAAcC,4DADL,MAAM,UAAU,KAExB,CACP;KAEA,IAAI,CAAC,IAAI,sBACP,IAAI,uBAAuBJ,4BAAc;KAG3C,IAAI,aAAa;MACf,IAAI,qBAAqB,SAAS,YAChC,OACA,UACA,WACF;MAEA,OAAO,IAAI,qBAAqB;KAClC;IACF;GACF,CAAC;GAED,QAAQ,SAAS,WAAW;IAC1B,gBAAgB,KAAK,MAAM;IAC3B,gBAAgB,OAAO,MAAM;GAC/B,CAAC;GAED,OAAO;EACT,CAGyB;CAC7B;CAEA,MAAM,cAAc,mBAAmB,SAAS,MAAM,CAAC;CAEvD,YAAY,SAAS,WAAW;EAC9B,gBAAgB,KAAK,MAAM;EAC3B,gBAAgB,OAAO,MAAM;CAC/B,CAAC;CAED,OAAO;EACL,MAAM;EACN,UAAU;EACV,UAAU;CACZ;AACF;AAEA,SAAS,QACP,MACA,UACA;CACA,MAAM,2BAAW,IAAI,IAAuC;CAE5D,OAAO,KAAK,QAAQ,KAAK,QAAQ;EAC/B,MAAM,SAAS,GAAGK,yDAAqB,KAAK,QAAQ;EACpD,MAAM,WAAW,IAAI,IAAI,MAAM;EAC/B,IAAI,CAAC,UACH,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC;OAErB,SAAS,KAAK,GAAG;EAEnB,OAAO;CACT,GAAG,QAAQ;AACb"}
@@ -51,9 +51,14 @@ function _createGroupedRowModel(table) {
51
51
  const groupUpRecursively = (rows, depth = 0, parentId) => {
52
52
  if (depth >= existingGrouping.length) return rows.map((row) => {
53
53
  row.depth = depth;
54
- groupedFlatRows.push(row);
55
- groupedRowsById[row.id] = row;
56
- if (row.subRows.length) row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id);
54
+ if (row.subRows.length) {
55
+ row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id);
56
+ for (let i = 0; i < row.subRows.length; i++) {
57
+ const subRow = row.subRows[i];
58
+ groupedFlatRows.push(subRow);
59
+ groupedRowsById[subRow.id] = subRow;
60
+ }
61
+ }
57
62
  return row;
58
63
  });
59
64
  const columnId = existingGrouping[depth];
@@ -1 +1 @@
1
- {"version":3,"file":"createGroupedRowModel.js","names":[],"sources":["../../../src/features/column-grouping/createGroupedRowModel.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap, tableMemo } from '../../utils'\nimport { constructRow } from '../../core/rows/constructRow'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport { table_autoResetExpanded } from '../row-expanding/rowExpandingFeature.utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport {\n column_getAggregationFn,\n row_getGroupingValue,\n} from './columnGroupingFeature.utils'\nimport type { Column } from '../../types/Column'\nimport type { Row_ColumnGrouping } from './columnGroupingFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized grouped 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 *\n * Register aggregation functions with the `aggregationFns` slot on the\n * `features` option:\n * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.\n */\nexport function createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnGroupingFeature',\n table,\n fnName: 'table.getGroupedRowModel',\n memoDeps: () => [\n table.atoms.grouping?.get(),\n table.getPreGroupedRowModel(),\n ],\n fn: () => _createGroupedRowModel(table),\n onAfterUpdate: () => {\n table_autoResetExpanded(table)\n table_autoResetPageIndex(table)\n },\n })\n }\n}\n\nfunction _createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const rowModel = table.getPreGroupedRowModel()\n const grouping = table.atoms.grouping?.get()\n\n if (!rowModel.rows.length || !grouping?.length) {\n rowModel.rows.forEach((row) => {\n row.depth = 0\n row.parentId = undefined\n })\n return rowModel\n }\n\n // Filter the grouping list down to columns that exist\n const existingGrouping = grouping.filter((columnId) =>\n table_getColumn(table, columnId),\n )\n\n const groupedFlatRows: Array<Row<TFeatures, TData>> &\n Partial<Row_ColumnGrouping> = []\n const groupedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n\n // Recursively group the data\n const groupUpRecursively = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n parentId?: string,\n ) => {\n // Grouping depth has been been met\n // Stop grouping and simply rewrite thd depth and row relationships\n if (depth >= existingGrouping.length) {\n return rows.map((row) => {\n row.depth = depth\n\n groupedFlatRows.push(row)\n groupedRowsById[row.id] = row\n\n if (row.subRows.length) {\n row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)\n }\n\n return row\n })\n }\n\n const columnId = existingGrouping[depth] as string\n\n // Group the rows together for this level\n const rowGroupsMap = groupBy(rows, columnId)\n\n // Perform aggregations for each group\n const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(\n ([groupingValue, groupedRows], index) => {\n let id = `${columnId}:${groupingValue}`\n id = parentId ? `${parentId}>${id}` : id\n\n // First, Recurse to group sub rows before aggregation\n const subRows = groupUpRecursively(groupedRows, depth + 1, id)\n\n subRows.forEach((subRow) => {\n subRow.parentId = id\n })\n\n // Flatten the leaf rows of the rows in this group\n const leafRows = depth\n ? flattenBy(groupedRows, (row) => row.subRows)\n : groupedRows\n\n const row = constructRow(\n table,\n id,\n leafRows[0]!.original,\n index,\n depth,\n undefined,\n parentId,\n ) as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n\n Object.assign(row, {\n groupingColumnId: columnId,\n groupingValue,\n subRows,\n leafRows,\n getValue: (colId: string) => {\n // Don't aggregate columns that are in the grouping\n if (existingGrouping.includes(colId)) {\n if (hasOwn(row._valuesCache, colId)) {\n return row._valuesCache[colId]\n }\n\n if (groupedRows[0]) {\n row._valuesCache[colId] =\n groupedRows[0].getValue(colId) ?? undefined\n }\n\n return row._valuesCache[colId]\n }\n\n if (\n row._groupingValuesCache &&\n hasOwn(row._groupingValuesCache, colId)\n ) {\n return row._groupingValuesCache[colId]\n }\n\n // Aggregate the values\n const column = table.getColumn(colId)\n const aggregateFn = column_getAggregationFn(\n column as Column<TFeatures, TData, unknown>,\n )\n\n if (!row._groupingValuesCache) {\n row._groupingValuesCache = makeObjectMap()\n }\n\n if (aggregateFn) {\n row._groupingValuesCache[colId] = aggregateFn(\n colId,\n leafRows,\n groupedRows,\n )\n\n return row._groupingValuesCache[colId]\n }\n },\n })\n\n subRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return row\n },\n )\n\n return aggregatedGroupedRows\n }\n\n const groupedRows = groupUpRecursively(rowModel.rows, 0)\n\n groupedRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return {\n rows: groupedRows,\n flatRows: groupedFlatRows,\n rowsById: groupedRowsById,\n }\n}\n\nfunction groupBy<TFeatures extends TableFeatures, TData extends RowData = any>(\n rows: Array<Row<TFeatures, TData>>,\n columnId: string,\n) {\n const groupMap = new Map<any, Array<Row<TFeatures, TData>>>()\n\n return rows.reduce((map, row) => {\n const resKey = `${row_getGroupingValue(row, columnId)}`\n const previous = map.get(resKey)\n if (!previous) {\n map.set(resKey, [row])\n } else {\n previous.push(row)\n }\n return map\n }, groupMap)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA0BA,SAAgB,wBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf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,QAAQ,CAAC,GAAG,CAAC;OAErB,SAAS,KAAK,GAAG;EAEnB,OAAO;CACT,GAAG,QAAQ;AACb"}
1
+ {"version":3,"file":"createGroupedRowModel.js","names":[],"sources":["../../../src/features/column-grouping/createGroupedRowModel.ts"],"sourcesContent":["import { flattenBy, hasOwn, makeObjectMap, tableMemo } from '../../utils'\nimport { constructRow } from '../../core/rows/constructRow'\nimport { table_getColumn } from '../../core/columns/coreColumnsFeature.utils'\nimport { table_autoResetExpanded } from '../row-expanding/rowExpandingFeature.utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport {\n column_getAggregationFn,\n row_getGroupingValue,\n} from './columnGroupingFeature.utils'\nimport type { Column } from '../../types/Column'\nimport type { Row_ColumnGrouping } from './columnGroupingFeature.types'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized grouped 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 *\n * Register aggregation functions with the `aggregationFns` slot on the\n * `features` option:\n * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.\n */\nexport function createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'columnGroupingFeature',\n table,\n fnName: 'table.getGroupedRowModel',\n memoDeps: () => [\n table.atoms.grouping?.get(),\n table.getPreGroupedRowModel(),\n ],\n fn: () => _createGroupedRowModel(table),\n onAfterUpdate: () => {\n table_autoResetExpanded(table)\n table_autoResetPageIndex(table)\n },\n })\n }\n}\n\nfunction _createGroupedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const rowModel = table.getPreGroupedRowModel()\n const grouping = table.atoms.grouping?.get()\n\n if (!rowModel.rows.length || !grouping?.length) {\n rowModel.rows.forEach((row) => {\n row.depth = 0\n row.parentId = undefined\n })\n return rowModel\n }\n\n // Filter the grouping list down to columns that exist\n const existingGrouping = grouping.filter((columnId) =>\n table_getColumn(table, columnId),\n )\n\n const groupedFlatRows: Array<Row<TFeatures, TData>> &\n Partial<Row_ColumnGrouping> = []\n const groupedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n\n // Recursively group the data\n const groupUpRecursively = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n parentId?: string,\n ) => {\n // Grouping depth has been been met\n // Stop grouping and simply rewrite thd depth and row relationships\n if (depth >= existingGrouping.length) {\n return rows.map((row) => {\n row.depth = depth\n\n // Every row is pushed into flatRows/rowsById exactly once, by its\n // parent frame: rows returned here are pushed by the caller (the\n // parent group's loop or the root loop), so only descendants below\n // the terminal depth are pushed here.\n if (row.subRows.length) {\n row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n }\n }\n\n return row\n })\n }\n\n const columnId = existingGrouping[depth] as string\n\n // Group the rows together for this level\n const rowGroupsMap = groupBy(rows, columnId)\n\n // Perform aggregations for each group\n const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map(\n ([groupingValue, groupedRows], index) => {\n let id = `${columnId}:${groupingValue}`\n id = parentId ? `${parentId}>${id}` : id\n\n // First, Recurse to group sub rows before aggregation\n const subRows = groupUpRecursively(groupedRows, depth + 1, id)\n\n subRows.forEach((subRow) => {\n subRow.parentId = id\n })\n\n // Flatten the leaf rows of the rows in this group\n const leafRows = depth\n ? flattenBy(groupedRows, (row) => row.subRows)\n : groupedRows\n\n const row = constructRow(\n table,\n id,\n leafRows[0]!.original,\n index,\n depth,\n undefined,\n parentId,\n ) as Row<TFeatures, TData> & Partial<Row_ColumnGrouping>\n\n Object.assign(row, {\n groupingColumnId: columnId,\n groupingValue,\n subRows,\n leafRows,\n getValue: (colId: string) => {\n // Don't aggregate columns that are in the grouping\n if (existingGrouping.includes(colId)) {\n if (hasOwn(row._valuesCache, colId)) {\n return row._valuesCache[colId]\n }\n\n if (groupedRows[0]) {\n row._valuesCache[colId] =\n groupedRows[0].getValue(colId) ?? undefined\n }\n\n return row._valuesCache[colId]\n }\n\n if (\n row._groupingValuesCache &&\n hasOwn(row._groupingValuesCache, colId)\n ) {\n return row._groupingValuesCache[colId]\n }\n\n // Aggregate the values\n const column = table.getColumn(colId)\n const aggregateFn = column_getAggregationFn(\n column as Column<TFeatures, TData, unknown>,\n )\n\n if (!row._groupingValuesCache) {\n row._groupingValuesCache = makeObjectMap()\n }\n\n if (aggregateFn) {\n row._groupingValuesCache[colId] = aggregateFn(\n colId,\n leafRows,\n groupedRows,\n )\n\n return row._groupingValuesCache[colId]\n }\n },\n })\n\n subRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return row\n },\n )\n\n return aggregatedGroupedRows\n }\n\n const groupedRows = groupUpRecursively(rowModel.rows, 0)\n\n groupedRows.forEach((subRow) => {\n groupedFlatRows.push(subRow)\n groupedRowsById[subRow.id] = subRow\n })\n\n return {\n rows: groupedRows,\n flatRows: groupedFlatRows,\n rowsById: groupedRowsById,\n }\n}\n\nfunction groupBy<TFeatures extends TableFeatures, TData extends RowData = any>(\n rows: Array<Row<TFeatures, TData>>,\n columnId: string,\n) {\n const groupMap = new Map<any, Array<Row<TFeatures, TData>>>()\n\n return rows.reduce((map, row) => {\n const resKey = `${row_getGroupingValue(row, columnId)}`\n const previous = map.get(resKey)\n if (!previous) {\n map.set(resKey, [row])\n } else {\n previous.push(row)\n }\n return map\n }, groupMap)\n}\n"],"mappings":";;;;;;;;;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AAS,QACP,MACA,UACA;CACA,MAAM,2BAAW,IAAI,IAAuC;CAE5D,OAAO,KAAK,QAAQ,KAAK,QAAQ;EAC/B,MAAM,SAAS,GAAG,qBAAqB,KAAK,QAAQ;EACpD,MAAM,WAAW,IAAI,IAAI,MAAM;EAC/B,IAAI,CAAC,UACH,IAAI,IAAI,QAAQ,CAAC,GAAG,CAAC;OAErB,SAAS,KAAK,GAAG;EAEnB,OAAO;CACT,GAAG,QAAQ;AACb"}
@@ -139,7 +139,7 @@ function table_getSelectedRowModel(table) {
139
139
  * ```
140
140
  */
141
141
  function table_getFilteredSelectedRowModel(table) {
142
- const rowModel = table.getCoreRowModel();
142
+ const rowModel = table.getFilteredRowModel();
143
143
  if (!require_utils.callMemoOrStaticFn(table, "getIsSomeRowsSelected", table_getIsSomeRowsSelected)) return {
144
144
  rows: [],
145
145
  flatRows: [],
@@ -159,7 +159,7 @@ function table_getFilteredSelectedRowModel(table) {
159
159
  * ```
160
160
  */
161
161
  function table_getGroupedSelectedRowModel(table) {
162
- const rowModel = table.getCoreRowModel();
162
+ const rowModel = table.getSortedRowModel();
163
163
  if (!require_utils.callMemoOrStaticFn(table, "getIsSomeRowsSelected", table_getIsSomeRowsSelected)) return {
164
164
  rows: [],
165
165
  flatRows: [],
@@ -1 +1 @@
1
- {"version":3,"file":"rowSelectionFeature.utils.cjs","names":["makeObjectMap","cloneState","callMemoOrStaticFn","hasOwn"],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAOA,4BAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;;CACA,iDAAM,SAAQ,iHAAuB,OAAO;AAC9C;;;;;;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AAQ;GACzB,MAAM,yBAAyB,iBAAiB,MAAM;GACtD,IAAI,2BAA2B,OAC7B,eAAe;QACV,IAAI,2BAA2B,QAAQ;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
1
+ {"version":3,"file":"rowSelectionFeature.utils.cjs","names":["makeObjectMap","cloneState","callMemoOrStaticFn","hasOwn"],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getFilteredRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n // The sorted model falls back grouped -> filtered -> core when those\n // features are not registered, so selected group rows are always visible.\n const rowModel = table.getSortedRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAOA,4BAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;;CACA,iDAAM,SAAQ,iHAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACIA,4BAAc,IACd,OAAO,OACLA,4BAAoB,GACpBC,yBAAW,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAClD,CACN;AACF;;;;;;;;;;;;AAeA,SAAgB,4BAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,QACE,OAAO,UAAU,cACb,QACA,CAACC,iCACC,OACA,wBACA,0BACF;EAEN,iDAAI,KAAM,gBAAe,CAAC,OAExB,OAAOF,4BAAoB;EAG7B,MAAM,eAAe,OAAO,OAAOA,4BAAoB,GAAG,GAAG;EAC7D,MAAM,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;EAIzD,IAAI,OACF,mBAAmB,SAAS,QAAQ;GAClC,IAAI,iBAAiB,GAAG,GACtB,aAAa,IAAI,MAA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pB;GACF,OAAO,IAAI,YACT,OAAO,KAAK,GAAG;EAEnB;EACA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,YAAY,SAAS,IAAI;EAC/B,UAAU;EACV,UAAU;CACZ;AACF;;;;;;;;;AAUA,SAAgB,cAGd,KAA4B,cAA0C;CACtE,OAAO,CAAC,EAAEG,qBAAO,cAAc,IAAI,EAAE,KAAK,aAAa,IAAI;AAC7D;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAAsD;;CACtD,IAAI,CAAC,IAAI,QAAQ,QAAQ,OAAO;CAEhC,MAAM,0CAAe,IAAI,MAAM,MAAM,8FAAc,IAAI,MAAK,CAAC;CAE7D,IAAI,eAAe;CACnB,IAAI,sBAAsB;CAE1B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KAAK;EAC3C,MAAM,SAAS,IAAI,QAAQ;EAG3B,IAAI,gBAAgB,CAAC,qBACnB;EAGF,IAAI,iBAAiB,MAAM,GACzB,IAAI,cAAc,QAAQ,YAAY,GACpC,eAAe;OAEf,sBAAsB;EAK1B,IAAI,OAAO,QAAQ,QAAQ;GACzB,MAAM,yBAAyB,iBAAiB,MAAM;GACtD,IAAI,2BAA2B,OAC7B,eAAe;QACV,IAAI,2BAA2B,QAAQ;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
@@ -139,7 +139,7 @@ function table_getSelectedRowModel(table) {
139
139
  * ```
140
140
  */
141
141
  function table_getFilteredSelectedRowModel(table) {
142
- const rowModel = table.getCoreRowModel();
142
+ const rowModel = table.getFilteredRowModel();
143
143
  if (!callMemoOrStaticFn(table, "getIsSomeRowsSelected", table_getIsSomeRowsSelected)) return {
144
144
  rows: [],
145
145
  flatRows: [],
@@ -159,7 +159,7 @@ function table_getFilteredSelectedRowModel(table) {
159
159
  * ```
160
160
  */
161
161
  function table_getGroupedSelectedRowModel(table) {
162
- const rowModel = table.getCoreRowModel();
162
+ const rowModel = table.getSortedRowModel();
163
163
  if (!callMemoOrStaticFn(table, "getIsSomeRowsSelected", table_getIsSomeRowsSelected)) return {
164
164
  rows: [],
165
165
  flatRows: [],
@@ -1 +1 @@
1
- {"version":3,"file":"rowSelectionFeature.utils.js","names":[],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAO,cAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;;CACA,iDAAM,SAAQ,iHAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACI,cAAc,IACd,OAAO,OACL,cAAoB,GACpB,WAAW,MAAM,aAAa,gBAAgB,CAAC,CAAC,CAClD,CACN;AACF;;;;;;;;;;;;AAeA,SAAgB,4BAId,OACA,OACA,MACA;CACA,sBAAsB,QAAQ,QAAQ;EACpC,QACE,OAAO,UAAU,cACb,QACA,CAAC,mBACC,OACA,wBACA,0BACF;EAEN,iDAAI,KAAM,gBAAe,CAAC,OAExB,OAAO,cAAoB;EAG7B,MAAM,eAAe,OAAO,OAAO,cAAoB,GAAG,GAAG;EAC7D,MAAM,qBAAqB,MAAM,sBAAsB,CAAC,CAAC;EAIzD,IAAI,OACF,mBAAmB,SAAS,QAAQ;GAClC,IAAI,iBAAiB,GAAG,GACtB,aAAa,IAAI,MAAM;EAE3B,CAAC;OAED,mBAAmB,SAAS,QAAQ;GAClC,OAAO,aAAa,IAAI;EAC1B,CAAC;EAGH,OAAO;CACT,CAAC;AACH;;;;;;;;;;;;AAaA,SAAgB,gCAId,OACA,OACA,MACA;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4B,cAA0C;CACtE,OAAO,CAAC,EAAE,OAAO,cAAc,IAAI,EAAE,KAAK,aAAa,IAAI;AAC7D;;;;;;;;;;;AAYA,SAAgB,iBAGd,KAAsD;;CACtD,IAAI,CAAC,IAAI,QAAQ,QAAQ,OAAO;CAEhC,MAAM,0CAAe,IAAI,MAAM,MAAM,8FAAc,IAAI,MAAK,CAAC;CAE7D,IAAI,eAAe;CACnB,IAAI,sBAAsB;CAE1B,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,QAAQ,KAAK;EAC3C,MAAM,SAAS,IAAI,QAAQ;EAG3B,IAAI,gBAAgB,CAAC,qBACnB;EAGF,IAAI,iBAAiB,MAAM,GACzB,IAAI,cAAc,QAAQ,YAAY,GACpC,eAAe;OAEf,sBAAsB;EAK1B,IAAI,OAAO,QAAQ,QAAQ;GACzB,MAAM,yBAAyB,iBAAiB,MAAM;GACtD,IAAI,2BAA2B,OAC7B,eAAe;QACV,IAAI,2BAA2B,QAAQ;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
1
+ {"version":3,"file":"rowSelectionFeature.utils.js","names":[],"sources":["../../../src/features/row-selection/rowSelectionFeature.utils.ts"],"sourcesContent":["import {\n callMemoOrStaticFn,\n cloneState,\n hasOwn,\n makeObjectMap,\n} from '../../utils'\nimport type { RowData, Updater } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { RowSelectionState } from './rowSelectionFeature.types'\n\n// State APIs\n\n/**\n * Creates the default row selection state.\n *\n * The feature default is an empty map, meaning no rows are selected. Reset APIs\n * use this value when `defaultState` is `true`.\n *\n * @example\n * ```ts\n * const selection = getDefaultRowSelectionState()\n * ```\n */\nexport function getDefaultRowSelectionState(): RowSelectionState {\n return makeObjectMap()\n}\n\n/**\n * Routes a row selection updater through the table's selection change handler.\n *\n * The updater may be a next selection map or a function of the previous map,\n * matching the instance `table.setRowSelection` behavior.\n *\n * @example\n * ```ts\n * table_setRowSelection(table, (old) => ({ ...old, [rowId]: true }))\n * ```\n */\nexport function table_setRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n updater: Updater<RowSelectionState>,\n) {\n table.options.onRowSelectionChange?.(updater)\n}\n\n/**\n * Resets `rowSelection` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.rowSelection` when it\n * exists. Passing `true` ignores initial state and resets to `{}`.\n *\n * @example\n * ```ts\n * table_resetRowSelection(table)\n * table_resetRowSelection(table, true)\n * ```\n */\nexport function table_resetRowSelection<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setRowSelection(\n table,\n defaultState\n ? makeObjectMap()\n : Object.assign(\n makeObjectMap<true>(),\n cloneState(table.initialState.rowSelection ?? {}),\n ),\n )\n}\n\n// Table APIs\n\n/**\n * Selects or deselects every selectable row before grouping.\n *\n * Omitting `value` toggles based on `table_getIsAllRowsSelected(table)`.\n * Deselecting removes matching ids from the existing selection map.\n *\n * @example\n * ```ts\n * table_toggleAllRowsSelected(table)\n * ```\n */\nexport function table_toggleAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n value =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllRowsSelected',\n table_getIsAllRowsSelected,\n )\n\n if (opts?.deselectAll && !value) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows\n\n // We don't use `mutateRowIsSelected` here for performance reasons.\n // All of the rows are flat already, so it wouldn't be worth it\n if (value) {\n preGroupedFlatRows.forEach((row) => {\n if (row_getCanSelect(row)) {\n rowSelection[row.id] = true\n }\n })\n } else {\n preGroupedFlatRows.forEach((row) => {\n delete rowSelection[row.id]\n })\n }\n\n return rowSelection\n })\n}\n\n/**\n * Selects or deselects every selectable row on the current page.\n *\n * Omitting `value` toggles based on `table_getIsAllPageRowsSelected(table)`.\n * Child rows are included when sub-row selection allows it.\n *\n * @example\n * ```ts\n * table_toggleAllPageRowsSelected(table)\n * ```\n */\nexport function table_toggleAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n value?: boolean,\n opts?: { deselectAll?: boolean },\n) {\n table_setRowSelection(table, (old) => {\n const resolvedValue =\n typeof value !== 'undefined'\n ? value\n : !callMemoOrStaticFn(\n table,\n 'getIsAllPageRowsSelected',\n table_getIsAllPageRowsSelected,\n )\n\n if (opts?.deselectAll && !resolvedValue) {\n // deselectAll opt: clear the whole selection map instead of deleting ids one-by-one\n return makeObjectMap<true>()\n }\n\n const rowSelection: RowSelectionState = Object.assign(\n makeObjectMap<true>(),\n old,\n )\n\n table.getRowModel().rows.forEach((row) => {\n mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table)\n })\n\n return rowSelection\n })\n}\n\n/**\n * Reads the row model before row selection is projected into selected rows.\n *\n * Selection does not alter the base row pipeline, so this returns the core row\n * model.\n *\n * @example\n * ```ts\n * const rowsBeforeSelection = table_getPreSelectedRowModel(table)\n * ```\n */\nexport function table_getPreSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n return table.getCoreRowModel()\n}\n\n/**\n * Builds a row model containing selected rows from the core row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getSelectedRowModel(table)\n * ```\n */\nexport function table_getSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getCoreRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the filtered row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getFilteredSelectedRowModel(table)\n * ```\n */\nexport function table_getFilteredSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const rowModel = table.getFilteredRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Builds a row model containing selected rows from the grouped row model.\n *\n * If no row ids are selected, an empty row model is returned without walking\n * the rows.\n *\n * @example\n * ```ts\n * const selectedRows = table_getGroupedSelectedRowModel(table)\n * ```\n */\nexport function table_getGroupedSelectedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n // The sorted model falls back grouped -> filtered -> core when those\n // features are not registered, so selected group rows are always visible.\n const rowModel = table.getSortedRowModel()\n\n if (\n !callMemoOrStaticFn(\n table,\n 'getIsSomeRowsSelected',\n table_getIsSomeRowsSelected,\n )\n ) {\n return {\n rows: [],\n flatRows: [],\n rowsById: makeObjectMap(),\n }\n }\n\n return selectRowsFn(rowModel, table)\n}\n\n/**\n * Returns the ids of all selected rows.\n *\n * @example\n * ```ts\n * const selectedRowIds = table_getSelectedRowIds(table)\n * ```\n */\nexport function table_getSelectedRowIds<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>): Array<string> {\n return Object.keys(table.atoms.rowSelection?.get() ?? {})\n}\n\n/**\n * Checks whether every selectable filtered row is selected.\n *\n * The result is false when there are no filtered rows or when selection state is\n * empty.\n *\n * @example\n * ```ts\n * const allSelected = table_getIsAllRowsSelected(table)\n * ```\n */\nexport function table_getIsAllRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const preGroupedFlatRows = table.getFilteredRowModel().flatRows\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllRowsSelected = Boolean(\n preGroupedFlatRows.length && Object.keys(rowSelection).length,\n )\n\n if (isAllRowsSelected) {\n if (\n preGroupedFlatRows.some(\n (row) => row_getCanSelect(row) && !isRowSelected(row, rowSelection),\n )\n ) {\n isAllRowsSelected = false\n }\n }\n\n return isAllRowsSelected\n}\n\n/**\n * Checks whether every selectable row on the current page is selected.\n *\n * Non-selectable rows are ignored for this calculation.\n *\n * @example\n * ```ts\n * const allPageRowsSelected = table_getIsAllPageRowsSelected(table)\n * ```\n */\nexport function table_getIsAllPageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n const paginationFlatRows = table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n\n let isAllPageRowsSelected = !!paginationFlatRows.length\n\n if (\n isAllPageRowsSelected &&\n paginationFlatRows.some((row) => !isRowSelected(row, rowSelection))\n ) {\n isAllPageRowsSelected = false\n }\n\n return isAllPageRowsSelected\n}\n\n/**\n * Checks whether selection is partially applied across filtered rows.\n *\n * The result is true when at least one row id is selected\n *\n * @example\n * ```ts\n * const someRowsSelected = table_getIsSomeRowsSelected(table)\n * ```\n */\nexport function table_getIsSomeRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (\n callMemoOrStaticFn(table, 'getSelectedRowIds', table_getSelectedRowIds)\n .length > 0\n )\n}\n\n/**\n * Checks whether the current page has a partial selection.\n *\n * @example\n * ```ts\n * const somePageRowsSelected = table_getIsSomePageRowsSelected(table)\n * ```\n */\nexport function table_getIsSomePageRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return table\n .getPaginatedRowModel()\n .flatRows.filter((row) => row_getCanSelect(row))\n .some(\n (row) =>\n row_getIsSelected(row) ||\n callMemoOrStaticFn(row, 'getIsSomeSelected', row_getIsSomeSelected),\n )\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects all rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects current page rows.\n *\n * The handler reads `event.target.checked`, so it is intended for controls whose\n * checked state means \"all page rows selected\".\n *\n * @example\n * ```ts\n * const onChange = table_getToggleAllPageRowsSelectedHandler(table)\n * ```\n */\nexport function table_getToggleAllPageRowsSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>) {\n return (e: unknown) => {\n table_toggleAllPageRowsSelected(\n table,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\n// Row APIs\n\n/**\n * Selects or deselects this row.\n *\n * Omitting `value` toggles the row. Child rows are selected recursively unless\n * `opts.selectChildren` is `false` or sub-row selection is disabled.\n *\n * @example\n * ```ts\n * row_toggleSelected(row)\n * row_toggleSelected(row, true)\n * row_toggleSelected(row, false)\n * row_toggleSelected(row, true, { selectChildren: false })\n * row_toggleSelected(row, false, { selectChildren: false })\n * ```\n */\nexport function row_toggleSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n row: Row<TFeatures, TData>,\n value?: boolean,\n opts?: {\n selectChildren?: boolean\n },\n) {\n const isSelected = row_getIsSelected(row)\n\n table_setRowSelection(row.table, (old) => {\n value = typeof value !== 'undefined' ? value : !isSelected\n\n const rowSelection = Object.assign(makeObjectMap<true>(), old)\n\n mutateRowIsSelected(\n rowSelection,\n row.id,\n value,\n opts?.selectChildren ?? true,\n row.table,\n )\n\n return rowSelection\n })\n}\n\n/**\n * Checks whether this row id is selected in `state.rowSelection`.\n *\n * Missing row ids are treated as not selected.\n *\n * @example\n * ```ts\n * const selected = row_getIsSelected(row)\n * ```\n */\nexport function row_getIsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n return isRowSelected(row, rowSelection)\n}\n\n/**\n * Checks whether some, but not all, selectable descendants are selected.\n *\n * This supports indeterminate selection UI for parent rows.\n *\n * @example\n * ```ts\n * const partial = row_getIsSomeSelected(row)\n * ```\n */\nexport function row_getIsSomeSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'some'\n}\n\n/**\n * Checks whether all selectable descendants are selected.\n *\n * Rows without selectable descendants return false.\n *\n * @example\n * ```ts\n * const allChildrenSelected = row_getIsAllSubRowsSelected(row)\n * ```\n */\nexport function row_getIsAllSubRowsSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n return isSubRowSelected(row) === 'all'\n}\n\n/**\n * Checks whether this row can be selected.\n *\n * `options.enableRowSelection` may be a boolean or a row predicate; it defaults\n * to `true`.\n *\n * @example\n * ```ts\n * const canSelect = row_getCanSelect(row)\n * ```\n */\nexport function row_getCanSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableRowSelection === 'function') {\n return options.enableRowSelection(row)\n }\n\n return options.enableRowSelection ?? true\n}\n\n/**\n * Checks whether selecting this row should also select its subRows.\n *\n * `options.enableSubRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canSelectChildren = row_getCanSelectSubRows(row)\n * ```\n */\nexport function row_getCanSelectSubRows<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableSubRowSelection === 'function') {\n return options.enableSubRowSelection(row)\n }\n\n return options.enableSubRowSelection ?? true\n}\n\n/**\n * Checks whether this row can be selected alongside other rows.\n *\n * `options.enableMultiRowSelection` may be a boolean or a row predicate; it\n * defaults to `true`.\n *\n * @example\n * ```ts\n * const canMultiSelect = row_getCanMultiSelect(row)\n * ```\n */\nexport function row_getCanMultiSelect<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const options = row.table.options\n if (typeof options.enableMultiRowSelection === 'function') {\n return options.enableMultiRowSelection(row)\n }\n\n return options.enableMultiRowSelection ?? true\n}\n\n/**\n * Creates a checkbox-style handler that selects or deselects this row.\n *\n * The handler is a no-op when the row cannot be selected and reads\n * `event.target.checked`.\n *\n * @example\n * ```ts\n * const onChange = row_getToggleSelectedHandler(row)\n * ```\n */\nexport function row_getToggleSelectedHandler<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>) {\n const canSelect = row_getCanSelect(row)\n\n return (e: unknown) => {\n if (!canSelect) return\n row_toggleSelected(\n row,\n ((e as MouseEvent).target as HTMLInputElement).checked,\n )\n }\n}\n\nconst mutateRowIsSelected = <\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowSelection: RowSelectionState,\n rowId: string,\n value: boolean,\n includeChildren: boolean,\n table: Table_Internal<TFeatures, TData>,\n): void => {\n const row = table.getRow(rowId, true)\n\n if (value) {\n if (!row_getCanMultiSelect(row)) {\n Object.keys(rowSelection).forEach((key) => delete rowSelection[key])\n }\n if (row_getCanSelect(row)) {\n rowSelection[rowId] = true\n }\n } else {\n delete rowSelection[rowId]\n }\n\n if (includeChildren && row.subRows.length && row_getCanSelectSubRows(row)) {\n row.subRows.forEach((r) =>\n mutateRowIsSelected(rowSelection, r.id, value, includeChildren, table),\n )\n }\n}\n\n/**\n * Builds a row model containing rows selected by the current row selection state.\n *\n * The result is derived from the supplied row model, so selected ids absent from\n * that model are not materialized as rows.\n *\n * @example\n * ```ts\n * const selectedRows = selectRowsFn(rowModel)\n * ```\n */\nexport function selectRowsFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n rowModel: RowModel<TFeatures, TData>,\n table: Table_Internal<TFeatures, TData>,\n): RowModel<TFeatures, TData> {\n const newSelectedFlatRows: Array<Row<TFeatures, TData>> = []\n const newSelectedRowsById = makeObjectMap<Row<TFeatures, TData>>()\n const rowSelection = table.atoms.rowSelection?.get() ?? {}\n // Filters top level and nested rows.\n const recurseRows = (\n rows: Array<Row<TFeatures, TData>>,\n depth = 0,\n ): Array<Row<TFeatures, TData>> => {\n const result: Array<Row<TFeatures, TData>> = []\n for (let i = 0; i < rows.length; i++) {\n const row = rows[i]!\n const isSelected = isRowSelected(row, rowSelection)\n\n if (isSelected) {\n newSelectedFlatRows.push(row)\n newSelectedRowsById[row.id] = row\n }\n\n if (row.subRows.length) {\n // Always recurse — selected descendants of unselected parents must\n // still be collected into flatRows/rowsById.\n const newSubRows = recurseRows(row.subRows, depth + 1)\n\n if (isSelected) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = newSubRows\n result.push(cloned)\n }\n } else if (isSelected) {\n result.push(row)\n }\n }\n return result\n }\n\n return {\n rows: recurseRows(rowModel.rows),\n flatRows: newSelectedFlatRows,\n rowsById: newSelectedRowsById,\n }\n}\n\n/**\n * Returns whether a row id is selected in the current row selection state.\n *\n * @example\n * ```ts\n * const selected = isRowSelected(row)\n * ```\n */\nexport function isRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>, rowSelection: RowSelectionState): boolean {\n return !!(hasOwn(rowSelection, row.id) && rowSelection[row.id])\n}\n\n/**\n * Returns whether all, some, or none of a row's selectable descendants are selected.\n *\n * The result is used to drive indeterminate row selection UI.\n *\n * @example\n * ```ts\n * const selectedState = isSubRowSelected(row)\n * ```\n */\nexport function isSubRowSelected<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(row: Row<TFeatures, TData>): boolean | 'some' | 'all' {\n if (!row.subRows.length) return false\n\n const rowSelection = row.table.atoms.rowSelection?.get() ?? {}\n\n let someSelected = false\n let allChildrenSelected = true\n\n for (let i = 0; i < row.subRows.length; i++) {\n const subRow = row.subRows[i]!\n\n // Bail out early if we know both of these\n if (someSelected && !allChildrenSelected) {\n break\n }\n\n if (row_getCanSelect(subRow)) {\n if (isRowSelected(subRow, rowSelection)) {\n someSelected = true\n } else {\n allChildrenSelected = false\n }\n }\n\n // Check row selection of nested subrows\n if (subRow.subRows.length) {\n const subRowChildrenSelected = isSubRowSelected(subRow)\n if (subRowChildrenSelected === 'all') {\n someSelected = true\n } else if (subRowChildrenSelected === 'some') {\n someSelected = true\n allChildrenSelected = false\n } else {\n allChildrenSelected = false\n }\n }\n }\n\n return allChildrenSelected ? 'all' : someSelected ? 'some' : false\n}\n"],"mappings":";;;;;;;;;;;;;;AA0BA,SAAgB,8BAAiD;CAC/D,OAAO,cAAc;AACvB;;;;;;;;;;;;AAaA,SAAgB,sBAId,OACA,SACA;;CACA,iDAAM,SAAQ,iHAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eACI,c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;IAC5C,eAAe;IACf,sBAAsB;GACxB,OACE,sBAAsB;EAE1B;CACF;CAEA,OAAO,sBAAsB,QAAQ,eAAe,SAAS;AAC/D"}
@@ -33,7 +33,10 @@ function _createSortedRowModel(table) {
33
33
  const sorting = (_table$atoms$sorting2 = table.atoms.sorting) === null || _table$atoms$sorting2 === void 0 ? void 0 : _table$atoms$sorting2.get();
34
34
  if (!preSortedRowModel.rows.length || !(sorting === null || sorting === void 0 ? void 0 : sorting.length)) return preSortedRowModel;
35
35
  const sortedFlatRows = [];
36
- const availableSorting = sorting.filter((sort) => require_rowSortingFeature_utils.column_getCanSort(table.getColumn(sort.id)));
36
+ const availableSorting = sorting.filter((sort) => {
37
+ const column = table.getColumn(sort.id);
38
+ return column ? require_rowSortingFeature_utils.column_getCanSort(column) : false;
39
+ });
37
40
  const resolvedSorting = [];
38
41
  for (let i = 0; i < availableSorting.length; i++) {
39
42
  const sortEntry = availableSorting[i];
@@ -1 +1 @@
1
- {"version":3,"file":"createSortedRowModel.cjs","names":["tableMemo","table_autoResetPageIndex","column_getCanSort","column_getSortFn"],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted 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 *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) =>\n column_getCanSort(\n table.getColumn(sort.id) as Column_Internal<TFeatures, TData>,\n ),\n )\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined && bUndefined) {\n continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (rows: Array<Row<TFeatures, TData>>) => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row.subRows.length) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = sortData(row.subRows)\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return sortedData\n }\n\n return {\n rows: sortData(preSortedRowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;oCACd,MAAM,MAAM,qFAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqBC,4DAAyB,KAAK;EACrD,C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IACjB,IAAI,QACF,WAAW;IAGb,IAAI,UAAU,eACZ,WAAW;IAGb,OAAO;GACT;EACF;EAEA,OAAO,KAAK,QAAQ,KAAK;CAC3B;CAEA,MAAM,YAAY,SAAuC;EACvD,MAAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAI3B,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,IAAI,QAAQ,QAAQ;IAEtB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;IACvD,OAAO,OAAO,QAAQ,GAAG;IACzB,OAAO,UAAU,SAAS,IAAI,OAAO;IACrC,WAAW,KAAK;IAChB,eAAe,KAAK,MAAM;GAC5B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI;EACrC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
1
+ {"version":3,"file":"createSortedRowModel.cjs","names":["tableMemo","table_autoResetPageIndex","column_getCanSort","column_getSortFn"],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted 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 *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) => {\n const column = table.getColumn(sort.id)\n return column ? column_getCanSort(column) : false\n })\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined && bUndefined) {\n continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (rows: Array<Row<TFeatures, TData>>) => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row.subRows.length) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = sortData(row.subRows)\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return sortedData\n }\n\n return {\n rows: sortData(preSortedRowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;oCACd,MAAM,MAAM,qFAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqBC,4DAAyB,KAAK;EACrD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AO,MAAM,MAAM,UAAU,EAAE;GAIrD,IAAI,YAAY,GAAG;IACjB,IAAI,QACF,WAAW;IAGb,IAAI,UAAU,eACZ,WAAW;IAGb,OAAO;GACT;EACF;EAEA,OAAO,KAAK,QAAQ,KAAK;CAC3B;CAEA,MAAM,YAAY,SAAuC;EACvD,MAAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAI3B,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,IAAI,QAAQ,QAAQ;IAEtB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;IACvD,OAAO,OAAO,QAAQ,GAAG;IACzB,OAAO,UAAU,SAAS,IAAI,OAAO;IACrC,WAAW,KAAK;IAChB,eAAe,KAAK,MAAM;GAC5B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI;EACrC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
@@ -33,7 +33,10 @@ function _createSortedRowModel(table) {
33
33
  const sorting = (_table$atoms$sorting2 = table.atoms.sorting) === null || _table$atoms$sorting2 === void 0 ? void 0 : _table$atoms$sorting2.get();
34
34
  if (!preSortedRowModel.rows.length || !(sorting === null || sorting === void 0 ? void 0 : sorting.length)) return preSortedRowModel;
35
35
  const sortedFlatRows = [];
36
- const availableSorting = sorting.filter((sort) => column_getCanSort(table.getColumn(sort.id)));
36
+ const availableSorting = sorting.filter((sort) => {
37
+ const column = table.getColumn(sort.id);
38
+ return column ? column_getCanSort(column) : false;
39
+ });
37
40
  const resolvedSorting = [];
38
41
  for (let i = 0; i < availableSorting.length; i++) {
39
42
  const sortEntry = availableSorting[i];
@@ -1 +1 @@
1
- {"version":3,"file":"createSortedRowModel.js","names":[],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted 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 *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) =>\n column_getCanSort(\n table.getColumn(sort.id) as Column_Internal<TFeatures, TData>,\n ),\n )\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined && bUndefined) {\n continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (rows: Array<Row<TFeatures, TData>>) => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row.subRows.length) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = sortData(row.subRows)\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return sortedData\n }\n\n return {\n rows: sortData(preSortedRowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;oCACd,MAAM,MAAM,qFAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqB,yBAAyB,KAAK;EACrD,CAAC;CACH;AACF;AAEA,SAAS,sBAGP,OAAqE;;CACrE,MAAM,oBAAoB,MAAM,qBAAqB;CACrD,MAAM,mCAAU,MAAM,MAAM,uFAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,oDAAC,QAAS,SAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAAmB,QAAQ,QAAQ,SACvC,kBACE,MAAM,UAAU,KAAK,EAAE,CACzB,CACF;CAEA,MAAM,kBAMD,CAAC;CAEN,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ,KAAK;EAChD,MAAM,YAAY,iBAAiB;EACnC,MAAM,SACJ,MAAM,UAAU,UAAU,EAAE;EAC9B,IAAI,CAAC,QACH;EAGF,gBAAgB,KAAK;GACnB,IAAI,UAAU;GACd,MAAM,UAAU;GAChB,eAAe,OAAO,UAAU;GAChC,eAAe,OAAO,UAAU;GAChC,QAAQ,iBAAiB,MAAM;EACjC,CAAC;CACH;CAEA,MAAM,eACJ,MACA,SACG;EACH,KAAK,IAAI,IAAI,GAAG,IAAI,gBAAgB,QAAQ,KAAK;GAC/C,MAAM,YAAY,gBAAgB;GAClC,MAAM,gBAAgB,UAAU;GAChC,MAAM,SAAS,UAAU;GAEzB,IAAI,UAAU;GAGd,IAAI,eAAe;IACjB,MAAM,SAAS,KAAK,SAAS,UAAU,EAAE;IACzC,MAAM,SAAS,KAAK,SAAS,UAAU,EAAE;IAEzC,MAAM,aAAa,WAAW;IAC9B,MAAM,aAAa,WAAW;IAE9B,IAAI,cAAc,YAChB;IAGF,IAAI,cAAc,YAAY;KAC5B,IAAI,kBAAkB,SAAS,OAAO,aAAa,KAAK;KACxD,IAAI,kBAAkB,QAAQ,OAAO,aAAa,IAAI;KACtD,UAAU,aAAa,gBAAgB,CAAC;IAC1C;GACF;GAEA,IAAI,YAAY,GACd,UAAU,UAAU,OAAO,MAAM,MAAM,UAAU,EAAE;GAIrD,IAAI,YAAY,GAAG;IACjB,IAAI,QACF,WAAW;IAGb,IAAI,UAAU,eACZ,WAAW;IAGb,OAAO;GACT;EACF;EAEA,OAAO,KAAK,QAAQ,KAAK;CAC3B;CAEA,MAAM,YAAY,SAAuC;EACvD,MAAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAI3B,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,IAAI,QAAQ,QAAQ;IAEtB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;IACvD,OAAO,OAAO,QAAQ,GAAG;IACzB,OAAO,UAAU,SAAS,IAAI,OAAO;IACrC,WAAW,KAAK;IAChB,eAAe,KAAK,MAAM;GAC5B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI;EACrC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
1
+ {"version":3,"file":"createSortedRowModel.js","names":[],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { tableMemo } from '../../utils'\nimport { table_autoResetPageIndex } from '../row-pagination/rowPaginationFeature.utils'\nimport { column_getCanSort, column_getSortFn } from './rowSortingFeature.utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { RowModel } from '../../core/row-models/coreRowModelsFeature.types'\nimport type { Table, Table_Internal } from '../../types/Table'\nimport type { Row } from '../../types/Row'\nimport type { SortFn } from './rowSortingFeature.types'\nimport type { RowData } from '../../types/type-utils'\n\n/**\n * Creates a memoized sorted 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 *\n * Register sorting functions with the `sortFns` slot on the `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.\n */\nexport function createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData> {\n return (_table) => {\n const table = _table as unknown as Table_Internal<TFeatures, TData>\n return tableMemo({\n feature: 'rowSortingFeature',\n table,\n fnName: 'table.getSortedRowModel',\n memoDeps: () => [\n table.atoms.sorting?.get(),\n table.getPreSortedRowModel(),\n ],\n fn: () => _createSortedRowModel(table),\n onAfterUpdate: () => table_autoResetPageIndex(table),\n })\n }\n}\n\nfunction _createSortedRowModel<\n TFeatures extends TableFeatures,\n TData extends RowData = any,\n>(table: Table_Internal<TFeatures, TData>): RowModel<TFeatures, TData> {\n const preSortedRowModel = table.getPreSortedRowModel()\n const sorting = table.atoms.sorting?.get()\n\n if (!preSortedRowModel.rows.length || !sorting?.length) {\n return preSortedRowModel\n }\n\n const sortedFlatRows: Array<Row<TFeatures, TData>> = []\n\n // Filter out sortings that correspond to non existing columns\n const availableSorting = sorting.filter((sort) => {\n const column = table.getColumn(sort.id)\n return column ? column_getCanSort(column) : false\n })\n\n const resolvedSorting: Array<{\n id: string\n desc?: boolean\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n invertSorting?: boolean\n sortFn: SortFn<TFeatures, TData>\n }> = []\n\n for (let i = 0; i < availableSorting.length; i++) {\n const sortEntry = availableSorting[i]!\n const column: Column_Internal<TFeatures, TData> | undefined =\n table.getColumn(sortEntry.id)\n if (!column) {\n continue\n }\n\n resolvedSorting.push({\n id: sortEntry.id,\n desc: sortEntry.desc,\n sortUndefined: column.columnDef.sortUndefined,\n invertSorting: column.columnDef.invertSorting,\n sortFn: column_getSortFn(column),\n })\n }\n\n const compareRows = (\n rowA: Row<TFeatures, TData>,\n rowB: Row<TFeatures, TData>,\n ) => {\n for (let i = 0; i < resolvedSorting.length; i++) {\n const sortEntry = resolvedSorting[i]!\n const sortUndefined = sortEntry.sortUndefined\n const isDesc = sortEntry.desc\n\n let sortInt = 0\n\n // All sorting ints should always return in ascending order\n if (sortUndefined) {\n const aValue = rowA.getValue(sortEntry.id)\n const bValue = rowB.getValue(sortEntry.id)\n\n const aUndefined = aValue === undefined\n const bUndefined = bValue === undefined\n\n if (aUndefined && bUndefined) {\n continue\n }\n\n if (aUndefined || bUndefined) {\n if (sortUndefined === 'first') return aUndefined ? -1 : 1\n if (sortUndefined === 'last') return aUndefined ? 1 : -1\n sortInt = aUndefined ? sortUndefined : -sortUndefined\n }\n }\n\n if (sortInt === 0) {\n sortInt = sortEntry.sortFn(rowA, rowB, sortEntry.id)\n }\n\n // If sorting is non-zero, take care of desc and inversion\n if (sortInt !== 0) {\n if (isDesc) {\n sortInt *= -1\n }\n\n if (sortEntry.invertSorting) {\n sortInt *= -1\n }\n\n return sortInt\n }\n }\n\n return rowA.index - rowB.index\n }\n\n const sortData = (rows: Array<Row<TFeatures, TData>>) => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n\n // If there are sub-rows, sort them. Clone only rows that need mutation\n // (i.e. have subRows) so we don't corrupt the source row model.\n for (let i = 0; i < sortedData.length; i++) {\n const row = sortedData[i]!\n if (row.subRows.length) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n Object.assign(cloned, row)\n cloned.subRows = sortData(row.subRows)\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return sortedData\n }\n\n return {\n rows: sortData(preSortedRowModel.rows),\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;;oCACd,MAAM,MAAM,qFAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqB,yBAAyB,KAAK;EACrD,CAAC;CACH;AACF;AAEA,SAAS,sBAGP,OAAqE;;CACrE,MAAM,oBAAoB,MAAM,qBAAqB;CACrD,MAAM,mCAAU,MAAM,MAAM,uFAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,oDAAC,QAAS,SAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAAmB,QAAQ,QAAQ,SAAS;EAChD,MAAM,SAAS,MAAM,UAAU,KAAK,EAAE;EACtC,OAAO,SAAS,kBAAkB,MAAM,IAAI;CAC9C,CAAC;CAED,MAAM,kBAMD,CAAC;CAEN,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ,KAAK;EAChD,MAAM,YAAY,iBAAiB;EACnC,MAAM,SACJ,MAAM,UAAU,UAAU,EAAE;EAC9B,IAAI,CAAC,QACH;EAGF,gBAAgB,KAAK;GACnB,IAAI,UAAU;GACd,MAAM,UAAU;GAChB,eAAe,OAAO,UAAU;GAChC,eAAe,OAAO,UAAU;GAChC,QAAQ,iBAAiB,MAAM;EACjC,CAAC;CACH;CAEA,MAAM,eACJ,MACA,SACG;EACH,KAAK,IAAI,IAAI,GAAG,IAAI,gBAAgB,QAAQ,KAAK;GAC/C,MAAM,YAAY,gBAAgB;GAClC,MAAM,gBAAgB,UAAU;GAChC,MAAM,SAAS,UAAU;GAEzB,IAAI,UAAU;GAGd,IAAI,eAAe;IACjB,MAAM,SAAS,KAAK,SAAS,UAAU,EAAE;IACzC,MAAM,SAAS,KAAK,SAAS,UAAU,EAAE;IAEzC,MAAM,aAAa,WAAW;IAC9B,MAAM,aAAa,WAAW;IAE9B,IAAI,cAAc,YAChB;IAGF,IAAI,cAAc,YAAY;KAC5B,IAAI,kBAAkB,SAAS,OAAO,aAAa,KAAK;KACxD,IAAI,kBAAkB,QAAQ,OAAO,aAAa,IAAI;KACtD,UAAU,aAAa,gBAAgB,CAAC;IAC1C;GACF;GAEA,IAAI,YAAY,GACd,UAAU,UAAU,OAAO,MAAM,MAAM,UAAU,EAAE;GAIrD,IAAI,YAAY,GAAG;IACjB,IAAI,QACF,WAAW;IAGb,IAAI,UAAU,eACZ,WAAW;IAGb,OAAO;GACT;EACF;EAEA,OAAO,KAAK,QAAQ,KAAK;CAC3B;CAEA,MAAM,YAAY,SAAuC;EACvD,MAAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAI3B,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,IAAI,QAAQ,QAAQ;IAEtB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;IACvD,OAAO,OAAO,QAAQ,GAAG;IACzB,OAAO,UAAU,SAAS,IAAI,OAAO;IACrC,WAAW,KAAK;IAChB,eAAe,KAAK,MAAM;GAC5B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;CACT;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI;EACrC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/table-core",
3
- "version": "9.0.0-beta.29",
3
+ "version": "9.0.0-beta.31",
4
4
  "description": "Headless UI for building powerful tables & datagrids for TS/JS.",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -83,11 +83,17 @@ function _createGroupedRowModel<
83
83
  return rows.map((row) => {
84
84
  row.depth = depth
85
85
 
86
- groupedFlatRows.push(row)
87
- groupedRowsById[row.id] = row
88
-
86
+ // Every row is pushed into flatRows/rowsById exactly once, by its
87
+ // parent frame: rows returned here are pushed by the caller (the
88
+ // parent group's loop or the root loop), so only descendants below
89
+ // the terminal depth are pushed here.
89
90
  if (row.subRows.length) {
90
91
  row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id)
92
+ for (let i = 0; i < row.subRows.length; i++) {
93
+ const subRow = row.subRows[i]!
94
+ groupedFlatRows.push(subRow)
95
+ groupedRowsById[subRow.id] = subRow
96
+ }
91
97
  }
92
98
 
93
99
  return row
@@ -247,7 +247,7 @@ export function table_getFilteredSelectedRowModel<
247
247
  TFeatures extends TableFeatures,
248
248
  TData extends RowData,
249
249
  >(table: Table_Internal<TFeatures, TData>) {
250
- const rowModel = table.getCoreRowModel()
250
+ const rowModel = table.getFilteredRowModel()
251
251
 
252
252
  if (
253
253
  !callMemoOrStaticFn(
@@ -281,7 +281,9 @@ export function table_getGroupedSelectedRowModel<
281
281
  TFeatures extends TableFeatures,
282
282
  TData extends RowData,
283
283
  >(table: Table_Internal<TFeatures, TData>) {
284
- const rowModel = table.getCoreRowModel()
284
+ // The sorted model falls back grouped -> filtered -> core when those
285
+ // features are not registered, so selected group rows are always visible.
286
+ const rowModel = table.getSortedRowModel()
285
287
 
286
288
  if (
287
289
  !callMemoOrStaticFn(
@@ -51,11 +51,10 @@ function _createSortedRowModel<
51
51
  const sortedFlatRows: Array<Row<TFeatures, TData>> = []
52
52
 
53
53
  // Filter out sortings that correspond to non existing columns
54
- const availableSorting = sorting.filter((sort) =>
55
- column_getCanSort(
56
- table.getColumn(sort.id) as Column_Internal<TFeatures, TData>,
57
- ),
58
- )
54
+ const availableSorting = sorting.filter((sort) => {
55
+ const column = table.getColumn(sort.id)
56
+ return column ? column_getCanSort(column) : false
57
+ })
59
58
 
60
59
  const resolvedSorting: Array<{
61
60
  id: string