@tanstack/table-core 8.16.0 → 9.0.0-alpha.0

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 (261) hide show
  1. package/dist/cjs/aggregationFns.cjs +98 -0
  2. package/dist/cjs/aggregationFns.cjs.map +1 -0
  3. package/dist/cjs/aggregationFns.d.cts +14 -0
  4. package/dist/cjs/columnHelper.cjs +19 -0
  5. package/dist/cjs/columnHelper.cjs.map +1 -0
  6. package/dist/cjs/columnHelper.d.cts +9 -0
  7. package/dist/cjs/core/cell.cjs +38 -0
  8. package/dist/cjs/core/cell.cjs.map +1 -0
  9. package/dist/cjs/core/cell.d.cts +50 -0
  10. package/dist/cjs/core/column.cjs +81 -0
  11. package/dist/cjs/core/column.cjs.map +1 -0
  12. package/dist/cjs/core/column.d.cts +56 -0
  13. package/dist/cjs/core/headers.cjs +310 -0
  14. package/dist/cjs/core/headers.cjs.map +1 -0
  15. package/dist/cjs/core/headers.d.cts +195 -0
  16. package/dist/cjs/core/row.cjs +93 -0
  17. package/dist/cjs/core/row.cjs.map +1 -0
  18. package/dist/cjs/core/row.d.cts +92 -0
  19. package/dist/cjs/core/table.cjs +228 -0
  20. package/dist/cjs/core/table.cjs.map +1 -0
  21. package/dist/cjs/core/table.d.cts +221 -0
  22. package/dist/cjs/features/ColumnFaceting.cjs +29 -0
  23. package/dist/cjs/features/ColumnFaceting.cjs.map +1 -0
  24. package/dist/cjs/features/ColumnFaceting.d.cts +35 -0
  25. package/dist/cjs/features/ColumnFiltering.cjs +137 -0
  26. package/dist/cjs/features/ColumnFiltering.cjs.map +1 -0
  27. package/dist/cjs/features/ColumnFiltering.d.cts +195 -0
  28. package/dist/cjs/features/ColumnGrouping.cjs +134 -0
  29. package/dist/cjs/features/ColumnGrouping.cjs.map +1 -0
  30. package/dist/cjs/features/ColumnGrouping.d.cts +202 -0
  31. package/dist/cjs/features/ColumnOrdering.cjs +76 -0
  32. package/dist/cjs/features/ColumnOrdering.cjs.map +1 -0
  33. package/dist/cjs/features/ColumnOrdering.d.cts +54 -0
  34. package/dist/cjs/features/ColumnPinning.cjs +145 -0
  35. package/dist/cjs/features/ColumnPinning.cjs.map +1 -0
  36. package/dist/cjs/features/ColumnPinning.d.cts +127 -0
  37. package/dist/cjs/features/ColumnSizing.cjs +308 -0
  38. package/dist/cjs/features/ColumnSizing.cjs.map +1 -0
  39. package/dist/cjs/features/ColumnSizing.d.cts +194 -0
  40. package/dist/cjs/features/ColumnVisibility.cjs +144 -0
  41. package/dist/cjs/features/ColumnVisibility.cjs.map +1 -0
  42. package/dist/cjs/features/ColumnVisibility.d.cts +130 -0
  43. package/dist/cjs/features/GlobalFaceting.cjs +29 -0
  44. package/dist/cjs/features/GlobalFaceting.cjs.map +1 -0
  45. package/dist/cjs/features/GlobalFaceting.d.cts +27 -0
  46. package/dist/cjs/features/GlobalFiltering.cjs +50 -0
  47. package/dist/cjs/features/GlobalFiltering.cjs.map +1 -0
  48. package/dist/cjs/features/GlobalFiltering.d.cts +80 -0
  49. package/dist/cjs/features/RowExpanding.cjs +154 -0
  50. package/dist/cjs/features/RowExpanding.cjs.map +1 -0
  51. package/dist/cjs/features/RowExpanding.d.cts +155 -0
  52. package/dist/cjs/features/RowPagination.cjs +162 -0
  53. package/dist/cjs/features/RowPagination.cjs.map +1 -0
  54. package/dist/cjs/features/RowPagination.d.cts +166 -0
  55. package/dist/cjs/features/RowPinning.cjs +133 -0
  56. package/dist/cjs/features/RowPinning.cjs.map +1 -0
  57. package/dist/cjs/features/RowPinning.d.cts +99 -0
  58. package/dist/cjs/features/RowSelection.cjs +298 -0
  59. package/dist/cjs/features/RowSelection.cjs.map +1 -0
  60. package/dist/cjs/features/RowSelection.d.cts +177 -0
  61. package/dist/cjs/features/RowSorting.cjs +201 -0
  62. package/dist/cjs/features/RowSorting.cjs.map +1 -0
  63. package/dist/cjs/features/RowSorting.d.cts +238 -0
  64. package/dist/cjs/filterFns.cjs +88 -0
  65. package/dist/cjs/filterFns.cjs.map +1 -0
  66. package/dist/cjs/filterFns.d.cts +14 -0
  67. package/{build/lib/index.js → dist/cjs/index.cjs} +36 -49
  68. package/dist/cjs/index.cjs.map +1 -0
  69. package/dist/cjs/index.d.cts +34 -0
  70. package/{build/lib/sortingFns.js → dist/cjs/sortingFns.cjs} +23 -52
  71. package/dist/cjs/sortingFns.cjs.map +1 -0
  72. package/dist/cjs/sortingFns.d.cts +12 -0
  73. package/dist/cjs/types.d.cts +120 -0
  74. package/{build/lib/utils/filterRowsUtils.js → dist/cjs/utils/filterRowsUtils.cjs} +34 -46
  75. package/dist/cjs/utils/filterRowsUtils.cjs.map +1 -0
  76. package/dist/cjs/utils/filterRowsUtils.d.cts +3 -0
  77. package/dist/cjs/utils/getCoreRowModel.cjs +54 -0
  78. package/dist/cjs/utils/getCoreRowModel.cjs.map +1 -0
  79. package/dist/cjs/utils/getCoreRowModel.d.cts +3 -0
  80. package/dist/cjs/utils/getExpandedRowModel.cjs +41 -0
  81. package/dist/cjs/utils/getExpandedRowModel.cjs.map +1 -0
  82. package/dist/cjs/utils/getExpandedRowModel.d.cts +8 -0
  83. package/dist/cjs/utils/getFacetedMinMaxValues.cjs +36 -0
  84. package/dist/cjs/utils/getFacetedMinMaxValues.cjs.map +1 -0
  85. package/dist/cjs/utils/getFacetedMinMaxValues.d.cts +3 -0
  86. package/dist/cjs/utils/getFacetedRowModel.cjs +35 -0
  87. package/dist/cjs/utils/getFacetedRowModel.cjs.map +1 -0
  88. package/dist/cjs/utils/getFacetedRowModel.d.cts +3 -0
  89. package/dist/cjs/utils/getFacetedUniqueValues.cjs +38 -0
  90. package/dist/cjs/utils/getFacetedUniqueValues.cjs.map +1 -0
  91. package/dist/cjs/utils/getFacetedUniqueValues.d.cts +3 -0
  92. package/dist/cjs/utils/getFilteredRowModel.cjs +116 -0
  93. package/dist/cjs/utils/getFilteredRowModel.cjs.map +1 -0
  94. package/dist/cjs/utils/getFilteredRowModel.d.cts +3 -0
  95. package/dist/cjs/utils/getGroupedRowModel.cjs +118 -0
  96. package/dist/cjs/utils/getGroupedRowModel.cjs.map +1 -0
  97. package/dist/cjs/utils/getGroupedRowModel.d.cts +3 -0
  98. package/dist/cjs/utils/getPaginationRowModel.cjs +49 -0
  99. package/dist/cjs/utils/getPaginationRowModel.cjs.map +1 -0
  100. package/dist/cjs/utils/getPaginationRowModel.d.cts +5 -0
  101. package/dist/cjs/utils/getSortedRowModel.cjs +91 -0
  102. package/dist/cjs/utils/getSortedRowModel.cjs.map +1 -0
  103. package/dist/cjs/utils/getSortedRowModel.d.cts +3 -0
  104. package/{build/lib/utils.js → dist/cjs/utils.cjs} +30 -41
  105. package/dist/cjs/utils.cjs.map +1 -0
  106. package/dist/cjs/utils.d.cts +39 -0
  107. package/{build/lib → dist/esm}/aggregationFns.d.ts +2 -1
  108. package/dist/esm/aggregationFns.js +98 -0
  109. package/dist/esm/aggregationFns.js.map +1 -0
  110. package/{build/lib → dist/esm}/columnHelper.d.ts +3 -2
  111. package/dist/esm/columnHelper.js +19 -0
  112. package/{build/lib → dist/esm}/columnHelper.js.map +1 -1
  113. package/{build/lib → dist/esm}/core/cell.d.ts +1 -0
  114. package/dist/esm/core/cell.js +38 -0
  115. package/{build/lib → dist/esm}/core/cell.js.map +1 -1
  116. package/{build/lib → dist/esm}/core/column.d.ts +1 -0
  117. package/dist/esm/core/column.js +81 -0
  118. package/{build/lib → dist/esm}/core/column.js.map +1 -1
  119. package/{build/lib → dist/esm}/core/headers.d.ts +1 -0
  120. package/dist/esm/core/headers.js +310 -0
  121. package/{build/lib → dist/esm}/core/headers.js.map +1 -1
  122. package/{build/lib → dist/esm}/core/row.d.ts +1 -0
  123. package/dist/esm/core/row.js +93 -0
  124. package/{build/lib → dist/esm}/core/row.js.map +1 -1
  125. package/{build/lib → dist/esm}/core/table.d.ts +1 -0
  126. package/dist/esm/core/table.js +228 -0
  127. package/{build/lib → dist/esm}/core/table.js.map +1 -1
  128. package/{build/lib → dist/esm}/features/ColumnFaceting.d.ts +1 -0
  129. package/{build/lib → dist/esm}/features/ColumnFaceting.js +5 -18
  130. package/{build/lib → dist/esm}/features/ColumnFaceting.js.map +1 -1
  131. package/{build/lib → dist/esm}/features/ColumnFiltering.d.ts +1 -0
  132. package/dist/esm/features/ColumnFiltering.js +137 -0
  133. package/{build/lib → dist/esm}/features/ColumnFiltering.js.map +1 -1
  134. package/{build/lib → dist/esm}/features/ColumnGrouping.d.ts +1 -0
  135. package/dist/esm/features/ColumnGrouping.js +134 -0
  136. package/{build/lib → dist/esm}/features/ColumnGrouping.js.map +1 -1
  137. package/{build/lib → dist/esm}/features/ColumnOrdering.d.ts +1 -0
  138. package/dist/esm/features/ColumnOrdering.js +76 -0
  139. package/{build/lib → dist/esm}/features/ColumnOrdering.js.map +1 -1
  140. package/{build/lib → dist/esm}/features/ColumnPinning.d.ts +1 -0
  141. package/dist/esm/features/ColumnPinning.js +145 -0
  142. package/{build/lib → dist/esm}/features/ColumnPinning.js.map +1 -1
  143. package/{build/lib → dist/esm}/features/ColumnSizing.d.ts +2 -1
  144. package/dist/esm/features/ColumnSizing.js +308 -0
  145. package/{build/lib → dist/esm}/features/ColumnSizing.js.map +1 -1
  146. package/{build/lib → dist/esm}/features/ColumnVisibility.d.ts +1 -0
  147. package/dist/esm/features/ColumnVisibility.js +144 -0
  148. package/{build/lib → dist/esm}/features/ColumnVisibility.js.map +1 -1
  149. package/{build/lib → dist/esm}/features/GlobalFaceting.d.ts +1 -0
  150. package/{build/lib → dist/esm}/features/GlobalFaceting.js +8 -21
  151. package/{build/lib → dist/esm}/features/GlobalFaceting.js.map +1 -1
  152. package/{build/lib → dist/esm}/features/GlobalFiltering.d.ts +1 -0
  153. package/dist/esm/features/GlobalFiltering.js +50 -0
  154. package/{build/lib → dist/esm}/features/GlobalFiltering.js.map +1 -1
  155. package/{build/lib → dist/esm}/features/RowExpanding.d.ts +1 -0
  156. package/{build/lib → dist/esm}/features/RowExpanding.js +40 -59
  157. package/{build/lib → dist/esm}/features/RowExpanding.js.map +1 -1
  158. package/{build/lib → dist/esm}/features/RowPagination.d.ts +1 -0
  159. package/dist/esm/features/RowPagination.js +162 -0
  160. package/{build/lib → dist/esm}/features/RowPagination.js.map +1 -1
  161. package/{build/lib → dist/esm}/features/RowPinning.d.ts +1 -0
  162. package/dist/esm/features/RowPinning.js +133 -0
  163. package/{build/lib → dist/esm}/features/RowPinning.js.map +1 -1
  164. package/{build/lib → dist/esm}/features/RowSelection.d.ts +1 -0
  165. package/dist/esm/features/RowSelection.js +298 -0
  166. package/{build/lib → dist/esm}/features/RowSelection.js.map +1 -1
  167. package/{build/lib → dist/esm}/features/RowSorting.d.ts +1 -0
  168. package/dist/esm/features/RowSorting.js +201 -0
  169. package/{build/lib → dist/esm}/features/RowSorting.js.map +1 -1
  170. package/{build/lib → dist/esm}/filterFns.d.ts +2 -1
  171. package/dist/esm/filterFns.js +88 -0
  172. package/dist/esm/filterFns.js.map +1 -0
  173. package/dist/esm/index.d.ts +34 -0
  174. package/dist/esm/index.js +87 -0
  175. package/dist/esm/index.js.map +1 -0
  176. package/{build/lib → dist/esm}/sortingFns.d.ts +2 -1
  177. package/dist/esm/sortingFns.js +91 -0
  178. package/dist/esm/sortingFns.js.map +1 -0
  179. package/{build/lib → dist/esm}/types.d.ts +21 -20
  180. package/{build/lib → dist/esm}/utils/filterRowsUtils.d.ts +1 -0
  181. package/dist/esm/utils/filterRowsUtils.js +99 -0
  182. package/dist/esm/utils/filterRowsUtils.js.map +1 -0
  183. package/{build/lib → dist/esm}/utils/getCoreRowModel.d.ts +1 -0
  184. package/dist/esm/utils/getCoreRowModel.js +54 -0
  185. package/{build/lib → dist/esm}/utils/getCoreRowModel.js.map +1 -1
  186. package/{build/lib → dist/esm}/utils/getExpandedRowModel.d.ts +1 -0
  187. package/dist/esm/utils/getExpandedRowModel.js +41 -0
  188. package/dist/esm/utils/getExpandedRowModel.js.map +1 -0
  189. package/{build/lib → dist/esm}/utils/getFacetedMinMaxValues.d.ts +1 -0
  190. package/dist/esm/utils/getFacetedMinMaxValues.js +36 -0
  191. package/dist/esm/utils/getFacetedMinMaxValues.js.map +1 -0
  192. package/{build/lib → dist/esm}/utils/getFacetedRowModel.d.ts +1 -0
  193. package/dist/esm/utils/getFacetedRowModel.js +35 -0
  194. package/{build/lib → dist/esm}/utils/getFacetedRowModel.js.map +1 -1
  195. package/{build/lib → dist/esm}/utils/getFacetedUniqueValues.d.ts +1 -0
  196. package/dist/esm/utils/getFacetedUniqueValues.js +38 -0
  197. package/dist/esm/utils/getFacetedUniqueValues.js.map +1 -0
  198. package/{build/lib → dist/esm}/utils/getFilteredRowModel.d.ts +1 -0
  199. package/dist/esm/utils/getFilteredRowModel.js +116 -0
  200. package/dist/esm/utils/getFilteredRowModel.js.map +1 -0
  201. package/{build/lib → dist/esm}/utils/getGroupedRowModel.d.ts +1 -0
  202. package/dist/esm/utils/getGroupedRowModel.js +118 -0
  203. package/{build/lib → dist/esm}/utils/getGroupedRowModel.js.map +1 -1
  204. package/{build/lib → dist/esm}/utils/getPaginationRowModel.d.ts +1 -0
  205. package/dist/esm/utils/getPaginationRowModel.js +49 -0
  206. package/dist/esm/utils/getPaginationRowModel.js.map +1 -0
  207. package/{build/lib → dist/esm}/utils/getSortedRowModel.d.ts +1 -0
  208. package/dist/esm/utils/getSortedRowModel.js +91 -0
  209. package/{build/lib → dist/esm}/utils/getSortedRowModel.js.map +1 -1
  210. package/{build/lib → dist/esm}/utils.d.ts +2 -1
  211. package/dist/esm/utils.js +100 -0
  212. package/{build/lib → dist/esm}/utils.js.map +1 -1
  213. package/package.json +15 -19
  214. package/src/utils/getFilteredRowModel.ts +1 -1
  215. package/build/lib/aggregationFns.js +0 -108
  216. package/build/lib/aggregationFns.js.map +0 -1
  217. package/build/lib/columnHelper.js +0 -71
  218. package/build/lib/core/cell.js +0 -42
  219. package/build/lib/core/column.js +0 -80
  220. package/build/lib/core/headers.js +0 -270
  221. package/build/lib/core/row.js +0 -89
  222. package/build/lib/core/table.js +0 -212
  223. package/build/lib/features/ColumnFiltering.js +0 -151
  224. package/build/lib/features/ColumnGrouping.js +0 -142
  225. package/build/lib/features/ColumnOrdering.js +0 -84
  226. package/build/lib/features/ColumnPinning.js +0 -130
  227. package/build/lib/features/ColumnSizing.js +0 -270
  228. package/build/lib/features/ColumnVisibility.js +0 -99
  229. package/build/lib/features/GlobalFiltering.js +0 -63
  230. package/build/lib/features/RowPagination.js +0 -169
  231. package/build/lib/features/RowPinning.js +0 -145
  232. package/build/lib/features/RowSelection.js +0 -391
  233. package/build/lib/features/RowSorting.js +0 -226
  234. package/build/lib/filterFns.js +0 -96
  235. package/build/lib/filterFns.js.map +0 -1
  236. package/build/lib/index.d.ts +0 -34
  237. package/build/lib/index.esm.js +0 -3522
  238. package/build/lib/index.esm.js.map +0 -1
  239. package/build/lib/index.js.map +0 -1
  240. package/build/lib/index.mjs +0 -3522
  241. package/build/lib/index.mjs.map +0 -1
  242. package/build/lib/sortingFns.js.map +0 -1
  243. package/build/lib/utils/filterRowsUtils.js.map +0 -1
  244. package/build/lib/utils/getCoreRowModel.js +0 -65
  245. package/build/lib/utils/getExpandedRowModel.js +0 -46
  246. package/build/lib/utils/getExpandedRowModel.js.map +0 -1
  247. package/build/lib/utils/getFacetedMinMaxValues.js +0 -43
  248. package/build/lib/utils/getFacetedMinMaxValues.js.map +0 -1
  249. package/build/lib/utils/getFacetedRowModel.js +0 -36
  250. package/build/lib/utils/getFacetedUniqueValues.js +0 -39
  251. package/build/lib/utils/getFacetedUniqueValues.js.map +0 -1
  252. package/build/lib/utils/getFilteredRowModel.js +0 -111
  253. package/build/lib/utils/getFilteredRowModel.js.map +0 -1
  254. package/build/lib/utils/getGroupedRowModel.js +0 -150
  255. package/build/lib/utils/getPaginationRowModel.js +0 -60
  256. package/build/lib/utils/getPaginationRowModel.js.map +0 -1
  257. package/build/lib/utils/getSortedRowModel.js +0 -102
  258. package/build/umd/index.development.js +0 -3578
  259. package/build/umd/index.development.js.map +0 -1
  260. package/build/umd/index.production.js +0 -12
  261. package/build/umd/index.production.js.map +0 -1
