@tanstack/table-core 9.0.0-beta.46 → 9.0.0-beta.48

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.
Files changed (212) hide show
  1. package/dist/core/row-models/coreRowModelsFeature.types.d.cts +1 -1
  2. package/dist/core/row-models/coreRowModelsFeature.types.d.ts +1 -1
  3. package/dist/core/row-models/coreRowModelsFeature.utils.cjs +1 -1
  4. package/dist/core/row-models/coreRowModelsFeature.utils.cjs.map +1 -1
  5. package/dist/core/row-models/coreRowModelsFeature.utils.d.cts +1 -1
  6. package/dist/core/row-models/coreRowModelsFeature.utils.d.ts +1 -1
  7. package/dist/core/row-models/coreRowModelsFeature.utils.js +1 -1
  8. package/dist/core/row-models/coreRowModelsFeature.utils.js.map +1 -1
  9. package/dist/features/aggregation/aggregationFeature.cjs +38 -0
  10. package/dist/features/aggregation/aggregationFeature.cjs.map +1 -0
  11. package/dist/features/aggregation/aggregationFeature.d.cts +10 -0
  12. package/dist/features/aggregation/aggregationFeature.d.ts +10 -0
  13. package/dist/features/aggregation/aggregationFeature.js +38 -0
  14. package/dist/features/aggregation/aggregationFeature.js.map +1 -0
  15. package/dist/features/aggregation/aggregationFeature.types.cjs +13 -0
  16. package/dist/features/aggregation/aggregationFeature.types.cjs.map +1 -0
  17. package/dist/features/aggregation/aggregationFeature.types.d.cts +172 -0
  18. package/dist/features/aggregation/aggregationFeature.types.d.ts +172 -0
  19. package/dist/features/aggregation/aggregationFeature.types.js +12 -0
  20. package/dist/features/aggregation/aggregationFeature.types.js.map +1 -0
  21. package/dist/features/aggregation/aggregationFeature.utils.cjs +198 -0
  22. package/dist/features/aggregation/aggregationFeature.utils.cjs.map +1 -0
  23. package/dist/features/aggregation/aggregationFeature.utils.d.cts +33 -0
  24. package/dist/features/aggregation/aggregationFeature.utils.d.ts +33 -0
  25. package/dist/features/aggregation/aggregationFeature.utils.js +192 -0
  26. package/dist/features/aggregation/aggregationFeature.utils.js.map +1 -0
  27. package/dist/features/aggregation/aggregationFns.cjs +240 -0
  28. package/dist/features/aggregation/aggregationFns.cjs.map +1 -0
  29. package/dist/features/aggregation/aggregationFns.d.cts +67 -0
  30. package/dist/features/aggregation/aggregationFns.d.ts +67 -0
  31. package/dist/features/aggregation/aggregationFns.js +229 -0
  32. package/dist/features/aggregation/aggregationFns.js.map +1 -0
  33. package/dist/features/column-filtering/columnFilteringFeature.types.d.cts +43 -3
  34. package/dist/features/column-filtering/columnFilteringFeature.types.d.ts +43 -3
  35. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs +18 -9
  36. package/dist/features/column-filtering/columnFilteringFeature.utils.cjs.map +1 -1
  37. package/dist/features/column-filtering/columnFilteringFeature.utils.d.cts +6 -2
  38. package/dist/features/column-filtering/columnFilteringFeature.utils.d.ts +6 -2
  39. package/dist/features/column-filtering/columnFilteringFeature.utils.js +18 -9
  40. package/dist/features/column-filtering/columnFilteringFeature.utils.js.map +1 -1
  41. package/dist/features/column-filtering/createFilteredRowModel.cjs +7 -2
  42. package/dist/features/column-filtering/createFilteredRowModel.cjs.map +1 -1
  43. package/dist/features/column-filtering/createFilteredRowModel.d.cts +6 -2
  44. package/dist/features/column-filtering/createFilteredRowModel.d.ts +6 -2
  45. package/dist/features/column-filtering/createFilteredRowModel.js +7 -2
  46. package/dist/features/column-filtering/createFilteredRowModel.js.map +1 -1
  47. package/dist/features/column-filtering/filterFns.cjs +399 -0
  48. package/dist/features/column-filtering/filterFns.cjs.map +1 -0
  49. package/dist/features/column-filtering/filterFns.d.cts +210 -0
  50. package/dist/features/column-filtering/filterFns.d.ts +210 -0
  51. package/dist/features/column-filtering/filterFns.js +375 -0
  52. package/dist/features/column-filtering/filterFns.js.map +1 -0
  53. package/dist/features/column-grouping/columnGroupingFeature.cjs +3 -12
  54. package/dist/features/column-grouping/columnGroupingFeature.cjs.map +1 -1
  55. package/dist/features/column-grouping/columnGroupingFeature.d.cts +1 -1
  56. package/dist/features/column-grouping/columnGroupingFeature.d.ts +1 -1
  57. package/dist/features/column-grouping/columnGroupingFeature.js +4 -13
  58. package/dist/features/column-grouping/columnGroupingFeature.js.map +1 -1
  59. package/dist/features/column-grouping/columnGroupingFeature.types.d.cts +6 -49
  60. package/dist/features/column-grouping/columnGroupingFeature.types.d.ts +6 -49
  61. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs +0 -50
  62. package/dist/features/column-grouping/columnGroupingFeature.utils.cjs.map +1 -1
  63. package/dist/features/column-grouping/columnGroupingFeature.utils.d.cts +2 -39
  64. package/dist/features/column-grouping/columnGroupingFeature.utils.d.ts +2 -39
  65. package/dist/features/column-grouping/columnGroupingFeature.utils.js +2 -49
  66. package/dist/features/column-grouping/columnGroupingFeature.utils.js.map +1 -1
  67. package/dist/features/column-grouping/createGroupedRowModel.cjs +23 -13
  68. package/dist/features/column-grouping/createGroupedRowModel.cjs.map +1 -1
  69. package/dist/features/column-grouping/createGroupedRowModel.d.cts +2 -3
  70. package/dist/features/column-grouping/createGroupedRowModel.d.ts +2 -3
  71. package/dist/features/column-grouping/createGroupedRowModel.js +25 -15
  72. package/dist/features/column-grouping/createGroupedRowModel.js.map +1 -1
  73. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs +4 -2
  74. package/dist/features/global-filtering/globalFilteringFeature.utils.cjs.map +1 -1
  75. package/dist/features/global-filtering/globalFilteringFeature.utils.d.cts +2 -6
  76. package/dist/features/global-filtering/globalFilteringFeature.utils.d.ts +2 -6
  77. package/dist/features/global-filtering/globalFilteringFeature.utils.js +4 -2
  78. package/dist/features/global-filtering/globalFilteringFeature.utils.js.map +1 -1
  79. package/dist/features/row-sorting/createSortedRowModel.cjs +6 -2
  80. package/dist/features/row-sorting/createSortedRowModel.cjs.map +1 -1
  81. package/dist/features/row-sorting/createSortedRowModel.d.cts +6 -2
  82. package/dist/features/row-sorting/createSortedRowModel.d.ts +6 -2
  83. package/dist/features/row-sorting/createSortedRowModel.js +6 -2
  84. package/dist/features/row-sorting/createSortedRowModel.js.map +1 -1
  85. package/dist/features/row-sorting/rowSortingFeature.types.d.cts +32 -3
  86. package/dist/features/row-sorting/rowSortingFeature.types.d.ts +32 -3
  87. package/dist/features/row-sorting/rowSortingFeature.utils.cjs +20 -5
  88. package/dist/features/row-sorting/rowSortingFeature.utils.cjs.map +1 -1
  89. package/dist/features/row-sorting/rowSortingFeature.utils.js +20 -5
  90. package/dist/features/row-sorting/rowSortingFeature.utils.js.map +1 -1
  91. package/dist/{fns → features/row-sorting}/sortFns.cjs +69 -22
  92. package/dist/features/row-sorting/sortFns.cjs.map +1 -0
  93. package/dist/features/row-sorting/sortFns.d.cts +98 -0
  94. package/dist/features/row-sorting/sortFns.d.ts +98 -0
  95. package/dist/{fns → features/row-sorting}/sortFns.js +69 -23
  96. package/dist/features/row-sorting/sortFns.js.map +1 -0
  97. package/dist/features/stockFeatures.cjs +2 -0
  98. package/dist/features/stockFeatures.cjs.map +1 -1
  99. package/dist/features/stockFeatures.d.cts +2 -0
  100. package/dist/features/stockFeatures.d.ts +2 -0
  101. package/dist/features/stockFeatures.js +2 -0
  102. package/dist/features/stockFeatures.js.map +1 -1
  103. package/dist/helpers/tableFeatures.cjs +5 -4
  104. package/dist/helpers/tableFeatures.cjs.map +1 -1
  105. package/dist/helpers/tableFeatures.d.cts +5 -4
  106. package/dist/helpers/tableFeatures.d.ts +5 -4
  107. package/dist/helpers/tableFeatures.js +5 -4
  108. package/dist/helpers/tableFeatures.js.map +1 -1
  109. package/dist/index.cjs +18 -3
  110. package/dist/index.d.cts +10 -8
  111. package/dist/index.d.ts +10 -8
  112. package/dist/index.js +6 -4
  113. package/dist/static-functions.cjs +8 -3
  114. package/dist/static-functions.d.cts +3 -2
  115. package/dist/static-functions.d.ts +3 -2
  116. package/dist/static-functions.js +3 -2
  117. package/dist/types/Cell.d.cts +3 -1
  118. package/dist/types/Cell.d.ts +3 -1
  119. package/dist/types/Column.d.cts +4 -2
  120. package/dist/types/Column.d.ts +4 -2
  121. package/dist/types/ColumnDef.d.cts +5 -3
  122. package/dist/types/ColumnDef.d.ts +5 -3
  123. package/dist/types/Row.d.cts +3 -1
  124. package/dist/types/Row.d.ts +3 -1
  125. package/dist/types/RowModel.d.cts +1 -1
  126. package/dist/types/RowModel.d.ts +1 -1
  127. package/dist/types/RowModelFns.d.cts +3 -3
  128. package/dist/types/RowModelFns.d.ts +3 -3
  129. package/dist/types/Table.d.cts +1 -1
  130. package/dist/types/Table.d.ts +1 -1
  131. package/dist/types/TableFeatures.d.cts +19 -11
  132. package/dist/types/TableFeatures.d.ts +19 -11
  133. package/dist/types/TableOptions.d.cts +5 -3
  134. package/dist/types/TableOptions.d.ts +5 -3
  135. package/dist/types/TableState.d.cts +1 -1
  136. package/dist/types/TableState.d.ts +1 -1
  137. package/dist/types/type-utils.d.cts +8 -1
  138. package/dist/types/type-utils.d.ts +8 -1
  139. package/dist/worker/initTableWorker.cjs.map +1 -1
  140. package/dist/worker/initTableWorker.js.map +1 -1
  141. package/package.json +1 -1
  142. package/skills/aggregation/SKILL.md +131 -0
  143. package/skills/api-not-found/SKILL.md +1 -1
  144. package/skills/client-vs-server/SKILL.md +1 -1
  145. package/skills/column-faceting/SKILL.md +11 -5
  146. package/skills/column-filtering/SKILL.md +8 -3
  147. package/skills/column-ordering/SKILL.md +1 -1
  148. package/skills/column-pinning/SKILL.md +1 -1
  149. package/skills/column-resizing/SKILL.md +1 -1
  150. package/skills/column-sizing/SKILL.md +1 -1
  151. package/skills/column-visibility/SKILL.md +1 -1
  152. package/skills/core/SKILL.md +1 -1
  153. package/skills/custom-features/SKILL.md +1 -1
  154. package/skills/expanding/SKILL.md +1 -1
  155. package/skills/global-filtering/SKILL.md +3 -3
  156. package/skills/grouping/SKILL.md +12 -13
  157. package/skills/migrate-v8-to-v9/SKILL.md +21 -8
  158. package/skills/pagination/SKILL.md +1 -1
  159. package/skills/row-pinning/SKILL.md +1 -1
  160. package/skills/row-selection/SKILL.md +1 -1
  161. package/skills/sorting/SKILL.md +9 -3
  162. package/skills/table-features/SKILL.md +19 -13
  163. package/skills/typescript/SKILL.md +1 -1
  164. package/src/core/row-models/coreRowModelsFeature.utils.ts +1 -1
  165. package/src/features/aggregation/aggregationFeature.ts +59 -0
  166. package/src/features/aggregation/aggregationFeature.types.ts +312 -0
  167. package/src/features/aggregation/aggregationFeature.utils.ts +401 -0
  168. package/src/features/aggregation/aggregationFns.ts +336 -0
  169. package/src/features/column-filtering/columnFilteringFeature.types.ts +61 -1
  170. package/src/features/column-filtering/columnFilteringFeature.utils.ts +33 -19
  171. package/src/features/column-filtering/createFilteredRowModel.ts +13 -3
  172. package/src/features/column-filtering/filterFns.ts +533 -0
  173. package/src/features/column-grouping/columnGroupingFeature.ts +1 -20
  174. package/src/features/column-grouping/columnGroupingFeature.types.ts +4 -86
  175. package/src/features/column-grouping/columnGroupingFeature.utils.ts +1 -88
  176. package/src/features/column-grouping/createGroupedRowModel.ts +32 -38
  177. package/src/features/global-filtering/globalFilteringFeature.utils.ts +9 -1
  178. package/src/features/row-sorting/createSortedRowModel.ts +6 -2
  179. package/src/features/row-sorting/rowSortingFeature.types.ts +54 -2
  180. package/src/features/row-sorting/rowSortingFeature.utils.ts +46 -14
  181. package/src/{fns → features/row-sorting}/sortFns.ts +95 -81
  182. package/src/features/stockFeatures.ts +3 -0
  183. package/src/helpers/tableFeatures.ts +5 -4
  184. package/src/index.ts +7 -8
  185. package/src/static-functions.ts +1 -0
  186. package/src/types/Cell.ts +2 -0
  187. package/src/types/Column.ts +3 -1
  188. package/src/types/ColumnDef.ts +6 -3
  189. package/src/types/Row.ts +2 -0
  190. package/src/types/RowModelFns.ts +3 -3
  191. package/src/types/TableFeatures.ts +19 -11
  192. package/src/types/TableOptions.ts +5 -1
  193. package/src/types/type-utils.ts +8 -0
  194. package/src/worker/initTableWorker.ts +1 -1
  195. package/dist/fns/aggregationFns.cjs +0 -163
  196. package/dist/fns/aggregationFns.cjs.map +0 -1
  197. package/dist/fns/aggregationFns.d.cts +0 -85
  198. package/dist/fns/aggregationFns.d.ts +0 -85
  199. package/dist/fns/aggregationFns.js +0 -153
  200. package/dist/fns/aggregationFns.js.map +0 -1
  201. package/dist/fns/filterFns.cjs +0 -242
  202. package/dist/fns/filterFns.cjs.map +0 -1
  203. package/dist/fns/filterFns.d.cts +0 -178
  204. package/dist/fns/filterFns.d.ts +0 -178
  205. package/dist/fns/filterFns.js +0 -226
  206. package/dist/fns/filterFns.js.map +0 -1
  207. package/dist/fns/sortFns.cjs.map +0 -1
  208. package/dist/fns/sortFns.d.cts +0 -65
  209. package/dist/fns/sortFns.d.ts +0 -65
  210. package/dist/fns/sortFns.js.map +0 -1
  211. package/src/fns/aggregationFns.ts +0 -245
  212. package/src/fns/filterFns.ts +0 -455