@@ -0,0 +1,310 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("../utils.cjs");
4
+ const debug = "debugHeaders";
5
+ function createHeader(table, column, options) {
6
+ const id = options.id ?? column.id;
7
+ let header = {
8
+ id,
9
+ column,
10
+ index: options.index,
11
+ isPlaceholder: !!options.isPlaceholder,
12
+ placeholderId: options.placeholderId,
13
+ depth: options.depth,
14
+ subHeaders: [],
15
+ colSpan: 0,
16
+ rowSpan: 0,
17
+ headerGroup: null,
18
+ getLeafHeaders: () => {
19
+ const leafHeaders = [];
20
+ const recurseHeader = (h) => {
21
+ if (h.subHeaders && h.subHeaders.length) {
22
+ h.subHeaders.map(recurseHeader);
23
+ }
24
+ leafHeaders.push(h);
25
+ };
26
+ recurseHeader(header);
27
+ return leafHeaders;
28
+ },
29
+ getContext: () => ({
30
+ table,
31
+ header,
32
+ column
33
+ })
34
+ };
35
+ table._features.forEach((feature) => {
36
+ var _a;
37
+ (_a = feature.createHeader) == null ? void 0 : _a.call(feature, header, table);
38
+ });
39
+ return header;
40
+ }
41
+ const Headers = {
42
+ createTable: (table) => {
43
+ table.getHeaderGroups = utils.memo(
44
+ () => [
45
+ table.getAllColumns(),
46
+ table.getVisibleLeafColumns(),
47
+ table.getState().columnPinning.left,
48
+ table.getState().columnPinning.right
49
+ ],
50
+ (allColumns, leafColumns, left, right) => {
51
+ const leftColumns = (left == null ? void 0 : left.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
52
+ const rightColumns = (right == null ? void 0 : right.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
53
+ const centerColumns = leafColumns.filter(
54
+ (column) => !(left == null ? void 0 : left.includes(column.id)) && !(right == null ? void 0 : right.includes(column.id))
55
+ );
56
+ const headerGroups = buildHeaderGroups(
57
+ allColumns,
58
+ [...leftColumns, ...centerColumns, ...rightColumns],
59
+ table
60
+ );
61
+ return headerGroups;
62
+ },
63
+ utils.getMemoOptions(table.options, debug, "getHeaderGroups")
64
+ );
65
+ table.getCenterHeaderGroups = utils.memo(
66
+ () => [
67
+ table.getAllColumns(),
68
+ table.getVisibleLeafColumns(),
69
+ table.getState().columnPinning.left,
70
+ table.getState().columnPinning.right
71
+ ],
72
+ (allColumns, leafColumns, left, right) => {
73
+ leafColumns = leafColumns.filter(
74
+ (column) => !(left == null ? void 0 : left.includes(column.id)) && !(right == null ? void 0 : right.includes(column.id))
75
+ );
76
+ return buildHeaderGroups(allColumns, leafColumns, table, "center");
77
+ },
78
+ utils.getMemoOptions(table.options, debug, "getCenterHeaderGroups")
79
+ );
80
+ table.getLeftHeaderGroups = utils.memo(
81
+ () => [
82
+ table.getAllColumns(),
83
+ table.getVisibleLeafColumns(),
84
+ table.getState().columnPinning.left
85
+ ],
86
+ (allColumns, leafColumns, left) => {
87
+ const orderedLeafColumns = (left == null ? void 0 : left.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
88
+ return buildHeaderGroups(allColumns, orderedLeafColumns, table, "left");
89
+ },
90
+ utils.getMemoOptions(table.options, debug, "getLeftHeaderGroups")
91
+ );
92
+ table.getRightHeaderGroups = utils.memo(
93
+ () => [
94
+ table.getAllColumns(),
95
+ table.getVisibleLeafColumns(),
96
+ table.getState().columnPinning.right
97
+ ],
98
+ (allColumns, leafColumns, right) => {
99
+ const orderedLeafColumns = (right == null ? void 0 : right.map((columnId) => leafColumns.find((d) => d.id === columnId)).filter(Boolean)) ?? [];
100
+ return buildHeaderGroups(allColumns, orderedLeafColumns, table, "right");
101
+ },
102
+ utils.getMemoOptions(table.options, debug, "getRightHeaderGroups")
103
+ );
104
+ table.getFooterGroups = utils.memo(
105
+ () => [table.getHeaderGroups()],
106
+ (headerGroups) => {
107
+ return [...headerGroups].reverse();
108
+ },
109
+ utils.getMemoOptions(table.options, debug, "getFooterGroups")
110
+ );
111
+ table.getLeftFooterGroups = utils.memo(
112
+ () => [table.getLeftHeaderGroups()],
113
+ (headerGroups) => {
114
+ return [...headerGroups].reverse();
115
+ },
116
+ utils.getMemoOptions(table.options, debug, "getLeftFooterGroups")
117
+ );
118
+ table.getCenterFooterGroups = utils.memo(
119
+ () => [table.getCenterHeaderGroups()],
120
+ (headerGroups) => {
121
+ return [...headerGroups].reverse();
122
+ },
123
+ utils.getMemoOptions(table.options, debug, "getCenterFooterGroups")
124
+ );
125
+ table.getRightFooterGroups = utils.memo(
126
+ () => [table.getRightHeaderGroups()],
127
+ (headerGroups) => {
128
+ return [...headerGroups].reverse();
129
+ },
130
+ utils.getMemoOptions(table.options, debug, "getRightFooterGroups")
131
+ );
132
+ table.getFlatHeaders = utils.memo(
133
+ () => [table.getHeaderGroups()],
134
+ (headerGroups) => {
135
+ return headerGroups.map((headerGroup) => {
136
+ return headerGroup.headers;
137
+ }).flat();
138
+ },
139
+ utils.getMemoOptions(table.options, debug, "getFlatHeaders")
140
+ );
141
+ table.getLeftFlatHeaders = utils.memo(
142
+ () => [table.getLeftHeaderGroups()],
143
+ (left) => {
144
+ return left.map((headerGroup) => {
145
+ return headerGroup.headers;
146
+ }).flat();
147
+ },
148
+ utils.getMemoOptions(table.options, debug, "getLeftFlatHeaders")
149
+ );
150
+ table.getCenterFlatHeaders = utils.memo(
151
+ () => [table.getCenterHeaderGroups()],
152
+ (left) => {
153
+ return left.map((headerGroup) => {
154
+ return headerGroup.headers;
155
+ }).flat();
156
+ },
157
+ utils.getMemoOptions(table.options, debug, "getCenterFlatHeaders")
158
+ );
159
+ table.getRightFlatHeaders = utils.memo(
160
+ () => [table.getRightHeaderGroups()],
161
+ (left) => {
162
+ return left.map((headerGroup) => {
163
+ return headerGroup.headers;
164
+ }).flat();
165
+ },
166
+ utils.getMemoOptions(table.options, debug, "getRightFlatHeaders")
167
+ );
168
+ table.getCenterLeafHeaders = utils.memo(
169
+ () => [table.getCenterFlatHeaders()],
170
+ (flatHeaders) => {
171
+ return flatHeaders.filter((header) => {
172
+ var _a;
173
+ return !((_a = header.subHeaders) == null ? void 0 : _a.length);
174
+ });
175
+ },
176
+ utils.getMemoOptions(table.options, debug, "getCenterLeafHeaders")
177
+ );
178
+ table.getLeftLeafHeaders = utils.memo(
179
+ () => [table.getLeftFlatHeaders()],
180
+ (flatHeaders) => {
181
+ return flatHeaders.filter((header) => {
182
+ var _a;
183
+ return !((_a = header.subHeaders) == null ? void 0 : _a.length);
184
+ });
185
+ },
186
+ utils.getMemoOptions(table.options, debug, "getLeftLeafHeaders")
187
+ );
188
+ table.getRightLeafHeaders = utils.memo(
189
+ () => [table.getRightFlatHeaders()],
190
+ (flatHeaders) => {
191
+ return flatHeaders.filter((header) => {
192
+ var _a;
193
+ return !((_a = header.subHeaders) == null ? void 0 : _a.length);
194
+ });
195
+ },
196
+ utils.getMemoOptions(table.options, debug, "getRightLeafHeaders")
197
+ );
198
+ table.getLeafHeaders = utils.memo(
199
+ () => [
200
+ table.getLeftHeaderGroups(),
201
+ table.getCenterHeaderGroups(),
202
+ table.getRightHeaderGroups()
203
+ ],
204
+ (left, center, right) => {
205
+ var _a, _b, _c;
206
+ return [
207
+ ...((_a = left[0]) == null ? void 0 : _a.headers) ?? [],
208
+ ...((_b = center[0]) == null ? void 0 : _b.headers) ?? [],
209
+ ...((_c = right[0]) == null ? void 0 : _c.headers) ?? []
210
+ ].map((header) => {
211
+ return header.getLeafHeaders();
212
+ }).flat();
213
+ },
214
+ utils.getMemoOptions(table.options, debug, "getLeafHeaders")
215
+ );
216
+ }
217
+ };
218
+ function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
219
+ var _a;
220
+ let maxDepth = 0;
221
+ const findMaxDepth = (columns, depth = 1) => {
222
+ maxDepth = Math.max(maxDepth, depth);
223
+ columns.filter((column) => column.getIsVisible()).forEach((column) => {
224
+ var _a2;
225
+ if ((_a2 = column.columns) == null ? void 0 : _a2.length) {
226
+ findMaxDepth(column.columns, depth + 1);
227
+ }
228
+ }, 0);
229
+ };
230
+ findMaxDepth(allColumns);
231
+ let headerGroups = [];
232
+ const createHeaderGroup = (headersToGroup, depth) => {
233
+ const headerGroup = {
234
+ depth,
235
+ id: [headerFamily, `${depth}`].filter(Boolean).join("_"),
236
+ headers: []
237
+ };
238
+ const pendingParentHeaders = [];
239
+ headersToGroup.forEach((headerToGroup) => {
240
+ const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
241
+ const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
242
+ let column;
243
+ let isPlaceholder = false;
244
+ if (isLeafHeader && headerToGroup.column.parent) {
245
+ column = headerToGroup.column.parent;
246
+ } else {
247
+ column = headerToGroup.column;
248
+ isPlaceholder = true;
249
+ }
250
+ if (latestPendingParentHeader && (latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
251
+ latestPendingParentHeader.subHeaders.push(headerToGroup);
252
+ } else {
253
+ const header = createHeader(table, column, {
254
+ id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join("_"),
255
+ isPlaceholder,
256
+ placeholderId: isPlaceholder ? `${pendingParentHeaders.filter((d) => d.column === column).length}` : void 0,
257
+ depth,
258
+ index: pendingParentHeaders.length
259
+ });
260
+ header.subHeaders.push(headerToGroup);
261
+ pendingParentHeaders.push(header);
262
+ }
263
+ headerGroup.headers.push(headerToGroup);
264
+ headerToGroup.headerGroup = headerGroup;
265
+ });
266
+ headerGroups.push(headerGroup);
267
+ if (depth > 0) {
268
+ createHeaderGroup(pendingParentHeaders, depth - 1);
269
+ }
270
+ };
271
+ const bottomHeaders = columnsToGroup.map(
272
+ (column, index) => createHeader(table, column, {
273
+ depth: maxDepth,
274
+ index
275
+ })
276
+ );
277
+ createHeaderGroup(bottomHeaders, maxDepth - 1);
278
+ headerGroups.reverse();
279
+ const recurseHeadersForSpans = (headers) => {
280
+ const filteredHeaders = headers.filter(
281
+ (header) => header.column.getIsVisible()
282
+ );
283
+ return filteredHeaders.map((header) => {
284
+ let colSpan = 0;
285
+ let rowSpan = 0;
286
+ let childRowSpans = [0];
287
+ if (header.subHeaders && header.subHeaders.length) {
288
+ childRowSpans = [];
289
+ recurseHeadersForSpans(header.subHeaders).forEach(
290
+ ({ colSpan: childColSpan, rowSpan: childRowSpan }) => {
291
+ colSpan += childColSpan;
292
+ childRowSpans.push(childRowSpan);
293
+ }
294
+ );
295
+ } else {
296
+ colSpan = 1;
297
+ }
298
+ const minChildRowSpan = Math.min(...childRowSpans);
299
+ rowSpan = rowSpan + minChildRowSpan;
300
+ header.colSpan = colSpan;
301
+ header.rowSpan = rowSpan;
302
+ return { colSpan, rowSpan };
303
+ });
304
+ };
305
+ recurseHeadersForSpans(((_a = headerGroups[0]) == null ? void 0 : _a.headers) ?? []);
306
+ return headerGroups;
307
+ }
308
+ exports.Headers = Headers;
309
+ exports.buildHeaderGroups = buildHeaderGroups;
310
+ //# sourceMappingURL=headers.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"headers.cjs","sources":["../../../src/core/headers.ts"],"sourcesContent":["import {\n RowData,\n Column,\n Header,\n HeaderGroup,\n Table,\n TableFeature,\n} from '../types'\nimport { getMemoOptions, memo } from '../utils'\n\nconst debug = 'debugHeaders'\n\nexport interface CoreHeaderGroup<TData extends RowData> {\n depth: number\n headers: Header<TData, unknown>[]\n id: string\n}\n\nexport interface HeaderContext<TData, TValue> {\n /**\n * An instance of a column.\n */\n column: Column<TData, TValue>\n /**\n * An instance of a header.\n */\n header: Header<TData, TValue>\n /**\n * The table instance.\n */\n table: Table<TData>\n}\n\nexport interface CoreHeader<TData extends RowData, TValue> {\n /**\n * The col-span for the header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#colspan)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n colSpan: number\n /**\n * The header's associated column object.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#column)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n column: Column<TData, TValue>\n /**\n * The depth of the header, zero-indexed based.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#depth)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n depth: number\n /**\n * Returns the rendering context (or props) for column-based components like headers, footers and filters.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#getcontext)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getContext: () => HeaderContext<TData, TValue>\n /**\n * Returns the leaf headers hierarchically nested under this header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#getleafheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getLeafHeaders: () => Header<TData, unknown>[]\n /**\n * The header's associated header group object.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#headergroup)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n headerGroup: HeaderGroup<TData>\n /**\n * The unique identifier for the header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#id)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n id: string\n /**\n * The index for the header within the header group.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#index)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n index: number\n /**\n * A boolean denoting if the header is a placeholder header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#isplaceholder)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n isPlaceholder: boolean\n /**\n * If the header is a placeholder header, this will be a unique header ID that does not conflict with any other headers across the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#placeholderid)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n placeholderId?: string\n /**\n * The row-span for the header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#rowspan)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n rowSpan: number\n /**\n * The header's hierarchical sub/child headers. Will be empty if the header's associated column is a leaf-column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#subheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n subHeaders: Header<TData, TValue>[]\n}\n\nexport interface HeadersInstance<TData extends RowData> {\n /**\n * Returns all header groups for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getheadergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getHeaderGroups: () => HeaderGroup<TData>[]\n /**\n * If pinning, returns the header groups for the left pinned columns.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftheadergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getLeftHeaderGroups: () => HeaderGroup<TData>[]\n /**\n * If pinning, returns the header groups for columns that are not pinned.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterheadergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getCenterHeaderGroups: () => HeaderGroup<TData>[]\n /**\n * If pinning, returns the header groups for the right pinned columns.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightheadergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getRightHeaderGroups: () => HeaderGroup<TData>[]\n\n /**\n * Returns the footer groups for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getfootergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getFooterGroups: () => HeaderGroup<TData>[]\n /**\n * If pinning, returns the footer groups for the left pinned columns.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftfootergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getLeftFooterGroups: () => HeaderGroup<TData>[]\n /**\n * If pinning, returns the footer groups for columns that are not pinned.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterfootergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getCenterFooterGroups: () => HeaderGroup<TData>[]\n /**\n * If pinning, returns the footer groups for the right pinned columns.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightfootergroups)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getRightFooterGroups: () => HeaderGroup<TData>[]\n\n /**\n * Returns headers for all columns in the table, including parent headers.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getflatheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getFlatHeaders: () => Header<TData, unknown>[]\n /**\n * If pinning, returns headers for all left pinned columns in the table, including parent headers.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftflatheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getLeftFlatHeaders: () => Header<TData, unknown>[]\n /**\n * If pinning, returns headers for all columns that are not pinned, including parent headers.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterflatheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getCenterFlatHeaders: () => Header<TData, unknown>[]\n /**\n * If pinning, returns headers for all right pinned columns in the table, including parent headers.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightflatheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getRightFlatHeaders: () => Header<TData, unknown>[]\n\n /**\n * Returns headers for all leaf columns in the table, (not including parent headers).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleafheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getLeafHeaders: () => Header<TData, unknown>[]\n /**\n * If pinning, returns headers for all left pinned leaf columns in the table, (not including parent headers).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftleafheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getLeftLeafHeaders: () => Header<TData, unknown>[]\n /**\n * If pinning, returns headers for all columns that are not pinned, (not including parent headers).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterleafheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getCenterLeafHeaders: () => Header<TData, unknown>[]\n /**\n * If pinning, returns headers for all right pinned leaf columns in the table, (not including parent headers).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightleafheaders)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)\n */\n getRightLeafHeaders: () => Header<TData, unknown>[]\n}\n\n//\n\nfunction createHeader<TData extends RowData, TValue>(\n table: Table<TData>,\n column: Column<TData, TValue>,\n options: {\n id?: string\n isPlaceholder?: boolean\n placeholderId?: string\n index: number\n depth: number\n }\n): Header<TData, TValue> {\n const id = options.id ?? column.id\n\n let header: CoreHeader<TData, TValue> = {\n id,\n column,\n index: options.index,\n isPlaceholder: !!options.isPlaceholder,\n placeholderId: options.placeholderId,\n depth: options.depth,\n subHeaders: [],\n colSpan: 0,\n rowSpan: 0,\n headerGroup: null!,\n getLeafHeaders: (): Header<TData, unknown>[] => {\n const leafHeaders: Header<TData, unknown>[] = []\n\n const recurseHeader = (h: CoreHeader<TData, any>) => {\n if (h.subHeaders && h.subHeaders.length) {\n h.subHeaders.map(recurseHeader)\n }\n leafHeaders.push(h as Header<TData, unknown>)\n }\n\n recurseHeader(header)\n\n return leafHeaders\n },\n getContext: () => ({\n table,\n header: header as Header<TData, TValue>,\n column,\n }),\n }\n\n table._features.forEach(feature => {\n feature.createHeader?.(header as Header<TData, TValue>, table)\n })\n\n return header as Header<TData, TValue>\n}\n\nexport const Headers: TableFeature = {\n createTable: <TData extends RowData>(table: Table<TData>): void => {\n // Header Groups\n\n table.getHeaderGroups = memo(\n () => [\n table.getAllColumns(),\n table.getVisibleLeafColumns(),\n table.getState().columnPinning.left,\n table.getState().columnPinning.right,\n ],\n (allColumns, leafColumns, left, right) => {\n const leftColumns =\n left\n ?.map(columnId => leafColumns.find(d => d.id === columnId)!)\n .filter(Boolean) ?? []\n\n const rightColumns =\n right\n ?.map(columnId => leafColumns.find(d => d.id === columnId)!)\n .filter(Boolean) ?? []\n\n const centerColumns = leafColumns.filter(\n column => !left?.includes(column.id) && !right?.includes(column.id)\n )\n\n const headerGroups = buildHeaderGroups(\n allColumns,\n [...leftColumns, ...centerColumns, ...rightColumns],\n table\n )\n\n return headerGroups\n },\n getMemoOptions(table.options, debug, 'getHeaderGroups')\n )\n\n table.getCenterHeaderGroups = memo(\n () => [\n table.getAllColumns(),\n table.getVisibleLeafColumns(),\n table.getState().columnPinning.left,\n table.getState().columnPinning.right,\n ],\n (allColumns, leafColumns, left, right) => {\n leafColumns = leafColumns.filter(\n column => !left?.includes(column.id) && !right?.includes(column.id)\n )\n return buildHeaderGroups(allColumns, leafColumns, table, 'center')\n },\n getMemoOptions(table.options, debug, 'getCenterHeaderGroups')\n )\n\n table.getLeftHeaderGroups = memo(\n () => [\n table.getAllColumns(),\n table.getVisibleLeafColumns(),\n table.getState().columnPinning.left,\n ],\n (allColumns, leafColumns, left) => {\n const orderedLeafColumns =\n left\n ?.map(columnId => leafColumns.find(d => d.id === columnId)!)\n .filter(Boolean) ?? []\n\n return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left')\n },\n getMemoOptions(table.options, debug, 'getLeftHeaderGroups')\n )\n\n table.getRightHeaderGroups = memo(\n () => [\n table.getAllColumns(),\n table.getVisibleLeafColumns(),\n table.getState().columnPinning.right,\n ],\n (allColumns, leafColumns, right) => {\n const orderedLeafColumns =\n right\n ?.map(columnId => leafColumns.find(d => d.id === columnId)!)\n .filter(Boolean) ?? []\n\n return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right')\n },\n getMemoOptions(table.options, debug, 'getRightHeaderGroups')\n )\n\n // Footer Groups\n\n table.getFooterGroups = memo(\n () => [table.getHeaderGroups()],\n headerGroups => {\n return [...headerGroups].reverse()\n },\n getMemoOptions(table.options, debug, 'getFooterGroups')\n )\n\n table.getLeftFooterGroups = memo(\n () => [table.getLeftHeaderGroups()],\n headerGroups => {\n return [...headerGroups].reverse()\n },\n getMemoOptions(table.options, debug, 'getLeftFooterGroups')\n )\n\n table.getCenterFooterGroups = memo(\n () => [table.getCenterHeaderGroups()],\n headerGroups => {\n return [...headerGroups].reverse()\n },\n getMemoOptions(table.options, debug, 'getCenterFooterGroups')\n )\n\n table.getRightFooterGroups = memo(\n () => [table.getRightHeaderGroups()],\n headerGroups => {\n return [...headerGroups].reverse()\n },\n getMemoOptions(table.options, debug, 'getRightFooterGroups')\n )\n\n // Flat Headers\n\n table.getFlatHeaders = memo(\n () => [table.getHeaderGroups()],\n headerGroups => {\n return headerGroups\n .map(headerGroup => {\n return headerGroup.headers\n })\n .flat()\n },\n getMemoOptions(table.options, debug, 'getFlatHeaders')\n )\n\n table.getLeftFlatHeaders = memo(\n () => [table.getLeftHeaderGroups()],\n left => {\n return left\n .map(headerGroup => {\n return headerGroup.headers\n })\n .flat()\n },\n getMemoOptions(table.options, debug, 'getLeftFlatHeaders')\n )\n\n table.getCenterFlatHeaders = memo(\n () => [table.getCenterHeaderGroups()],\n left => {\n return left\n .map(headerGroup => {\n return headerGroup.headers\n })\n .flat()\n },\n getMemoOptions(table.options, debug, 'getCenterFlatHeaders')\n )\n\n table.getRightFlatHeaders = memo(\n () => [table.getRightHeaderGroups()],\n left => {\n return left\n .map(headerGroup => {\n return headerGroup.headers\n })\n .flat()\n },\n getMemoOptions(table.options, debug, 'getRightFlatHeaders')\n )\n\n // Leaf Headers\n\n table.getCenterLeafHeaders = memo(\n () => [table.getCenterFlatHeaders()],\n flatHeaders => {\n return flatHeaders.filter(header => !header.subHeaders?.length)\n },\n getMemoOptions(table.options, debug, 'getCenterLeafHeaders')\n )\n\n table.getLeftLeafHeaders = memo(\n () => [table.getLeftFlatHeaders()],\n flatHeaders => {\n return flatHeaders.filter(header => !header.subHeaders?.length)\n },\n getMemoOptions(table.options, debug, 'getLeftLeafHeaders')\n )\n\n table.getRightLeafHeaders = memo(\n () => [table.getRightFlatHeaders()],\n flatHeaders => {\n return flatHeaders.filter(header => !header.subHeaders?.length)\n },\n getMemoOptions(table.options, debug, 'getRightLeafHeaders')\n )\n\n table.getLeafHeaders = memo(\n () => [\n table.getLeftHeaderGroups(),\n table.getCenterHeaderGroups(),\n table.getRightHeaderGroups(),\n ],\n (left, center, right) => {\n return [\n ...(left[0]?.headers ?? []),\n ...(center[0]?.headers ?? []),\n ...(right[0]?.headers ?? []),\n ]\n .map(header => {\n return header.getLeafHeaders()\n })\n .flat()\n },\n getMemoOptions(table.options, debug, 'getLeafHeaders')\n )\n },\n}\n\nexport function buildHeaderGroups<TData extends RowData>(\n allColumns: Column<TData, unknown>[],\n columnsToGroup: Column<TData, unknown>[],\n table: Table<TData>,\n headerFamily?: 'center' | 'left' | 'right'\n) {\n // Find the max depth of the columns:\n // build the leaf column row\n // build each buffer row going up\n // placeholder for non-existent level\n // real column for existing level\n\n let maxDepth = 0\n\n const findMaxDepth = (columns: Column<TData, unknown>[], depth = 1) => {\n maxDepth = Math.max(maxDepth, depth)\n\n columns\n .filter(column => column.getIsVisible())\n .forEach(column => {\n if (column.columns?.length) {\n findMaxDepth(column.columns, depth + 1)\n }\n }, 0)\n }\n\n findMaxDepth(allColumns)\n\n let headerGroups: HeaderGroup<TData>[] = []\n\n const createHeaderGroup = (\n headersToGroup: Header<TData, unknown>[],\n depth: number\n ) => {\n // The header group we are creating\n const headerGroup: HeaderGroup<TData> = {\n depth,\n id: [headerFamily, `${depth}`].filter(Boolean).join('_'),\n headers: [],\n }\n\n // The parent columns we're going to scan next\n const pendingParentHeaders: Header<TData, unknown>[] = []\n\n // Scan each column for parents\n headersToGroup.forEach(headerToGroup => {\n // What is the latest (last) parent column?\n\n const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0]\n\n const isLeafHeader = headerToGroup.column.depth === headerGroup.depth\n\n let column: Column<TData, unknown>\n let isPlaceholder = false\n\n if (isLeafHeader && headerToGroup.column.parent) {\n // The parent header is new\n column = headerToGroup.column.parent\n } else {\n // The parent header is repeated\n column = headerToGroup.column\n isPlaceholder = true\n }\n\n if (\n latestPendingParentHeader &&\n latestPendingParentHeader?.column === column\n ) {\n // This column is repeated. Add it as a sub header to the next batch\n latestPendingParentHeader.subHeaders.push(headerToGroup)\n } else {\n // This is a new header. Let's create it\n const header = createHeader(table, column, {\n id: [headerFamily, depth, column.id, headerToGroup?.id]\n .filter(Boolean)\n .join('_'),\n isPlaceholder,\n placeholderId: isPlaceholder\n ? `${pendingParentHeaders.filter(d => d.column === column).length}`\n : undefined,\n depth,\n index: pendingParentHeaders.length,\n })\n\n // Add the headerToGroup as a subHeader of the new header\n header.subHeaders.push(headerToGroup)\n // Add the new header to the pendingParentHeaders to get grouped\n // in the next batch\n pendingParentHeaders.push(header)\n }\n\n headerGroup.headers.push(headerToGroup)\n headerToGroup.headerGroup = headerGroup\n })\n\n headerGroups.push(headerGroup)\n\n if (depth > 0) {\n createHeaderGroup(pendingParentHeaders, depth - 1)\n }\n }\n\n const bottomHeaders = columnsToGroup.map((column, index) =>\n createHeader(table, column, {\n depth: maxDepth,\n index,\n })\n )\n\n createHeaderGroup(bottomHeaders, maxDepth - 1)\n\n headerGroups.reverse()\n\n // headerGroups = headerGroups.filter(headerGroup => {\n // return !headerGroup.headers.every(header => header.isPlaceholder)\n // })\n\n const recurseHeadersForSpans = (\n headers: Header<TData, unknown>[]\n ): { colSpan: number; rowSpan: number }[] => {\n const filteredHeaders = headers.filter(header =>\n header.column.getIsVisible()\n )\n\n return filteredHeaders.map(header => {\n let colSpan = 0\n let rowSpan = 0\n let childRowSpans = [0]\n\n if (header.subHeaders && header.subHeaders.length) {\n childRowSpans = []\n\n recurseHeadersForSpans(header.subHeaders).forEach(\n ({ colSpan: childColSpan, rowSpan: childRowSpan }) => {\n colSpan += childColSpan\n childRowSpans.push(childRowSpan)\n }\n )\n } else {\n colSpan = 1\n }\n\n const minChildRowSpan = Math.min(...childRowSpans)\n rowSpan = rowSpan + minChildRowSpan\n\n header.colSpan = colSpan\n header.rowSpan = rowSpan\n\n return { colSpan, rowSpan }\n })\n }\n\n recurseHeadersForSpans(headerGroups[0]?.headers ?? [])\n\n return headerGroups\n}\n"],"names":["memo","getMemoOptions","_a"],"mappings":";;;AAUA,MAAM,QAAQ;AA0Md,SAAS,aACP,OACA,QACA,SAOuB;AACjB,QAAA,KAAK,QAAQ,MAAM,OAAO;AAEhC,MAAI,SAAoC;AAAA,IACtC;AAAA,IACA;AAAA,IACA,OAAO,QAAQ;AAAA,IACf,eAAe,CAAC,CAAC,QAAQ;AAAA,IACzB,eAAe,QAAQ;AAAA,IACvB,OAAO,QAAQ;AAAA,IACf,YAAY,CAAC;AAAA,IACb,SAAS;AAAA,IACT,SAAS;AAAA,IACT,aAAa;AAAA,IACb,gBAAgB,MAAgC;AAC9C,YAAM,cAAwC,CAAA;AAExC,YAAA,gBAAgB,CAAC,MAA8B;AACnD,YAAI,EAAE,cAAc,EAAE,WAAW,QAAQ;AACrC,YAAA,WAAW,IAAI,aAAa;AAAA,QAChC;AACA,oBAAY,KAAK,CAA2B;AAAA,MAAA;AAG9C,oBAAc,MAAM;AAEb,aAAA;AAAA,IACT;AAAA,IACA,YAAY,OAAO;AAAA,MACjB;AAAA,MACA;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAGI,QAAA,UAAU,QAAQ,CAAW,YAAA;;AACzB,kBAAA,iBAAA,iCAAe,QAAiC;AAAA,EAAK,CAC9D;AAEM,SAAA;AACT;AAEO,MAAM,UAAwB;AAAA,EACnC,aAAa,CAAwB,UAA8B;AAGjE,UAAM,kBAAkBA,MAAA;AAAA,MACtB,MAAM;AAAA,QACJ,MAAM,cAAc;AAAA,QACpB,MAAM,sBAAsB;AAAA,QAC5B,MAAM,WAAW,cAAc;AAAA,QAC/B,MAAM,WAAW,cAAc;AAAA,MACjC;AAAA,MACA,CAAC,YAAY,aAAa,MAAM,UA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interface CoreHeaderGroup<TData extends RowData> {
4
+ depth: number;
5
+ headers: Header<TData, unknown>[];
6
+ id: string;
7
+ }
8
+ export interface HeaderContext<TData, TValue> {
9
+ /**
10
+ * An instance of a column.
11
+ */
12
+ column: Column<TData, TValue>;
13
+ /**
14
+ * An instance of a header.
15
+ */
16
+ header: Header<TData, TValue>;
17
+ /**
18
+ * The table instance.
19
+ */
20
+ table: Table<TData>;
21
+ }
22
+ export interface CoreHeader<TData extends RowData, TValue> {
23
+ /**
24
+ * The col-span for the header.
25
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#colspan)
26
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
27
+ */
28
+ colSpan: number;
29
+ /**
30
+ * The header's associated column object.
31
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#column)
32
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
33
+ */
34
+ column: Column<TData, TValue>;
35
+ /**
36
+ * The depth of the header, zero-indexed based.
37
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#depth)
38
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
39
+ */
40
+ depth: number;
41
+ /**
42
+ * Returns the rendering context (or props) for column-based components like headers, footers and filters.
43
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#getcontext)
44
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
45
+ */
46
+ getContext: () => HeaderContext<TData, TValue>;
47
+ /**
48
+ * Returns the leaf headers hierarchically nested under this header.
49
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#getleafheaders)
50
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
51
+ */
52
+ getLeafHeaders: () => Header<TData, unknown>[];
53
+ /**
54
+ * The header's associated header group object.
55
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#headergroup)
56
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
57
+ */
58
+ headerGroup: HeaderGroup<TData>;
59
+ /**
60
+ * The unique identifier for the header.
61
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#id)
62
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
63
+ */
64
+ id: string;
65
+ /**
66
+ * The index for the header within the header group.
67
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#index)
68
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
69
+ */
70
+ index: number;
71
+ /**
72
+ * A boolean denoting if the header is a placeholder header.
73
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#isplaceholder)
74
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
75
+ */
76
+ isPlaceholder: boolean;
77
+ /**
78
+ * If the header is a placeholder header, this will be a unique header ID that does not conflict with any other headers across the table.
79
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#placeholderid)
80
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
81
+ */
82
+ placeholderId?: string;
83
+ /**
84
+ * The row-span for the header.
85
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#rowspan)
86
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
87
+ */
88
+ rowSpan: number;
89
+ /**
90
+ * The header's hierarchical sub/child headers. Will be empty if the header's associated column is a leaf-column.
91
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/header#subheaders)
92
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
93
+ */
94
+ subHeaders: Header<TData, TValue>[];
95
+ }
96
+ export interface HeadersInstance<TData extends RowData> {
97
+ /**
98
+ * Returns all header groups for the table.
99
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getheadergroups)
100
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
101
+ */
102
+ getHeaderGroups: () => HeaderGroup<TData>[];
103
+ /**
104
+ * If pinning, returns the header groups for the left pinned columns.
105
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftheadergroups)
106
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
107
+ */
108
+ getLeftHeaderGroups: () => HeaderGroup<TData>[];
109
+ /**
110
+ * If pinning, returns the header groups for columns that are not pinned.
111
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterheadergroups)
112
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
113
+ */
114
+ getCenterHeaderGroups: () => HeaderGroup<TData>[];
115
+ /**
116
+ * If pinning, returns the header groups for the right pinned columns.
117
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightheadergroups)
118
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
119
+ */
120
+ getRightHeaderGroups: () => HeaderGroup<TData>[];
121
+ /**
122
+ * Returns the footer groups for the table.
123
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getfootergroups)
124
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
125
+ */
126
+ getFooterGroups: () => HeaderGroup<TData>[];
127
+ /**
128
+ * If pinning, returns the footer groups for the left pinned columns.
129
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftfootergroups)
130
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
131
+ */
132
+ getLeftFooterGroups: () => HeaderGroup<TData>[];
133
+ /**
134
+ * If pinning, returns the footer groups for columns that are not pinned.
135
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterfootergroups)
136
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
137
+ */
138
+ getCenterFooterGroups: () => HeaderGroup<TData>[];
139
+ /**
140
+ * If pinning, returns the footer groups for the right pinned columns.
141
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightfootergroups)
142
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
143
+ */
144
+ getRightFooterGroups: () => HeaderGroup<TData>[];
145
+ /**
146
+ * Returns headers for all columns in the table, including parent headers.
147
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getflatheaders)
148
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
149
+ */
150
+ getFlatHeaders: () => Header<TData, unknown>[];
151
+ /**
152
+ * If pinning, returns headers for all left pinned columns in the table, including parent headers.
153
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftflatheaders)
154
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
155
+ */
156
+ getLeftFlatHeaders: () => Header<TData, unknown>[];
157
+ /**
158
+ * If pinning, returns headers for all columns that are not pinned, including parent headers.
159
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterflatheaders)
160
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
161
+ */
162
+ getCenterFlatHeaders: () => Header<TData, unknown>[];
163
+ /**
164
+ * If pinning, returns headers for all right pinned columns in the table, including parent headers.
165
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightflatheaders)
166
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
167
+ */
168
+ getRightFlatHeaders: () => Header<TData, unknown>[];
169
+ /**
170
+ * Returns headers for all leaf columns in the table, (not including parent headers).
171
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleafheaders)
172
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
173
+ */
174
+ getLeafHeaders: () => Header<TData, unknown>[];
175
+ /**
176
+ * If pinning, returns headers for all left pinned leaf columns in the table, (not including parent headers).
177
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getleftleafheaders)
178
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
179
+ */
180
+ getLeftLeafHeaders: () => Header<TData, unknown>[];
181
+ /**
182
+ * If pinning, returns headers for all columns that are not pinned, (not including parent headers).
183
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getcenterleafheaders)
184
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
185
+ */
186
+ getCenterLeafHeaders: () => Header<TData, unknown>[];
187
+ /**
188
+ * If pinning, returns headers for all right pinned leaf columns in the table, (not including parent headers).
189
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/core/headers#getrightleafheaders)
190
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/headers)
191
+ */
192
+ getRightLeafHeaders: () => Header<TData, unknown>[];
193
+ }
194
+ export declare const Headers: TableFeature;
195
+ export declare function buildHeaderGroups<TData extends RowData>(allColumns: Column<TData, unknown>[], columnsToGroup: Column<TData, unknown>[], table: Table<TData>, headerFamily?: 'center' | 'left' | 'right'): HeaderGroup<TData>[];
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const utils = require("../utils.cjs");
4
+ const cell = require("./cell.cjs");
5
+ const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
6
+ var _a;
7
+ let row = {
8
+ id,
9
+ index: rowIndex,
10
+ original,
11
+ depth,
12
+ parentId,
13
+ _valuesCache: {},
14
+ _uniqueValuesCache: {},
15
+ getValue: (columnId) => {
16
+ if (row._valuesCache.hasOwnProperty(columnId)) {
17
+ return row._valuesCache[columnId];
18
+ }
19
+ const column = table.getColumn(columnId);
20
+ if (!(column == null ? void 0 : column.accessorFn)) {
21
+ return void 0;
22
+ }
23
+ row._valuesCache[columnId] = column.accessorFn(
24
+ row.original,
25
+ rowIndex
26
+ );
27
+ return row._valuesCache[columnId];
28
+ },
29
+ getUniqueValues: (columnId) => {
30
+ if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
31
+ return row._uniqueValuesCache[columnId];
32
+ }
33
+ const column = table.getColumn(columnId);
34
+ if (!(column == null ? void 0 : column.accessorFn)) {
35
+ return void 0;
36
+ }
37
+ if (!column.columnDef.getUniqueValues) {
38
+ row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
39
+ return row._uniqueValuesCache[columnId];
40
+ }
41
+ row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(
42
+ row.original,
43
+ rowIndex
44
+ );
45
+ return row._uniqueValuesCache[columnId];
46
+ },
47
+ renderValue: (columnId) => row.getValue(columnId) ?? table.options.renderFallbackValue,
48
+ subRows: subRows ?? [],
49
+ getLeafRows: () => utils.flattenBy(row.subRows, (d) => d.subRows),
50
+ getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : void 0,
51
+ getParentRows: () => {
52
+ let parentRows = [];
53
+ let currentRow = row;
54
+ while (true) {
55
+ const parentRow = currentRow.getParentRow();
56
+ if (!parentRow)
57
+ break;
58
+ parentRows.push(parentRow);
59
+ currentRow = parentRow;
60
+ }
61
+ return parentRows.reverse();
62
+ },
63
+ getAllCells: utils.memo(
64
+ () => [table.getAllLeafColumns()],
65
+ (leafColumns) => {
66
+ return leafColumns.map((column) => {
67
+ return cell.createCell(table, row, column, column.id);
68
+ });
69
+ },
70
+ utils.getMemoOptions(table.options, "debugRows", "getAllCells")
71
+ ),
72
+ _getAllCellsByColumnId: utils.memo(
73
+ () => [row.getAllCells()],
74
+ (allCells) => {
75
+ return allCells.reduce(
76
+ (acc, cell2) => {
77
+ acc[cell2.column.id] = cell2;
78
+ return acc;
79
+ },
80
+ {}
81
+ );
82
+ },
83
+ utils.getMemoOptions(table.options, "debugRows", "getAllCellsByColumnId")
84
+ )
85
+ };
86
+ for (let i = 0; i < table._features.length; i++) {
87
+ const feature = table._features[i];
88
+ (_a = feature == null ? void 0 : feature.createRow) == null ? void 0 : _a.call(feature, row, table);
89
+ }
90
+ return row;
91
+ };
92
+ exports.createRow = createRow;
93
+ //# sourceMappingURL=row.cjs.map