@@ -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 // 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,CACd,MAAM,MAAM,UAAU,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,WAAW,MAAM,MAAM,UAAU,IAAI;CAE3C,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,UAAU,QAAQ;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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I,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"}
1
+ {"version":3,"file":"createGroupedRowModel.cjs","names":["tableMemo","table_getColumn","makeObjectMap","normalizeAggregationRows","constructRow","hasOwn","aggregateColumnValue","row_getGroupingValue"],"sources":["../../../src/features/column-grouping/createGroupedRowModel.ts"],"sourcesContent":["import { 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 aggregateColumnValue,\n normalizeAggregationRows,\n} from '../aggregation/aggregationFeature.utils'\nimport { row_getGroupingValue } from './columnGroupingFeature.utils'\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 * When aggregationFeature is also registered, grouped rows use its shared\n * executor for non-group values. Grouping remains useful without aggregation.\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 table.options.columns,\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 const leafRows = normalizeAggregationRows(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 const groupingIndex = existingGrouping.indexOf(colId)\n\n // The active grouping column and ancestor grouping columns expose\n // their inherited grouping values. Columns grouped at deeper\n // levels are still eligible for aggregation here.\n if (groupingIndex !== -1 && groupingIndex <= depth) {\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 const aggregationCache = (row as any)._aggregationValuesCache as\n | Record<string, unknown>\n | undefined\n if (aggregationCache && hasOwn(aggregationCache, colId)) {\n return aggregationCache[colId]\n }\n\n const column = table.getColumn(colId) as any\n if (typeof column.getAggregationFns !== 'function') return undefined\n\n const cache = ((row as any)._aggregationValuesCache ??=\n makeObjectMap())\n cache[colId] = aggregateColumnValue({\n childRows: subRows,\n column,\n groupingRow: row,\n rows: leafRows,\n })\n return cache[colId]\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":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,wBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;IACd,MAAM,MAAM,UAAU,IAAI;IAC1B,MAAM,sBAAsB;IAC5B,MAAM,QAAQ;GAChB;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,WAAW,MAAM,MAAM,UAAU,IAAI;CAE3C,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,UAAU,QAAQ;EAC9C,SAAS,K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,IAAIC,qBAAO,IAAI,cAAc,KAAK,GAChC,OAAO,IAAI,aAAa;MAG1B,IAAI,YAAY,IACd,IAAI,aAAa,SACf,YAAY,EAAE,CAAC,SAAS,KAAK,KAAK;MAGtC,OAAO,IAAI,aAAa;KAC1B;KAEA,MAAM,mBAAoB,IAAY;KAGtC,IAAI,oBAAoBA,qBAAO,kBAAkB,KAAK,GACpD,OAAO,iBAAiB;KAG1B,MAAM,SAAS,MAAM,UAAU,KAAK;KACpC,IAAI,OAAO,OAAO,sBAAsB,YAAY,OAAO;KAE3D,MAAM,QAAS,AAAC,IAAY,4BAC1BH,4BAAc;KAChB,MAAM,SAASI,sDAAqB;MAClC,WAAW;MACX;MACA,aAAa;MACb,MAAM;KACR,CAAC;KACD,OAAO,MAAM;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,GAAGC,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"}
@@ -9,9 +9,8 @@ import { TableFeatures } from "../../types/TableFeatures.cjs";
9
9
  *
10
10
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
11
11
  *
12
- * Register aggregation functions with the `aggregationFns` slot on the
13
- * `features` option:
14
- * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.
12
+ * When aggregationFeature is also registered, grouped rows use its shared
13
+ * executor for non-group values. Grouping remains useful without aggregation.
15
14
  */
16
15
  declare function createGroupedRowModel<TFeatures extends TableFeatures, TData extends RowData = any>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData>;
17
16
  //#endregion
@@ -9,9 +9,8 @@ import { TableFeatures } from "../../types/TableFeatures.js";
9
9
  *
10
10
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
11
11
  *
12
- * Register aggregation functions with the `aggregationFns` slot on the
13
- * `features` option:
14
- * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.
12
+ * When aggregationFeature is also registered, grouped rows use its shared
13
+ * executor for non-group values. Grouping remains useful without aggregation.
15
14
  */
16
15
  declare function createGroupedRowModel<TFeatures extends TableFeatures, TData extends RowData = any>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData>;
17
16
  //#endregion
@@ -1,8 +1,9 @@
1
- import { flattenBy, hasOwn, makeObjectMap, tableMemo } from "../../utils.js";
1
+ import { hasOwn, makeObjectMap, tableMemo } from "../../utils.js";
2
2
  import { table_getColumn } from "../../core/columns/coreColumnsFeature.utils.js";
3
3
  import { constructRow } from "../../core/rows/constructRow.js";
4
4
  import { table_autoResetPageIndex } from "../row-pagination/rowPaginationFeature.utils.js";
5
- import { column_getAggregationFn, row_getGroupingValue } from "./columnGroupingFeature.utils.js";
5
+ import { aggregateColumnValue, normalizeAggregationRows } from "../aggregation/aggregationFeature.utils.js";
6
+ import { row_getGroupingValue } from "./columnGroupingFeature.utils.js";
6
7
  import { table_autoResetExpanded } from "../row-expanding/rowExpandingFeature.utils.js";
7
8
 
8
9
  //#region src/features/column-grouping/createGroupedRowModel.ts
@@ -11,9 +12,8 @@ import { table_autoResetExpanded } from "../row-expanding/rowExpandingFeature.ut
11
12
  *
12
13
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
13
14
  *
14
- * Register aggregation functions with the `aggregationFns` slot on the
15
- * `features` option:
16
- * `tableFeatures({ columnGroupingFeature, groupedRowModel: createGroupedRowModel(), aggregationFns })`.
15
+ * When aggregationFeature is also registered, grouped rows use its shared
16
+ * executor for non-group values. Grouping remains useful without aggregation.
17
17
  */
18
18
  function createGroupedRowModel() {
19
19
  return (_table) => {
@@ -22,7 +22,11 @@ function createGroupedRowModel() {
22
22
  feature: "columnGroupingFeature",
23
23
  table,
24
24
  fnName: "table.getGroupedRowModel",
25
- memoDeps: () => [table.atoms.grouping?.get(), table.getPreGroupedRowModel()],
25
+ memoDeps: () => [
26
+ table.atoms.grouping?.get(),
27
+ table.getPreGroupedRowModel(),
28
+ table.options.columns
29
+ ],
26
30
  fn: () => _createGroupedRowModel(table),
27
31
  onAfterUpdate: () => {
28
32
  table_autoResetExpanded(table);
@@ -66,7 +70,7 @@ function _createGroupedRowModel(table) {
66
70
  subRows.forEach((subRow) => {
67
71
  subRow.parentId = id;
68
72
  });
69
- const leafRows = depth ? flattenBy(groupedRows, (row) => row.subRows) : groupedRows;
73
+ const leafRows = normalizeAggregationRows(groupedRows);
70
74
  const row = constructRow(table, id, leafRows[0].original, index, depth, void 0, parentId);
71
75
  Object.assign(row, {
72
76
  groupingColumnId: columnId,
@@ -74,18 +78,24 @@ function _createGroupedRowModel(table) {
74
78
  subRows,
75
79
  leafRows,
76
80
  getValue: (colId) => {
77
- if (existingGrouping.includes(colId)) {
81
+ const groupingIndex = existingGrouping.indexOf(colId);
82
+ if (groupingIndex !== -1 && groupingIndex <= depth) {
78
83
  if (hasOwn(row._valuesCache, colId)) return row._valuesCache[colId];
79
84
  if (groupedRows[0]) row._valuesCache[colId] = groupedRows[0].getValue(colId) ?? void 0;
80
85
  return row._valuesCache[colId];
81
86
  }
82
- if (row._groupingValuesCache && hasOwn(row._groupingValuesCache, colId)) return row._groupingValuesCache[colId];
83
- const aggregateFn = column_getAggregationFn(table.getColumn(colId));
84
- if (!row._groupingValuesCache) row._groupingValuesCache = makeObjectMap();
85
- if (aggregateFn) {
86
- row._groupingValuesCache[colId] = aggregateFn(colId, leafRows, groupedRows);
87
- return row._groupingValuesCache[colId];
88
- }
87
+ const aggregationCache = row._aggregationValuesCache;
88
+ if (aggregationCache && hasOwn(aggregationCache, colId)) return aggregationCache[colId];
89
+ const column = table.getColumn(colId);
90
+ if (typeof column.getAggregationFns !== "function") return void 0;
91
+ const cache = row._aggregationValuesCache ??= makeObjectMap();
92
+ cache[colId] = aggregateColumnValue({
93
+ childRows: subRows,
94
+ column,
95
+ groupingRow: row,
96
+ rows: leafRows
97
+ });
98
+ return cache[colId];
89
99
  }
90
100
  });
91
101
  subRows.forEach((subRow) => {
@@ -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 // 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,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB,CACd,MAAM,MAAM,UAAU,IAAI,GAC1B,MAAM,sBAAsB,CAC9B;GACA,UAAU,uBAAuB,KAAK;GACtC,qBAAqB;IACnB,wBAAwB,KAAK;IAC7B,yBAAyB,KAAK;GAChC;EACF,CAAC;CACH;AACF;AAEA,SAAS,uBAGP,OAAqE;CACrE,MAAM,WAAW,MAAM,sBAAsB;CAC7C,MAAM,WAAW,MAAM,MAAM,UAAU,IAAI;CAE3C,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,UAAU,QAAQ;EAC9C,SAAS,KAAK,SAAS,QAAQ;GAC7B,IAAI,QAAQ;GACZ,IAAI,WAAW;EACjB,CAAC;EACD,OAAO;CACT;CAGA,MAAM,mBAAmB,SAAS,QAAQ,aACxC,gBAAgB,OAAO,QAAQ,CACjC;CAEA,MAAM,kBAC0B,CAAC;CACjC,MAAM,kBAAkB,cAAqC;CAG7D,MAAM,sBACJ,MACA,QAAQ,GACR,aACG;EAGH,IAAI,SAAS,iBAAiB,QAC5B,OAAO,KAAK,KAAK,QAAQ;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AAuB,cAAc;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,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"}
1
+ {"version":3,"file":"createGroupedRowModel.js","names":[],"sources":["../../../src/features/column-grouping/createGroupedRowModel.ts"],"sourcesContent":["import { 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 aggregateColumnValue,\n normalizeAggregationRows,\n} from '../aggregation/aggregationFeature.utils'\nimport { row_getGroupingValue } from './columnGroupingFeature.utils'\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 * When aggregationFeature is also registered, grouped rows use its shared\n * executor for non-group values. Grouping remains useful without aggregation.\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 table.options.columns,\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 const leafRows = normalizeAggregationRows(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 const groupingIndex = existingGrouping.indexOf(colId)\n\n // The active grouping column and ancestor grouping columns expose\n // their inherited grouping values. Columns grouped at deeper\n // levels are still eligible for aggregation here.\n if (groupingIndex !== -1 && groupingIndex <= depth) {\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 const aggregationCache = (row as any)._aggregationValuesCache as\n | Record<string, unknown>\n | undefined\n if (aggregationCache && hasOwn(aggregationCache, colId)) {\n return aggregationCache[colId]\n }\n\n const column = table.getColumn(colId) as any\n if (typeof column.getAggregationFns !== 'function') return undefined\n\n const cache = ((row as any)._aggregationValuesCache ??=\n makeObjectMap())\n cache[colId] = aggregateColumnValue({\n childRows: subRows,\n column,\n groupingRow: row,\n rows: leafRows,\n })\n return cache[colId]\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":";;;;;;;;;;;;;;;;;AAyBA,SAAgB,wBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB;IACd,MAAM,MAAM,UAAU,IAAI;IAC1B,MAAM,sBAAsB;IAC5B,MAAM,QAAQ;GAChB;GACA,UAAU,uBAAuB,KAAK;GACtC,qBAAqB;IACnB,wBAAwB,KAAK;IAC7B,yBAAyB,KAAK;GAChC;EACF,CAAC;CACH;AACF;AAEA,SAAS,uBAGP,OAAqE;CACrE,MAAM,WAAW,MAAM,sBAAsB;CAC7C,MAAM,WAAW,MAAM,MAAM,UAAU,IAAI;CAE3C,IAAI,CAAC,SAAS,KAAK,UAAU,CAAC,UAAU,QAAQ;EAC9C,SAAS,KAAK,SAAS,QAAQ;GAC7B,IAAI,QAAQ;GACZ,IAAI,WAAW;EACjB,CAAC;EACD,OAAO;CACT;CAGA,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AAY,EAAE,CAAC,SAAS,KAAK,KAAK;MAGtC,OAAO,IAAI,aAAa;KAC1B;KAEA,MAAM,mBAAoB,IAAY;KAGtC,IAAI,oBAAoB,OAAO,kBAAkB,KAAK,GACpD,OAAO,iBAAiB;KAG1B,MAAM,SAAS,MAAM,UAAU,KAAK;KACpC,IAAI,OAAO,OAAO,sBAAsB,YAAY,OAAO;KAE3D,MAAM,QAAS,AAAC,IAAY,4BAC1B,cAAc;KAChB,MAAM,SAAS,qBAAqB;MAClC,WAAW;MACX;MACA,aAAa;MACb,MAAM;KACR,CAAC;KACD,OAAO,MAAM;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,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"}
@@ -1,5 +1,5 @@
1
1
  const require_utils = require('../../utils.cjs');
2
- const require_filterFns = require('../../fns/filterFns.cjs');
2
+ const require_filterFns = require('../column-filtering/filterFns.cjs');
3
3
 
4
4
  //#region src/features/global-filtering/globalFilteringFeature.utils.ts
5
5
  /**
@@ -45,7 +45,9 @@ function table_getGlobalAutoFilterFn() {
45
45
  function table_getGlobalFilterFn(table) {
46
46
  const { globalFilterFn } = table.options;
47
47
  const filterFns = table._rowModelFns.filterFns;
48
- return require_utils.isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === "auto" ? table_getGlobalAutoFilterFn() : filterFns?.[globalFilterFn];
48
+ const filterFn = require_utils.isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === "auto" ? table_getGlobalAutoFilterFn() : filterFns?.[globalFilterFn];
49
+ if (process.env.NODE_ENV === "development" && !filterFn && globalFilterFn != null) console.warn(`globalFilterFn '${String(globalFilterFn)}' is not registered`);
50
+ return filterFn;
49
51
  }
50
52
  /**
51
53
  * Routes a global filter updater through the table's global filter handler.
@@ -1 +1 @@
1
- {"version":3,"file":"globalFilteringFeature.utils.cjs","names":["filterFn_includesString","isFunction","cloneState"],"sources":["../../../src/features/global-filtering/globalFilteringFeature.utils.ts"],"sourcesContent":["import { filterFn_includesString } from '../../fns/filterFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { FilterFn } from '../column-filtering/columnFilteringFeature.types'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\n\n/**\n * Checks whether this accessor column participates in global filtering.\n *\n * The column must have an accessor and pass column-level, table-level, and\n * optional `getColumnCanGlobalFilter` checks.\n *\n * @example\n * ```ts\n * const canGlobalFilter = column_getCanGlobalFilter(column)\n * ```\n */\nexport function column_getCanGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n (column.columnDef.enableGlobalFilter ?? true) &&\n (column.table.options.enableGlobalFilter ?? true) &&\n (column.table.options.enableFilters ?? true) &&\n (column.table.options.getColumnCanGlobalFilter?.(column as any) ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Provides the built-in automatic global filter function.\n *\n * Global filtering defaults to `includesString`, which gives search-box style\n * matching across globally filterable columns.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalAutoFilterFn()\n * ```\n */\nexport function table_getGlobalAutoFilterFn() {\n return filterFn_includesString\n}\n\n/**\n * Resolves the filter function used for global filtering.\n *\n * Function-valued `options.globalFilterFn` is returned directly, `'auto'`\n * delegates to `table_getGlobalAutoFilterFn`, and string values are looked up in\n * the table's filter function registry.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalFilterFn(table)\n * ```\n */\nexport function table_getGlobalFilterFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): FilterFn<TFeatures, TData> | undefined {\n const { globalFilterFn: globalFilterFn } = table.options\n const filterFns: Record<string, FilterFn<TFeatures, TData>> | undefined =\n table._rowModelFns.filterFns\n\n const filterFn = isFunction(globalFilterFn)\n ? globalFilterFn\n : globalFilterFn === 'auto'\n ? table_getGlobalAutoFilterFn()\n : filterFns?.[globalFilterFn as string]\n\n return filterFn\n}\n\n/**\n * Routes a global filter updater through the table's global filter handler.\n *\n * The updater may be a next value or a function of the previous value, matching\n * the instance `table.setGlobalFilter` behavior.\n *\n * @example\n * ```ts\n * table_setGlobalFilter(table, 'search text')\n * ```\n */\nexport function table_setGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: any) {\n table.options.onGlobalFilterChange?.(updater)\n}\n\n/**\n * Resets `globalFilter` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.globalFilter`. Passing\n * `true` ignores initial state and resets to `undefined`.\n *\n * @example\n * ```ts\n * table_resetGlobalFilter(table)\n * table_resetGlobalFilter(table, true)\n * ```\n */\nexport function table_resetGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGlobalFilter(\n table,\n defaultState ? undefined : cloneState(table.initialState.globalFilter),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,0BAId,QAA4D;CAC5D,QACG,OAAO,UAAU,sBAAsB,UACvC,OAAO,MAAM,QAAQ,sBAAsB,UAC3C,OAAO,MAAM,QAAQ,iBAAiB,UACtC,OAAO,MAAM,QAAQ,2BAA2B,MAAa,KAAK,SACnE,CAAC,CAAC,OAAO;AAEb;;;;;;;;;;;;AAaA,SAAgB,8BAA8B;CAC5C,OAAOA;AACT;;;;;;;;;;;;;AAcA,SAAgB,wBAId,OACwC;CACxC,MAAM,EAAkB,mBAAmB,MAAM;CACjD,MAAM,YACJ,MAAM,aAAa;CAQrB,OANiBC,yBAAW,cAAc,IACtC,iBACA,mBAAmB,SACjB,4BAA4B,IAC5B,YAAY;AAGpB;;;;;;;;;;;;AAaA,SAAgB,sBAGd,OAAyC,SAAc;CACvD,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eAAe,SAAYC,yBAAW,MAAM,aAAa,YAAY,CACvE;AACF"}
1
+ {"version":3,"file":"globalFilteringFeature.utils.cjs","names":["filterFn_includesString","isFunction","cloneState"],"sources":["../../../src/features/global-filtering/globalFilteringFeature.utils.ts"],"sourcesContent":["import { filterFn_includesString } from '../column-filtering/filterFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { FilterFn } from '../column-filtering/columnFilteringFeature.types'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\n\n/**\n * Checks whether this accessor column participates in global filtering.\n *\n * The column must have an accessor and pass column-level, table-level, and\n * optional `getColumnCanGlobalFilter` checks.\n *\n * @example\n * ```ts\n * const canGlobalFilter = column_getCanGlobalFilter(column)\n * ```\n */\nexport function column_getCanGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n (column.columnDef.enableGlobalFilter ?? true) &&\n (column.table.options.enableGlobalFilter ?? true) &&\n (column.table.options.enableFilters ?? true) &&\n (column.table.options.getColumnCanGlobalFilter?.(column as any) ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Provides the built-in automatic global filter function.\n *\n * Global filtering defaults to `includesString`, which gives search-box style\n * matching across globally filterable columns.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalAutoFilterFn()\n * ```\n */\nexport function table_getGlobalAutoFilterFn() {\n return filterFn_includesString\n}\n\n/**\n * Resolves the filter function used for global filtering.\n *\n * Function-valued `options.globalFilterFn` is returned directly, `'auto'`\n * delegates to `table_getGlobalAutoFilterFn`, and string values are looked up in\n * the table's filter function registry.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalFilterFn(table)\n * ```\n */\nexport function table_getGlobalFilterFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): FilterFn<TFeatures, TData> | undefined {\n const { globalFilterFn: globalFilterFn } = table.options\n const filterFns: Record<string, FilterFn<TFeatures, TData>> | undefined =\n table._rowModelFns.filterFns\n\n const filterFn = isFunction(globalFilterFn)\n ? globalFilterFn\n : globalFilterFn === 'auto'\n ? table_getGlobalAutoFilterFn()\n : filterFns?.[globalFilterFn as string]\n\n if (\n process.env.NODE_ENV === 'development' &&\n !filterFn &&\n globalFilterFn != null\n ) {\n console.warn(`globalFilterFn '${String(globalFilterFn)}' is not registered`)\n }\n\n return filterFn\n}\n\n/**\n * Routes a global filter updater through the table's global filter handler.\n *\n * The updater may be a next value or a function of the previous value, matching\n * the instance `table.setGlobalFilter` behavior.\n *\n * @example\n * ```ts\n * table_setGlobalFilter(table, 'search text')\n * ```\n */\nexport function table_setGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: any) {\n table.options.onGlobalFilterChange?.(updater)\n}\n\n/**\n * Resets `globalFilter` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.globalFilter`. Passing\n * `true` ignores initial state and resets to `undefined`.\n *\n * @example\n * ```ts\n * table_resetGlobalFilter(table)\n * table_resetGlobalFilter(table, true)\n * ```\n */\nexport function table_resetGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGlobalFilter(\n table,\n defaultState ? undefined : cloneState(table.initialState.globalFilter),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,0BAId,QAA4D;CAC5D,QACG,OAAO,UAAU,sBAAsB,UACvC,OAAO,MAAM,QAAQ,sBAAsB,UAC3C,OAAO,MAAM,QAAQ,iBAAiB,UACtC,OAAO,MAAM,QAAQ,2BAA2B,MAAa,KAAK,SACnE,CAAC,CAAC,OAAO;AAEb;;;;;;;;;;;;AAaA,SAAgB,8BAA8B;CAC5C,OAAOA;AACT;;;;;;;;;;;;;AAcA,SAAgB,wBAId,OACwC;CACxC,MAAM,EAAkB,mBAAmB,MAAM;CACjD,MAAM,YACJ,MAAM,aAAa;CAErB,MAAM,WAAWC,yBAAW,cAAc,IACtC,iBACA,mBAAmB,SACjB,4BAA4B,IAC5B,YAAY;CAElB,IACE,QAAQ,IAAI,aAAa,iBACzB,CAAC,YACD,kBAAkB,MAElB,QAAQ,KAAK,mBAAmB,OAAO,cAAc,EAAE,oBAAoB;CAG7E,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,sBAGd,OAAyC,SAAc;CACvD,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eAAe,SAAYC,yBAAW,MAAM,aAAa,YAAY,CACvE;AACF"}
@@ -1,6 +1,5 @@
1
1
  import { CellData, RowData } from "../../types/type-utils.cjs";
2
- import { Row } from "../../types/Row.cjs";
3
- import { FilterFn } from "../column-filtering/columnFilteringFeature.types.cjs";
2
+ import { CreatedFilterFn, FilterFn } from "../column-filtering/columnFilteringFeature.types.cjs";
4
3
  import { Table } from "../../types/Table.cjs";
5
4
  import { Column } from "../../types/Column.cjs";
6
5
  import { TableFeatures } from "../../types/TableFeatures.cjs";
@@ -28,10 +27,7 @@ declare function column_getCanGlobalFilter<TFeatures extends TableFeatures, TDat
28
27
  * const filterFn = table_getGlobalAutoFilterFn()
29
28
  * ```
30
29
  */
31
- declare function table_getGlobalAutoFilterFn(): (<TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>, columnId: string, filterValue: unknown) => boolean) & {
32
- autoRemove: (val: any) => boolean;
33
- resolveFilterValue: (val: any) => string;
34
- };
30
+ declare function table_getGlobalAutoFilterFn(): CreatedFilterFn<any, any>;
35
31
  /**
36
32
  * Resolves the filter function used for global filtering.
37
33
  *
@@ -1,6 +1,5 @@
1
1
  import { CellData, RowData } from "../../types/type-utils.js";
2
- import { Row } from "../../types/Row.js";
3
- import { FilterFn } from "../column-filtering/columnFilteringFeature.types.js";
2
+ import { CreatedFilterFn, FilterFn } from "../column-filtering/columnFilteringFeature.types.js";
4
3
  import { Table } from "../../types/Table.js";
5
4
  import { Column } from "../../types/Column.js";
6
5
  import { TableFeatures } from "../../types/TableFeatures.js";
@@ -28,10 +27,7 @@ declare function column_getCanGlobalFilter<TFeatures extends TableFeatures, TDat
28
27
  * const filterFn = table_getGlobalAutoFilterFn()
29
28
  * ```
30
29
  */
31
- declare function table_getGlobalAutoFilterFn(): (<TFeatures extends TableFeatures, TData extends RowData>(row: Row<TFeatures, TData>, columnId: string, filterValue: unknown) => boolean) & {
32
- autoRemove: (val: any) => boolean;
33
- resolveFilterValue: (val: any) => string;
34
- };
30
+ declare function table_getGlobalAutoFilterFn(): CreatedFilterFn<any, any>;
35
31
  /**
36
32
  * Resolves the filter function used for global filtering.
37
33
  *
@@ -1,5 +1,5 @@
1
1
  import { cloneState, isFunction } from "../../utils.js";
2
- import { filterFn_includesString } from "../../fns/filterFns.js";
2
+ import { filterFn_includesString } from "../column-filtering/filterFns.js";
3
3
 
4
4
  //#region src/features/global-filtering/globalFilteringFeature.utils.ts
5
5
  /**
@@ -45,7 +45,9 @@ function table_getGlobalAutoFilterFn() {
45
45
  function table_getGlobalFilterFn(table) {
46
46
  const { globalFilterFn } = table.options;
47
47
  const filterFns = table._rowModelFns.filterFns;
48
- return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === "auto" ? table_getGlobalAutoFilterFn() : filterFns?.[globalFilterFn];
48
+ const filterFn = isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === "auto" ? table_getGlobalAutoFilterFn() : filterFns?.[globalFilterFn];
49
+ if (process.env.NODE_ENV === "development" && !filterFn && globalFilterFn != null) console.warn(`globalFilterFn '${String(globalFilterFn)}' is not registered`);
50
+ return filterFn;
49
51
  }
50
52
  /**
51
53
  * Routes a global filter updater through the table's global filter handler.
@@ -1 +1 @@
1
- {"version":3,"file":"globalFilteringFeature.utils.js","names":[],"sources":["../../../src/features/global-filtering/globalFilteringFeature.utils.ts"],"sourcesContent":["import { filterFn_includesString } from '../../fns/filterFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { FilterFn } from '../column-filtering/columnFilteringFeature.types'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\n\n/**\n * Checks whether this accessor column participates in global filtering.\n *\n * The column must have an accessor and pass column-level, table-level, and\n * optional `getColumnCanGlobalFilter` checks.\n *\n * @example\n * ```ts\n * const canGlobalFilter = column_getCanGlobalFilter(column)\n * ```\n */\nexport function column_getCanGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n (column.columnDef.enableGlobalFilter ?? true) &&\n (column.table.options.enableGlobalFilter ?? true) &&\n (column.table.options.enableFilters ?? true) &&\n (column.table.options.getColumnCanGlobalFilter?.(column as any) ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Provides the built-in automatic global filter function.\n *\n * Global filtering defaults to `includesString`, which gives search-box style\n * matching across globally filterable columns.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalAutoFilterFn()\n * ```\n */\nexport function table_getGlobalAutoFilterFn() {\n return filterFn_includesString\n}\n\n/**\n * Resolves the filter function used for global filtering.\n *\n * Function-valued `options.globalFilterFn` is returned directly, `'auto'`\n * delegates to `table_getGlobalAutoFilterFn`, and string values are looked up in\n * the table's filter function registry.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalFilterFn(table)\n * ```\n */\nexport function table_getGlobalFilterFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): FilterFn<TFeatures, TData> | undefined {\n const { globalFilterFn: globalFilterFn } = table.options\n const filterFns: Record<string, FilterFn<TFeatures, TData>> | undefined =\n table._rowModelFns.filterFns\n\n const filterFn = isFunction(globalFilterFn)\n ? globalFilterFn\n : globalFilterFn === 'auto'\n ? table_getGlobalAutoFilterFn()\n : filterFns?.[globalFilterFn as string]\n\n return filterFn\n}\n\n/**\n * Routes a global filter updater through the table's global filter handler.\n *\n * The updater may be a next value or a function of the previous value, matching\n * the instance `table.setGlobalFilter` behavior.\n *\n * @example\n * ```ts\n * table_setGlobalFilter(table, 'search text')\n * ```\n */\nexport function table_setGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: any) {\n table.options.onGlobalFilterChange?.(updater)\n}\n\n/**\n * Resets `globalFilter` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.globalFilter`. Passing\n * `true` ignores initial state and resets to `undefined`.\n *\n * @example\n * ```ts\n * table_resetGlobalFilter(table)\n * table_resetGlobalFilter(table, true)\n * ```\n */\nexport function table_resetGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGlobalFilter(\n table,\n defaultState ? undefined : cloneState(table.initialState.globalFilter),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,0BAId,QAA4D;CAC5D,QACG,OAAO,UAAU,sBAAsB,UACvC,OAAO,MAAM,QAAQ,sBAAsB,UAC3C,OAAO,MAAM,QAAQ,iBAAiB,UACtC,OAAO,MAAM,QAAQ,2BAA2B,MAAa,KAAK,SACnE,CAAC,CAAC,OAAO;AAEb;;;;;;;;;;;;AAaA,SAAgB,8BAA8B;CAC5C,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,wBAId,OACwC;CACxC,MAAM,EAAkB,mBAAmB,MAAM;CACjD,MAAM,YACJ,MAAM,aAAa;CAQrB,OANiB,WAAW,cAAc,IACtC,iBACA,mBAAmB,SACjB,4BAA4B,IAC5B,YAAY;AAGpB;;;;;;;;;;;;AAaA,SAAgB,sBAGd,OAAyC,SAAc;CACvD,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eAAe,SAAY,WAAW,MAAM,aAAa,YAAY,CACvE;AACF"}
1
+ {"version":3,"file":"globalFilteringFeature.utils.js","names":[],"sources":["../../../src/features/global-filtering/globalFilteringFeature.utils.ts"],"sourcesContent":["import { filterFn_includesString } from '../column-filtering/filterFns'\nimport { cloneState, isFunction } from '../../utils'\nimport type { Column_Internal } from '../../types/Column'\nimport type { FilterFn } from '../column-filtering/columnFilteringFeature.types'\nimport type { CellData, RowData } from '../../types/type-utils'\nimport type { TableFeatures } from '../../types/TableFeatures'\nimport type { Table_Internal } from '../../types/Table'\n\n/**\n * Checks whether this accessor column participates in global filtering.\n *\n * The column must have an accessor and pass column-level, table-level, and\n * optional `getColumnCanGlobalFilter` checks.\n *\n * @example\n * ```ts\n * const canGlobalFilter = column_getCanGlobalFilter(column)\n * ```\n */\nexport function column_getCanGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n TValue extends CellData = CellData,\n>(column: Column_Internal<TFeatures, TData, TValue>): boolean {\n return (\n (column.columnDef.enableGlobalFilter ?? true) &&\n (column.table.options.enableGlobalFilter ?? true) &&\n (column.table.options.enableFilters ?? true) &&\n (column.table.options.getColumnCanGlobalFilter?.(column as any) ?? true) &&\n !!column.accessorFn\n )\n}\n\n/**\n * Provides the built-in automatic global filter function.\n *\n * Global filtering defaults to `includesString`, which gives search-box style\n * matching across globally filterable columns.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalAutoFilterFn()\n * ```\n */\nexport function table_getGlobalAutoFilterFn() {\n return filterFn_includesString\n}\n\n/**\n * Resolves the filter function used for global filtering.\n *\n * Function-valued `options.globalFilterFn` is returned directly, `'auto'`\n * delegates to `table_getGlobalAutoFilterFn`, and string values are looked up in\n * the table's filter function registry.\n *\n * @example\n * ```ts\n * const filterFn = table_getGlobalFilterFn(table)\n * ```\n */\nexport function table_getGlobalFilterFn<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(\n table: Table_Internal<TFeatures, TData>,\n): FilterFn<TFeatures, TData> | undefined {\n const { globalFilterFn: globalFilterFn } = table.options\n const filterFns: Record<string, FilterFn<TFeatures, TData>> | undefined =\n table._rowModelFns.filterFns\n\n const filterFn = isFunction(globalFilterFn)\n ? globalFilterFn\n : globalFilterFn === 'auto'\n ? table_getGlobalAutoFilterFn()\n : filterFns?.[globalFilterFn as string]\n\n if (\n process.env.NODE_ENV === 'development' &&\n !filterFn &&\n globalFilterFn != null\n ) {\n console.warn(`globalFilterFn '${String(globalFilterFn)}' is not registered`)\n }\n\n return filterFn\n}\n\n/**\n * Routes a global filter updater through the table's global filter handler.\n *\n * The updater may be a next value or a function of the previous value, matching\n * the instance `table.setGlobalFilter` behavior.\n *\n * @example\n * ```ts\n * table_setGlobalFilter(table, 'search text')\n * ```\n */\nexport function table_setGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, updater: any) {\n table.options.onGlobalFilterChange?.(updater)\n}\n\n/**\n * Resets `globalFilter` to the configured initial state or feature default.\n *\n * With no argument, the reset clones `table.initialState.globalFilter`. Passing\n * `true` ignores initial state and resets to `undefined`.\n *\n * @example\n * ```ts\n * table_resetGlobalFilter(table)\n * table_resetGlobalFilter(table, true)\n * ```\n */\nexport function table_resetGlobalFilter<\n TFeatures extends TableFeatures,\n TData extends RowData,\n>(table: Table_Internal<TFeatures, TData>, defaultState?: boolean) {\n table_setGlobalFilter(\n table,\n defaultState ? undefined : cloneState(table.initialState.globalFilter),\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,0BAId,QAA4D;CAC5D,QACG,OAAO,UAAU,sBAAsB,UACvC,OAAO,MAAM,QAAQ,sBAAsB,UAC3C,OAAO,MAAM,QAAQ,iBAAiB,UACtC,OAAO,MAAM,QAAQ,2BAA2B,MAAa,KAAK,SACnE,CAAC,CAAC,OAAO;AAEb;;;;;;;;;;;;AAaA,SAAgB,8BAA8B;CAC5C,OAAO;AACT;;;;;;;;;;;;;AAcA,SAAgB,wBAId,OACwC;CACxC,MAAM,EAAkB,mBAAmB,MAAM;CACjD,MAAM,YACJ,MAAM,aAAa;CAErB,MAAM,WAAW,WAAW,cAAc,IACtC,iBACA,mBAAmB,SACjB,4BAA4B,IAC5B,YAAY;CAElB,IACE,QAAQ,IAAI,aAAa,iBACzB,CAAC,YACD,kBAAkB,MAElB,QAAQ,KAAK,mBAAmB,OAAO,cAAc,EAAE,oBAAoB;CAG7E,OAAO;AACT;;;;;;;;;;;;AAaA,SAAgB,sBAGd,OAAyC,SAAc;CACvD,MAAM,QAAQ,uBAAuB,OAAO;AAC9C;;;;;;;;;;;;;AAcA,SAAgB,wBAGd,OAAyC,cAAwB;CACjE,sBACE,OACA,eAAe,SAAY,WAAW,MAAM,aAAa,YAAY,CACvE;AACF"}
@@ -8,8 +8,12 @@ const require_rowSortingFeature_utils = require('./rowSortingFeature.utils.cjs')
8
8
  *
9
9
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
10
10
  *
11
- * Register sorting functions with the `sortFns` slot on the `features` option:
12
- * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.
11
+ * Register the sorting functions you use with the `sortFns` slot on the
12
+ * `features` option:
13
+ * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.
14
+ * Importing individual `sortFn_*` functions keeps unused built-ins out of
15
+ * your bundle; sorting functions passed directly to the `sortFn` column
16
+ * option need no registration at all.
13
17
  */
14
18
  function createSortedRowModel() {
15
19
  return (_table) => {
@@ -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 { copyInstancePropertiesWithoutMemos, 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 if (!availableSorting.length) {\n return preSortedRowModel\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 = (\n rows: Array<Row<TFeatures, TData>>,\n ): {\n rows: Array<Row<TFeatures, TData>>\n changed: boolean\n } => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n let changed = false\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 !== rows[i]) {\n changed = true\n }\n\n if (row.subRows.length) {\n const sortedSubRows = sortData(row.subRows)\n\n if (sortedSubRows.changed) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = sortedSubRows.rows\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n changed = true\n } else {\n sortedFlatRows.push(row)\n }\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return { rows: sortedData, changed }\n }\n\n return {\n rows: sortData(preSortedRowModel.rows).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,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C5B,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,YACJ,SAIG;EACH,MAAM,aAAa,KAAK,MAAM;EAE9B,WAAW,KAAK,WAAW;EAC3B,IAAI,UAAU;EAId,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,QAAQ,KAAK,IACf,UAAU;GAGZ,IAAI,IAAI,QAAQ,QAAQ;IACtB,MAAM,gBAAgB,SAAS,IAAI,OAAO;IAE1C,IAAI,cAAc,SAAS;KAEzB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;KACvD,iDAAmC,QAAQ,GAAG;KAC9C,OAAO,UAAU,cAAc;KAC/B,WAAW,KAAK;KAChB,eAAe,KAAK,MAAM;KAC1B,UAAU;IACZ,OACE,eAAe,KAAK,GAAG;GAE3B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;GAAE,MAAM;GAAY;EAAQ;CACrC;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI,CAAC,CAAC;EACvC,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 { copyInstancePropertiesWithoutMemos, 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 the sorting functions you use with the `sortFns` slot on the\n * `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.\n * Importing individual `sortFn_*` functions keeps unused built-ins out of\n * your bundle; sorting functions passed directly to the `sortFn` column\n * option need no registration at all.\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 if (!availableSorting.length) {\n return preSortedRowModel\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 = (\n rows: Array<Row<TFeatures, TData>>,\n ): {\n rows: Array<Row<TFeatures, TData>>\n changed: boolean\n } => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n let changed = false\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 !== rows[i]) {\n changed = true\n }\n\n if (row.subRows.length) {\n const sortedSubRows = sortData(row.subRows)\n\n if (sortedSubRows.changed) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = sortedSubRows.rows\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n changed = true\n } else {\n sortedFlatRows.push(row)\n }\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return { rows: sortedData, changed }\n }\n\n return {\n rows: sortData(preSortedRowModel.rows).rows,\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAOA,wBAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB,CACd,MAAM,MAAM,SAAS,IAAI,GACzB,MAAM,qBAAqB,CAC7B;GACA,UAAU,sBAAsB,KAAK;GACrC,qBAAqBC,4DAAyB,KAAK;EACrD,CAAC;CACH;AACF;AAEA,SAAS,sBAGP,OAAqE;CACrE,MAAM,oBAAoB,MAAM,qBAAqB;CACrD,MAAM,UAAU,MAAM,MAAM,SAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,CAAC,SAAS,QAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAAmB,QAAQ,QAAQ,SAAS;EAChD,MAAM,SAAS,MAAM,UAAU,KAAK,EAAE;EACtC,OAAO,SAASC,kDAAkB,MAAM,IAAI;CAC9C,CAAC;CAED,IAAI,CAAC,iBAAiB,QACpB,OAAO;CAGT,MAAM,kBAMD,CAAC;CAEN,KAAK,IAAI,IAAI,GAAG,IAAI,iBAAiB,QAAQ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AAgB,SAAS,IAAI,OAAO;IAE1C,IAAI,cAAc,SAAS;KAEzB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;KACvD,iDAAmC,QAAQ,GAAG;KAC9C,OAAO,UAAU,cAAc;KAC/B,WAAW,KAAK;KAChB,eAAe,KAAK,MAAM;KAC1B,UAAU;IACZ,OACE,eAAe,KAAK,GAAG;GAE3B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;GAAE,MAAM;GAAY;EAAQ;CACrC;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI,CAAC,CAAC;EACvC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
@@ -9,8 +9,12 @@ import { TableFeatures } from "../../types/TableFeatures.cjs";
9
9
  *
10
10
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
11
11
  *
12
- * Register sorting functions with the `sortFns` slot on the `features` option:
13
- * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.
12
+ * Register the sorting functions you use with the `sortFns` slot on the
13
+ * `features` option:
14
+ * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.
15
+ * Importing individual `sortFn_*` functions keeps unused built-ins out of
16
+ * your bundle; sorting functions passed directly to the `sortFn` column
17
+ * option need no registration at all.
14
18
  */
15
19
  declare function createSortedRowModel<TFeatures extends TableFeatures, TData extends RowData>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData>;
16
20
  //#endregion
@@ -9,8 +9,12 @@ import { TableFeatures } from "../../types/TableFeatures.js";
9
9
  *
10
10
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
11
11
  *
12
- * Register sorting functions with the `sortFns` slot on the `features` option:
13
- * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.
12
+ * Register the sorting functions you use with the `sortFns` slot on the
13
+ * `features` option:
14
+ * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.
15
+ * Importing individual `sortFn_*` functions keeps unused built-ins out of
16
+ * your bundle; sorting functions passed directly to the `sortFn` column
17
+ * option need no registration at all.
14
18
  */
15
19
  declare function createSortedRowModel<TFeatures extends TableFeatures, TData extends RowData>(): (table: Table<TFeatures, TData>) => () => RowModel<TFeatures, TData>;
16
20
  //#endregion
@@ -8,8 +8,12 @@ import { column_getCanSort, column_getSortFn } from "./rowSortingFeature.utils.j
8
8
  *
9
9
  * The factory reads the relevant table state atoms and options, then returns a row model function used by the table row-model pipeline.
10
10
  *
11
- * Register sorting functions with the `sortFns` slot on the `features` option:
12
- * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns })`.
11
+ * Register the sorting functions you use with the `sortFns` slot on the
12
+ * `features` option:
13
+ * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.
14
+ * Importing individual `sortFn_*` functions keeps unused built-ins out of
15
+ * your bundle; sorting functions passed directly to the `sortFn` column
16
+ * option need no registration at all.
13
17
  */
14
18
  function createSortedRowModel() {
15
19
  return (_table) => {
@@ -1 +1 @@
1
- {"version":3,"file":"createSortedRowModel.js","names":[],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { copyInstancePropertiesWithoutMemos, 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 if (!availableSorting.length) {\n return preSortedRowModel\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 = (\n rows: Array<Row<TFeatures, TData>>,\n ): {\n rows: Array<Row<TFeatures, TData>>\n changed: boolean\n } => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n let changed = false\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 !== rows[i]) {\n changed = true\n }\n\n if (row.subRows.length) {\n const sortedSubRows = sortData(row.subRows)\n\n if (sortedSubRows.changed) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = sortedSubRows.rows\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n changed = true\n } else {\n sortedFlatRows.push(row)\n }\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return { rows: sortedData, changed }\n }\n\n return {\n rows: sortData(preSortedRowModel.rows).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,CACd,MAAM,MAAM,SAAS,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,UAAU,MAAM,MAAM,SAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,CAAC,SAAS,QAC9C,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,IAAI,CAAC,iBAAiB,QACpB,OAAO;CAGT,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,S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U,kBAAkB;CAC9B;AACF"}
1
+ {"version":3,"file":"createSortedRowModel.js","names":[],"sources":["../../../src/features/row-sorting/createSortedRowModel.ts"],"sourcesContent":["import { copyInstancePropertiesWithoutMemos, 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 the sorting functions you use with the `sortFns` slot on the\n * `features` option:\n * `tableFeatures({ rowSortingFeature, sortedRowModel: createSortedRowModel(), sortFns: { alphanumeric: sortFn_alphanumeric } })`.\n * Importing individual `sortFn_*` functions keeps unused built-ins out of\n * your bundle; sorting functions passed directly to the `sortFn` column\n * option need no registration at all.\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 if (!availableSorting.length) {\n return preSortedRowModel\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 = (\n rows: Array<Row<TFeatures, TData>>,\n ): {\n rows: Array<Row<TFeatures, TData>>\n changed: boolean\n } => {\n const sortedData = rows.slice()\n\n sortedData.sort(compareRows)\n let changed = false\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 !== rows[i]) {\n changed = true\n }\n\n if (row.subRows.length) {\n const sortedSubRows = sortData(row.subRows)\n\n if (sortedSubRows.changed) {\n // Preserve prototype chain so methods like getValue() remain accessible\n const cloned = Object.create(Object.getPrototypeOf(row))\n copyInstancePropertiesWithoutMemos(cloned, row)\n cloned.subRows = sortedSubRows.rows\n sortedData[i] = cloned\n sortedFlatRows.push(cloned)\n changed = true\n } else {\n sortedFlatRows.push(row)\n }\n } else {\n sortedFlatRows.push(row)\n }\n }\n\n return { rows: sortedData, changed }\n }\n\n return {\n rows: sortData(preSortedRowModel.rows).rows,\n flatRows: sortedFlatRows,\n rowsById: preSortedRowModel.rowsById,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAuBA,SAAgB,uBAG0D;CACxE,QAAQ,WAAW;EACjB,MAAM,QAAQ;EACd,OAAO,UAAU;GACf,SAAS;GACT;GACA,QAAQ;GACR,gBAAgB,CACd,MAAM,MAAM,SAAS,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,UAAU,MAAM,MAAM,SAAS,IAAI;CAEzC,IAAI,CAAC,kBAAkB,KAAK,UAAU,CAAC,SAAS,QAC9C,OAAO;CAGT,MAAM,iBAA+C,CAAC;CAGtD,MAAM,mBAAmB,QAAQ,QAAQ,SAAS;EAChD,MAAM,SAAS,M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AAW;EAC3B,IAAI,UAAU;EAId,KAAK,IAAI,IAAI,GAAG,IAAI,WAAW,QAAQ,KAAK;GAC1C,MAAM,MAAM,WAAW;GACvB,IAAI,QAAQ,KAAK,IACf,UAAU;GAGZ,IAAI,IAAI,QAAQ,QAAQ;IACtB,MAAM,gBAAgB,SAAS,IAAI,OAAO;IAE1C,IAAI,cAAc,SAAS;KAEzB,MAAM,SAAS,OAAO,OAAO,OAAO,eAAe,GAAG,CAAC;KACvD,mCAAmC,QAAQ,GAAG;KAC9C,OAAO,UAAU,cAAc;KAC/B,WAAW,KAAK;KAChB,eAAe,KAAK,MAAM;KAC1B,UAAU;IACZ,OACE,eAAe,KAAK,GAAG;GAE3B,OACE,eAAe,KAAK,GAAG;EAE3B;EAEA,OAAO;GAAE,MAAM;GAAY;EAAQ;CACrC;CAEA,OAAO;EACL,MAAM,SAAS,kBAAkB,IAAI,CAAC,CAAC;EACvC,UAAU;EACV,UAAU,kBAAkB;CAC9B;AACF"}
@@ -1,5 +1,5 @@
1
- import { OnChangeFn, RowData, Updater } from "../../types/type-utils.cjs";
2
- import { BuiltInSortFn } from "../../fns/sortFns.cjs";
1
+ import { OnChangeFn, RowData, TransformDataValueFn, Updater } from "../../types/type-utils.cjs";
2
+ import { BuiltInSortFn } from "./sortFns.cjs";
3
3
  import { Row } from "../../types/Row.cjs";
4
4
  import { RowModel } from "../../core/row-models/coreRowModelsFeature.types.cjs";
5
5
  import { IsAny, TableFeatures } from "../../types/TableFeatures.cjs";
@@ -20,6 +20,35 @@ interface RowModelFns_RowSorting<in out TFeatures extends TableFeatures, in out
20
20
  interface SortFns {}
21
21
  interface SortFn<in out TFeatures extends TableFeatures, in out TData extends RowData> {
22
22
  (rowA: Row<TFeatures, TData>, rowB: Row<TFeatures, TData>, columnId: string): number;
23
+ /**
24
+ * Normalizes each row's value before the two sides are compared. Only
25
+ * honored by sorting functions built with `constructSortFn` (including all
26
+ * built-in sorting functions).
27
+ */
28
+ resolveDataValue?: TransformDataValueFn;
29
+ }
30
+ /**
31
+ * The definition object accepted by `constructSortFn`.
32
+ *
33
+ * `sort` is a value-level comparator: it receives both rows' (resolved) data
34
+ * values instead of the whole rows, so normalization concerns stay in
35
+ * `resolveDataValue`.
36
+ */
37
+ interface SortFnDef<in out TFeatures extends TableFeatures, in out TData extends RowData> {
38
+ sort: (dataValueA: any, dataValueB: any, rowA: Row<TFeatures, TData>, rowB: Row<TFeatures, TData>, columnId: string) => number;
39
+ resolveDataValue?: TransformDataValueFn;
40
+ }
41
+ /**
42
+ * The shape returned by `constructSortFn`: a `SortFn` with its definition
43
+ * attached, so variants can be built by spreading it into another
44
+ * `constructSortFn` call.
45
+ *
46
+ * The call signature is generic so a created sorting function can be used
47
+ * with any table's rows, regardless of the feature set it was defined
48
+ * against.
49
+ */
50
+ interface CreatedSortFn<in out TFeatures extends TableFeatures, in out TData extends RowData> extends SortFnDef<TFeatures, TData> {
51
+ <TRowFeatures extends TableFeatures, TRowData extends RowData>(rowA: Row<TRowFeatures, TRowData>, rowB: Row<TRowFeatures, TRowData>, columnId: string): number;
23
52
  }
24
53
  type CustomSortFns<TFeatures extends TableFeatures, TData extends RowData> = Record<string, SortFn<TFeatures, TData>>;
25
54
  /**
@@ -187,5 +216,5 @@ interface CachedRowModel_Sorted<in out TFeatures extends TableFeatures, in out T
187
216
  sortedRowModel: () => RowModel<TFeatures, TData>;
188
217
  }
189
218
  //#endregion
190
- export { CachedRowModel_Sorted, ColumnDef_RowSorting, ColumnSort, Column_RowSorting, CustomSortFns, ExtractSortFnKeys, RowModelFns_RowSorting, SortDirection, SortFn, SortFnOption, SortFns, SortingState, TableOptions_RowSorting, TableState_RowSorting, Table_RowModels_Sorted, Table_RowSorting };
219
+ export { CachedRowModel_Sorted, ColumnDef_RowSorting, ColumnSort, Column_RowSorting, CreatedSortFn, CustomSortFns, ExtractSortFnKeys, RowModelFns_RowSorting, SortDirection, SortFn, SortFnDef, SortFnOption, SortFns, SortingState, TableOptions_RowSorting, TableState_RowSorting, Table_RowModels_Sorted, Table_RowSorting };
191
220
  //# sourceMappingURL=rowSortingFeature.types.d.cts.map
@@ -1,5 +1,5 @@
1
- import { OnChangeFn, RowData, Updater } from "../../types/type-utils.js";
2
- import { BuiltInSortFn } from "../../fns/sortFns.js";
1
+ import { OnChangeFn, RowData, TransformDataValueFn, Updater } from "../../types/type-utils.js";
2
+ import { BuiltInSortFn } from "./sortFns.js";
3
3
  import { Row } from "../../types/Row.js";
4
4
  import { RowModel } from "../../core/row-models/coreRowModelsFeature.types.js";
5
5
  import { IsAny, TableFeatures } from "../../types/TableFeatures.js";
@@ -20,6 +20,35 @@ interface RowModelFns_RowSorting<in out TFeatures extends TableFeatures, in out
20
20
  interface SortFns {}
21
21
  interface SortFn<in out TFeatures extends TableFeatures, in out TData extends RowData> {
22
22
  (rowA: Row<TFeatures, TData>, rowB: Row<TFeatures, TData>, columnId: string): number;
23
+ /**
24
+ * Normalizes each row's value before the two sides are compared. Only
25
+ * honored by sorting functions built with `constructSortFn` (including all
26
+ * built-in sorting functions).
27
+ */
28
+ resolveDataValue?: TransformDataValueFn;
29
+ }
30
+ /**
31
+ * The definition object accepted by `constructSortFn`.
32
+ *
33
+ * `sort` is a value-level comparator: it receives both rows' (resolved) data
34
+ * values instead of the whole rows, so normalization concerns stay in
35
+ * `resolveDataValue`.
36
+ */
37
+ interface SortFnDef<in out TFeatures extends TableFeatures, in out TData extends RowData> {
38
+ sort: (dataValueA: any, dataValueB: any, rowA: Row<TFeatures, TData>, rowB: Row<TFeatures, TData>, columnId: string) => number;
39
+ resolveDataValue?: TransformDataValueFn;
40
+ }
41
+ /**
42
+ * The shape returned by `constructSortFn`: a `SortFn` with its definition
43
+ * attached, so variants can be built by spreading it into another
44
+ * `constructSortFn` call.
45
+ *
46
+ * The call signature is generic so a created sorting function can be used
47
+ * with any table's rows, regardless of the feature set it was defined
48
+ * against.
49
+ */
50
+ interface CreatedSortFn<in out TFeatures extends TableFeatures, in out TData extends RowData> extends SortFnDef<TFeatures, TData> {
51
+ <TRowFeatures extends TableFeatures, TRowData extends RowData>(rowA: Row<TRowFeatures, TRowData>, rowB: Row<TRowFeatures, TRowData>, columnId: string): number;
23
52
  }
24
53
  type CustomSortFns<TFeatures extends TableFeatures, TData extends RowData> = Record<string, SortFn<TFeatures, TData>>;
25
54
  /**
@@ -187,5 +216,5 @@ interface CachedRowModel_Sorted<in out TFeatures extends TableFeatures, in out T
187
216
  sortedRowModel: () => RowModel<TFeatures, TData>;
188
217
  }
189
218
  //#endregion
190
- export { CachedRowModel_Sorted, ColumnDef_RowSorting, ColumnSort, Column_RowSorting, CustomSortFns, ExtractSortFnKeys, RowModelFns_RowSorting, SortDirection, SortFn, SortFnOption, SortFns, SortingState, TableOptions_RowSorting, TableState_RowSorting, Table_RowModels_Sorted, Table_RowSorting };
219
+ export { CachedRowModel_Sorted, ColumnDef_RowSorting, ColumnSort, Column_RowSorting, CreatedSortFn, CustomSortFns, ExtractSortFnKeys, RowModelFns_RowSorting, SortDirection, SortFn, SortFnDef, SortFnOption, SortFns, SortingState, TableOptions_RowSorting, TableState_RowSorting, Table_RowModels_Sorted, Table_RowSorting };
191
220
  //# sourceMappingURL=rowSortingFeature.types.d.ts.map