@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,133 @@
1
+ import { makeStateUpdater, memo, getMemoOptions } from "../utils.js";
2
+ const getDefaultRowPinningState = () => ({
3
+ top: [],
4
+ bottom: []
5
+ });
6
+ const RowPinning = {
7
+ getInitialState: (state) => {
8
+ return {
9
+ rowPinning: getDefaultRowPinningState(),
10
+ ...state
11
+ };
12
+ },
13
+ getDefaultOptions: (table) => {
14
+ return {
15
+ onRowPinningChange: makeStateUpdater("rowPinning", table)
16
+ };
17
+ },
18
+ createRow: (row, table) => {
19
+ row.pin = (position, includeLeafRows, includeParentRows) => {
20
+ const leafRowIds = includeLeafRows ? row.getLeafRows().map(({ id }) => id) : [];
21
+ const parentRowIds = includeParentRows ? row.getParentRows().map(({ id }) => id) : [];
22
+ const rowIds = /* @__PURE__ */ new Set([...parentRowIds, row.id, ...leafRowIds]);
23
+ table.setRowPinning((old) => {
24
+ if (position === "bottom") {
25
+ return {
26
+ top: ((old == null ? void 0 : old.top) ?? []).filter((d) => !(rowIds == null ? void 0 : rowIds.has(d))),
27
+ bottom: [
28
+ ...((old == null ? void 0 : old.bottom) ?? []).filter((d) => !(rowIds == null ? void 0 : rowIds.has(d))),
29
+ ...Array.from(rowIds)
30
+ ]
31
+ };
32
+ }
33
+ if (position === "top") {
34
+ return {
35
+ top: [
36
+ ...((old == null ? void 0 : old.top) ?? []).filter((d) => !(rowIds == null ? void 0 : rowIds.has(d))),
37
+ ...Array.from(rowIds)
38
+ ],
39
+ bottom: ((old == null ? void 0 : old.bottom) ?? []).filter((d) => !(rowIds == null ? void 0 : rowIds.has(d)))
40
+ };
41
+ }
42
+ return {
43
+ top: ((old == null ? void 0 : old.top) ?? []).filter((d) => !(rowIds == null ? void 0 : rowIds.has(d))),
44
+ bottom: ((old == null ? void 0 : old.bottom) ?? []).filter((d) => !(rowIds == null ? void 0 : rowIds.has(d)))
45
+ };
46
+ });
47
+ };
48
+ row.getCanPin = () => {
49
+ const { enableRowPinning, enablePinning } = table.options;
50
+ if (typeof enableRowPinning === "function") {
51
+ return enableRowPinning(row);
52
+ }
53
+ return enableRowPinning ?? enablePinning ?? true;
54
+ };
55
+ row.getIsPinned = () => {
56
+ const rowIds = [row.id];
57
+ const { top, bottom } = table.getState().rowPinning;
58
+ const isTop = rowIds.some((d) => top == null ? void 0 : top.includes(d));
59
+ const isBottom = rowIds.some((d) => bottom == null ? void 0 : bottom.includes(d));
60
+ return isTop ? "top" : isBottom ? "bottom" : false;
61
+ };
62
+ row.getPinnedIndex = () => {
63
+ var _a;
64
+ const position = row.getIsPinned();
65
+ if (!position)
66
+ return -1;
67
+ const visiblePinnedRowIds = (_a = table._getPinnedRows(position)) == null ? void 0 : _a.map(({ id }) => id);
68
+ return (visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) ?? -1;
69
+ };
70
+ },
71
+ createTable: (table) => {
72
+ table.setRowPinning = (updater) => {
73
+ var _a, _b;
74
+ return (_b = (_a = table.options).onRowPinningChange) == null ? void 0 : _b.call(_a, updater);
75
+ };
76
+ table.resetRowPinning = (defaultState) => {
77
+ var _a;
78
+ return table.setRowPinning(
79
+ defaultState ? getDefaultRowPinningState() : ((_a = table.initialState) == null ? void 0 : _a.rowPinning) ?? getDefaultRowPinningState()
80
+ );
81
+ };
82
+ table.getIsSomeRowsPinned = (position) => {
83
+ var _a, _b, _c;
84
+ const pinningState = table.getState().rowPinning;
85
+ if (!position) {
86
+ return Boolean(((_a = pinningState.top) == null ? void 0 : _a.length) || ((_b = pinningState.bottom) == null ? void 0 : _b.length));
87
+ }
88
+ return Boolean((_c = pinningState[position]) == null ? void 0 : _c.length);
89
+ };
90
+ table._getPinnedRows = memo(
91
+ (position) => [
92
+ table.getRowModel().rows,
93
+ table.getState().rowPinning[position],
94
+ position
95
+ ],
96
+ (visibleRows, pinnedRowIds, position) => {
97
+ const rows = table.options.keepPinnedRows ?? true ? (
98
+ //get all rows that are pinned even if they would not be otherwise visible
99
+ //account for expanded parent rows, but not pagination or filtering
100
+ (pinnedRowIds ?? []).map((rowId) => {
101
+ const row = table.getRow(rowId, true);
102
+ return row.getIsAllParentsExpanded() ? row : null;
103
+ })
104
+ ) : (
105
+ //else get only visible rows that are pinned
106
+ (pinnedRowIds ?? []).map(
107
+ (rowId) => visibleRows.find((row) => row.id === rowId)
108
+ )
109
+ );
110
+ return rows.filter(Boolean).map((d) => ({ ...d, position }));
111
+ },
112
+ getMemoOptions(table.options, "debugRows", "_getPinnedRows")
113
+ );
114
+ table.getTopRows = () => table._getPinnedRows("top");
115
+ table.getBottomRows = () => table._getPinnedRows("bottom");
116
+ table.getCenterRows = memo(
117
+ () => [
118
+ table.getRowModel().rows,
119
+ table.getState().rowPinning.top,
120
+ table.getState().rowPinning.bottom
121
+ ],
122
+ (allRows, top, bottom) => {
123
+ const topAndBottom = /* @__PURE__ */ new Set([...top ?? [], ...bottom ?? []]);
124
+ return allRows.filter((d) => !topAndBottom.has(d.id));
125
+ },
126
+ getMemoOptions(table.options, "debugRows", "getCenterRows")
127
+ );
128
+ }
129
+ };
130
+ export {
131
+ RowPinning
132
+ };
133
+ //# sourceMappingURL=RowPinning.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"RowPinning.js","sources":["../../../src/features/RowPinning.ts"],"sourcesContent":["import {\n OnChangeFn,\n Updater,\n Table,\n Row,\n RowData,\n TableFeature,\n} from '../types'\nimport { getMemoOptions, makeStateUpdater, memo } from '../utils'\n\nexport type RowPinningPosition = false | 'top' | 'bottom'\n\nexport interface RowPinningState {\n bottom?: string[]\n top?: string[]\n}\n\nexport interface RowPinningTableState {\n rowPinning: RowPinningState\n}\n\nexport interface RowPinningOptions<TData extends RowData> {\n /**\n * Enables/disables row pinning for the table. Defaults to `true`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#enablerowpinning)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n enableRowPinning?: boolean | ((row: Row<TData>) => boolean)\n /**\n * When `false`, pinned rows will not be visible if they are filtered or paginated out of the table. When `true`, pinned rows will always be visible regardless of filtering or pagination. Defaults to `true`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#keeppinnedrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n keepPinnedRows?: boolean\n /**\n * If provided, this function will be called with an `updaterFn` when `state.rowPinning` changes. This overrides the default internal state management, so you will also need to supply `state.rowPinning` from your own managed state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#onrowpinningchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/onrowpinningchange)\n */\n onRowPinningChange?: OnChangeFn<RowPinningState>\n}\n\nexport interface RowPinningDefaultOptions {\n onRowPinningChange: OnChangeFn<RowPinningState>\n}\n\nexport interface RowPinningRow {\n /**\n * Returns whether or not the row can be pinned.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getcanpin-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getCanPin: () => boolean\n /**\n * Returns the pinned position of the row. (`'top'`, `'bottom'` or `false`)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getispinned-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getIsPinned: () => RowPinningPosition\n /**\n * Returns the numeric pinned index of the row within a pinned row group.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getpinnedindex-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getPinnedIndex: () => number\n /**\n * Pins a row to the `'top'` or `'bottom'`, or unpins the row to the center if `false` is passed.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#pin-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n pin: (\n position: RowPinningPosition,\n includeLeafRows?: boolean,\n includeParentRows?: boolean\n ) => void\n}\n\nexport interface RowPinningInstance<TData extends RowData> {\n _getPinnedRows: (position: 'top' | 'bottom') => Row<TData>[]\n /**\n * Returns all bottom pinned rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getbottomrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getBottomRows: () => Row<TData>[]\n /**\n * Returns all rows that are not pinned to the top or bottom.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getcenterrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getCenterRows: () => Row<TData>[]\n /**\n * Returns whether or not any rows are pinned. Optionally specify to only check for pinned rows in either the `top` or `bottom` position.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getissomerowspinned)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getIsSomeRowsPinned: (position?: RowPinningPosition) => boolean\n /**\n * Returns all top pinned rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#gettoprows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getTopRows: () => Row<TData>[]\n /**\n * Resets the **rowPinning** state to `initialState.rowPinning`, or `true` can be passed to force a default blank state reset to `{ top: [], bottom: [], }`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#resetrowpinning)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n resetRowPinning: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.rowPinning` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#setrowpinning)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n setRowPinning: (updater: Updater<RowPinningState>) => void\n}\n\n//\n\nconst getDefaultRowPinningState = (): RowPinningState => ({\n top: [],\n bottom: [],\n})\n\nexport const RowPinning: TableFeature = {\n getInitialState: (state): RowPinningTableState => {\n return {\n rowPinning: getDefaultRowPinningState(),\n ...state,\n }\n },\n\n getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): RowPinningDefaultOptions => {\n return {\n onRowPinningChange: makeStateUpdater('rowPinning', table),\n }\n },\n\n createRow: <TData extends RowData>(\n row: Row<TData>,\n table: Table<TData>\n ): void => {\n row.pin = (position, includeLeafRows, includeParentRows) => {\n const leafRowIds = includeLeafRows\n ? row.getLeafRows().map(({ id }) => id)\n : []\n const parentRowIds = includeParentRows\n ? row.getParentRows().map(({ id }) => id)\n : []\n const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds])\n\n table.setRowPinning(old => {\n if (position === 'bottom') {\n return {\n top: (old?.top ?? []).filter(d => !rowIds?.has(d)),\n bottom: [\n ...(old?.bottom ?? []).filter(d => !rowIds?.has(d)),\n ...Array.from(rowIds),\n ],\n }\n }\n\n if (position === 'top') {\n return {\n top: [\n ...(old?.top ?? []).filter(d => !rowIds?.has(d)),\n ...Array.from(rowIds),\n ],\n bottom: (old?.bottom ?? []).filter(d => !rowIds?.has(d)),\n }\n }\n\n return {\n top: (old?.top ?? []).filter(d => !rowIds?.has(d)),\n bottom: (old?.bottom ?? []).filter(d => !rowIds?.has(d)),\n }\n })\n }\n row.getCanPin = () => {\n const { enableRowPinning, enablePinning } = table.options\n if (typeof enableRowPinning === 'function') {\n return enableRowPinning(row)\n }\n return enableRowPinning ?? enablePinning ?? true\n }\n row.getIsPinned = () => {\n const rowIds = [row.id]\n\n const { top, bottom } = table.getState().rowPinning\n\n const isTop = rowIds.some(d => top?.includes(d))\n const isBottom = rowIds.some(d => bottom?.includes(d))\n\n return isTop ? 'top' : isBottom ? 'bottom' : false\n }\n row.getPinnedIndex = () => {\n const position = row.getIsPinned()\n if (!position) return -1\n\n const visiblePinnedRowIds = table\n ._getPinnedRows(position)\n ?.map(({ id }) => id)\n\n return visiblePinnedRowIds?.indexOf(row.id) ?? -1\n }\n },\n\n createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setRowPinning = updater => table.options.onRowPinningChange?.(updater)\n\n table.resetRowPinning = defaultState =>\n table.setRowPinning(\n defaultState\n ? getDefaultRowPinningState()\n : table.initialState?.rowPinning ?? getDefaultRowPinningState()\n )\n\n table.getIsSomeRowsPinned = position => {\n const pinningState = table.getState().rowPinning\n\n if (!position) {\n return Boolean(pinningState.top?.length || pinningState.bottom?.length)\n }\n return Boolean(pinningState[position]?.length)\n }\n\n table._getPinnedRows = memo(\n position => [\n table.getRowModel().rows,\n table.getState().rowPinning[position!],\n position,\n ],\n (visibleRows, pinnedRowIds, position) => {\n const rows =\n table.options.keepPinnedRows ?? true\n ? //get all rows that are pinned even if they would not be otherwise visible\n //account for expanded parent rows, but not pagination or filtering\n (pinnedRowIds ?? []).map(rowId => {\n const row = table.getRow(rowId, true)\n return row.getIsAllParentsExpanded() ? row : null\n })\n : //else get only visible rows that are pinned\n (pinnedRowIds ?? []).map(\n rowId => visibleRows.find(row => row.id === rowId)!\n )\n\n return rows\n .filter(Boolean)\n .map(d => ({ ...d, position })) as Row<TData>[]\n },\n getMemoOptions(table.options, 'debugRows', '_getPinnedRows')\n )\n\n table.getTopRows = () => table._getPinnedRows('top')\n\n table.getBottomRows = () => table._getPinnedRows('bottom')\n\n table.getCenterRows = memo(\n () => [\n table.getRowModel().rows,\n table.getState().rowPinning.top,\n table.getState().rowPinning.bottom,\n ],\n (allRows, top, bottom) => {\n const topAndBottom = new Set([...(top ?? []), ...(bottom ?? [])])\n return allRows.filter(d => !topAndBottom.has(d.id))\n },\n getMemoOptions(table.options, 'debugRows', 'getCenterRows')\n )\n },\n}\n"],"names":["getDefaultRowPinningState","top","bottom","RowPinning","getInitialState","state","rowPinning","getDefaultOptions","table","onRowPinningChange","makeStateUpdater","createRow","row","pin","position","includeLeafRows","includeParentRows","leafRowIds","getLeafRows","map","_ref","id","parentRowIds","getParentRows","_ref2","rowIds","Set","setRowPinning","old","_old$top3","_old$bottom3","_old$top","_old$bottom","filter","d","has","Array","from","_old$top2","_old$bottom2","getCanPin","_ref3","enableRowPinning","enablePinning","options","getIsPinned","getState","isTop","some","includes","isBottom","getPinnedIndex","_table$_getPinnedRows","_visiblePinnedRowIds$","visiblePinnedRowIds","_getPinnedRows","_ref4","indexOf","createTable","updater","resetRowPinning","defaultState","_table$initialState$r","_table$initialState","initialState","getIsSomeRowsPinned","_pinningState$positio","pinningState","_pinningState$top","_pinningState$bottom","Boolean","length","memo","getRowModel","rows","visibleRows","pinnedRowIds","_table$options$keepPi","keepPinnedRows","rowId","getRow","getIsAllParentsExpanded","find","getMemoOptions","getTopRows","getBottomRows","getCenterRows","allRows","topAndBottom"],"mappings":";;;;;;;;;;;;;;AAqHA;;AAEA,MAAMA,yBAAyB,GAAGA,OAAwB;AACxDC,EAAAA,GAAG,EAAE,EAAE;AACPC,EAAAA,MAAM,EAAE,EAAA;AACV,CAAC,CAAC,CAAA;AAEK,MAAMC,UAAwB,GAAG;EACtCC,eAAe,EAAGC,KAAK,IAA2B;IAChD,OAAO;MACLC,UAAU,EAAEN,yBAAyB,EAAE;MACvC,GAAGK,KAAAA;KACJ,CAAA;GACF;EAEDE,iBAAiB,EACfC,KAAmB,IACU;IAC7B,OAAO;AACLC,MAAAA,kBAAkB,EAAEC,sBAAgB,CAAC,YAAY,EAAEF,KAAK,CAAA;KACzD,CAAA;GACF;AAEDG,EAAAA,SAAS,EAAEA,CACTC,GAAe,EACfJ,KAAmB,KACV;IACTI,GAAG,CAACC,GAAG,GAAG,CAACC,QAAQ,EAAEC,eAAe,EAAEC,iBAAiB,KAAK;AAC1D,MAAA,MAAMC,UAAU,GAAGF,eAAe,GAC9BH,GAAG,CAACM,WAAW,EAAE,CAACC,GAAG,CAACC,IAAA,IAAA;QAAA,IAAC;AAAEC,UAAAA,EAAAA;AAAG,SAAC,GAAAD,IAAA,CAAA;AAAA,QAAA,OAAKC,EAAE,CAAA;AAAA,OAAA,CAAC,GACrC,EAAE,CAAA;AACN,MAAA,MAAMC,YAAY,GAAGN,iBAAiB,GAClCJ,GAAG,CAACW,aAA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,CAACb,EAAE,CAAC,CAAC,CAAA;KACpD,EACD8D,oBAAc,CAAC3E,KAAK,CAACoC,OAAO,EAAE,WAAW,EAAE,eAAe,CAC5D,CAAC,CAAA;AACH,GAAA;AACF;;;;"}
1
+ {"version":3,"file":"RowPinning.js","sources":["../../../src/features/RowPinning.ts"],"sourcesContent":["import {\n OnChangeFn,\n Updater,\n Table,\n Row,\n RowData,\n TableFeature,\n} from '../types'\nimport { getMemoOptions, makeStateUpdater, memo } from '../utils'\n\nexport type RowPinningPosition = false | 'top' | 'bottom'\n\nexport interface RowPinningState {\n bottom?: string[]\n top?: string[]\n}\n\nexport interface RowPinningTableState {\n rowPinning: RowPinningState\n}\n\nexport interface RowPinningOptions<TData extends RowData> {\n /**\n * Enables/disables row pinning for the table. Defaults to `true`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#enablerowpinning)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n enableRowPinning?: boolean | ((row: Row<TData>) => boolean)\n /**\n * When `false`, pinned rows will not be visible if they are filtered or paginated out of the table. When `true`, pinned rows will always be visible regardless of filtering or pagination. Defaults to `true`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#keeppinnedrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n keepPinnedRows?: boolean\n /**\n * If provided, this function will be called with an `updaterFn` when `state.rowPinning` changes. This overrides the default internal state management, so you will also need to supply `state.rowPinning` from your own managed state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#onrowpinningchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/onrowpinningchange)\n */\n onRowPinningChange?: OnChangeFn<RowPinningState>\n}\n\nexport interface RowPinningDefaultOptions {\n onRowPinningChange: OnChangeFn<RowPinningState>\n}\n\nexport interface RowPinningRow {\n /**\n * Returns whether or not the row can be pinned.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getcanpin-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getCanPin: () => boolean\n /**\n * Returns the pinned position of the row. (`'top'`, `'bottom'` or `false`)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getispinned-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getIsPinned: () => RowPinningPosition\n /**\n * Returns the numeric pinned index of the row within a pinned row group.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getpinnedindex-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getPinnedIndex: () => number\n /**\n * Pins a row to the `'top'` or `'bottom'`, or unpins the row to the center if `false` is passed.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#pin-1)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n pin: (\n position: RowPinningPosition,\n includeLeafRows?: boolean,\n includeParentRows?: boolean\n ) => void\n}\n\nexport interface RowPinningInstance<TData extends RowData> {\n _getPinnedRows: (position: 'top' | 'bottom') => Row<TData>[]\n /**\n * Returns all bottom pinned rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getbottomrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getBottomRows: () => Row<TData>[]\n /**\n * Returns all rows that are not pinned to the top or bottom.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getcenterrows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getCenterRows: () => Row<TData>[]\n /**\n * Returns whether or not any rows are pinned. Optionally specify to only check for pinned rows in either the `top` or `bottom` position.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#getissomerowspinned)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getIsSomeRowsPinned: (position?: RowPinningPosition) => boolean\n /**\n * Returns all top pinned rows.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#gettoprows)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n getTopRows: () => Row<TData>[]\n /**\n * Resets the **rowPinning** state to `initialState.rowPinning`, or `true` can be passed to force a default blank state reset to `{ top: [], bottom: [], }`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#resetrowpinning)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n resetRowPinning: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.rowPinning` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/row-pinning#setrowpinning)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/row-pinning)\n */\n setRowPinning: (updater: Updater<RowPinningState>) => void\n}\n\n//\n\nconst getDefaultRowPinningState = (): RowPinningState => ({\n top: [],\n bottom: [],\n})\n\nexport const RowPinning: TableFeature = {\n getInitialState: (state): RowPinningTableState => {\n return {\n rowPinning: getDefaultRowPinningState(),\n ...state,\n }\n },\n\n getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): RowPinningDefaultOptions => {\n return {\n onRowPinningChange: makeStateUpdater('rowPinning', table),\n }\n },\n\n createRow: <TData extends RowData>(\n row: Row<TData>,\n table: Table<TData>\n ): void => {\n row.pin = (position, includeLeafRows, includeParentRows) => {\n const leafRowIds = includeLeafRows\n ? row.getLeafRows().map(({ id }) => id)\n : []\n const parentRowIds = includeParentRows\n ? row.getParentRows().map(({ id }) => id)\n : []\n const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds])\n\n table.setRowPinning(old => {\n if (position === 'bottom') {\n return {\n top: (old?.top ?? []).filter(d => !rowIds?.has(d)),\n bottom: [\n ...(old?.bottom ?? []).filter(d => !rowIds?.has(d)),\n ...Array.from(rowIds),\n ],\n }\n }\n\n if (position === 'top') {\n return {\n top: [\n ...(old?.top ?? []).filter(d => !rowIds?.has(d)),\n ...Array.from(rowIds),\n ],\n bottom: (old?.bottom ?? []).filter(d => !rowIds?.has(d)),\n }\n }\n\n return {\n top: (old?.top ?? []).filter(d => !rowIds?.has(d)),\n bottom: (old?.bottom ?? []).filter(d => !rowIds?.has(d)),\n }\n })\n }\n row.getCanPin = () => {\n const { enableRowPinning, enablePinning } = table.options\n if (typeof enableRowPinning === 'function') {\n return enableRowPinning(row)\n }\n return enableRowPinning ?? enablePinning ?? true\n }\n row.getIsPinned = () => {\n const rowIds = [row.id]\n\n const { top, bottom } = table.getState().rowPinning\n\n const isTop = rowIds.some(d => top?.includes(d))\n const isBottom = rowIds.some(d => bottom?.includes(d))\n\n return isTop ? 'top' : isBottom ? 'bottom' : false\n }\n row.getPinnedIndex = () => {\n const position = row.getIsPinned()\n if (!position) return -1\n\n const visiblePinnedRowIds = table\n ._getPinnedRows(position)\n ?.map(({ id }) => id)\n\n return visiblePinnedRowIds?.indexOf(row.id) ?? -1\n }\n },\n\n createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setRowPinning = updater => table.options.onRowPinningChange?.(updater)\n\n table.resetRowPinning = defaultState =>\n table.setRowPinning(\n defaultState\n ? getDefaultRowPinningState()\n : table.initialState?.rowPinning ?? getDefaultRowPinningState()\n )\n\n table.getIsSomeRowsPinned = position => {\n const pinningState = table.getState().rowPinning\n\n if (!position) {\n return Boolean(pinningState.top?.length || pinningState.bottom?.length)\n }\n return Boolean(pinningState[position]?.length)\n }\n\n table._getPinnedRows = memo(\n position => [\n table.getRowModel().rows,\n table.getState().rowPinning[position!],\n position,\n ],\n (visibleRows, pinnedRowIds, position) => {\n const rows =\n table.options.keepPinnedRows ?? true\n ? //get all rows that are pinned even if they would not be otherwise visible\n //account for expanded parent rows, but not pagination or filtering\n (pinnedRowIds ?? []).map(rowId => {\n const row = table.getRow(rowId, true)\n return row.getIsAllParentsExpanded() ? row : null\n })\n : //else get only visible rows that are pinned\n (pinnedRowIds ?? []).map(\n rowId => visibleRows.find(row => row.id === rowId)!\n )\n\n return rows\n .filter(Boolean)\n .map(d => ({ ...d, position })) as Row<TData>[]\n },\n getMemoOptions(table.options, 'debugRows', '_getPinnedRows')\n )\n\n table.getTopRows = () => table._getPinnedRows('top')\n\n table.getBottomRows = () => table._getPinnedRows('bottom')\n\n table.getCenterRows = memo(\n () => [\n table.getRowModel().rows,\n table.getState().rowPinning.top,\n table.getState().rowPinning.bottom,\n ],\n (allRows, top, bottom) => {\n const topAndBottom = new Set([...(top ?? []), ...(bottom ?? [])])\n return allRows.filter(d => !topAndBottom.has(d.id))\n },\n getMemoOptions(table.options, 'debugRows', 'getCenterRows')\n )\n },\n}\n"],"names":[],"mappings":";AAuHA,MAAM,4BAA4B,OAAwB;AAAA,EACxD,KAAK,CAAC;AAAA,EACN,QAAQ,CAAC;AACX;AAEO,MAAM,aAA2B;AAAA,EACtC,iBAAiB,CAAC,UAAgC;AACzC,WAAA;AAAA,MACL,YAAY,0BAA0B;AAAA,MACtC,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EAEA,mBAAmB,CACjB,UAC6B;AACtB,WAAA;AAAA,MACL,oBAAoB,iBAAiB,cAAc,KAAK;AAAA,IAAA;AAAA,EAE5D;AAAA,EAEA,WAAW,CACT,KACA,UACS;AACT,QAAI,MAAM,CAAC,UAAU,iBAAiB,sBAAsB;AAC1D,YAAM,aAAa,kBACf,IAAI,YAAc,EAAA,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,IACpC,CAAA;AACJ,YAAM,eAAe,oBACjB,IAAI,cAAgB,EAAA,IAAI,CAAC,EAAE,GAAG,MAAM,EAAE,IACtC,CAAA;AACE,YAAA,SAAa,oBAAA,IAAI,CAAC,GAAG,cAAc,IAAI,IAAI,GAAG,UAAU,CAAC;AAE/D,YAAM,cAAc,CAAO,QAAA;AACzB,YAAI,aAAa,UAAU;AAClB,iBAAA;AAAA,YACL,OAAM,2BAAK,QAAO,IAAI,OAAO,CAAA,MAAK,EAAC,iCAAQ,IAAI,GAAE;AAAA,YACjD,QAAQ;AAAA,cACN,KAAI,2BAAK,WAA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a,MAAM,MAAM,eAAe,KAAK;AAEnD,UAAM,gBAAgB,MAAM,MAAM,eAAe,QAAQ;AAEzD,UAAM,gBAAgB;AAAA,MACpB,MAAM;AAAA,QACJ,MAAM,cAAc;AAAA,QACpB,MAAM,WAAW,WAAW;AAAA,QAC5B,MAAM,WAAW,WAAW;AAAA,MAC9B;AAAA,MACA,CAAC,SAAS,KAAK,WAAW;AACxB,cAAM,eAAe,oBAAI,IAAI,CAAC,GAAI,OAAO,CAAA,GAAK,GAAI,UAAU,CAAG,CAAA,CAAC;AACzD,eAAA,QAAQ,OAAO,CAAK,MAAA,CAAC,aAAa,IAAI,EAAE,EAAE,CAAC;AAAA,MACpD;AAAA,MACA,eAAe,MAAM,SAAS,aAAa,eAAe;AAAA,IAAA;AAAA,EAE9D;AACF;"}
@@ -1,4 +1,5 @@
1
1
  import { OnChangeFn, Table, Row, RowModel, Updater, RowData, TableFeature } from '../types';
2
+
2
3
  export type RowSelectionState = Record<string, boolean>;
3
4
  export interface RowSelectionTableState {
4
5
  rowSelection: RowSelectionState;
@@ -0,0 +1,298 @@
1
+ import { makeStateUpdater, memo, getMemoOptions } from "../utils.js";
2
+ const RowSelection = {
3
+ getInitialState: (state) => {
4
+ return {
5
+ rowSelection: {},
6
+ ...state
7
+ };
8
+ },
9
+ getDefaultOptions: (table) => {
10
+ return {
11
+ onRowSelectionChange: makeStateUpdater("rowSelection", table),
12
+ enableRowSelection: true,
13
+ enableMultiRowSelection: true,
14
+ enableSubRowSelection: true
15
+ // enableGroupingRowSelection: false,
16
+ // isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
17
+ // isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
18
+ };
19
+ },
20
+ createTable: (table) => {
21
+ table.setRowSelection = (updater) => {
22
+ var _a, _b;
23
+ return (_b = (_a = table.options).onRowSelectionChange) == null ? void 0 : _b.call(_a, updater);
24
+ };
25
+ table.resetRowSelection = (defaultState) => table.setRowSelection(
26
+ defaultState ? {} : table.initialState.rowSelection ?? {}
27
+ );
28
+ table.toggleAllRowsSelected = (value) => {
29
+ table.setRowSelection((old) => {
30
+ value = typeof value !== "undefined" ? value : !table.getIsAllRowsSelected();
31
+ const rowSelection = { ...old };
32
+ const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
33
+ if (value) {
34
+ preGroupedFlatRows.forEach((row) => {
35
+ if (!row.getCanSelect()) {
36
+ return;
37
+ }
38
+ rowSelection[row.id] = true;
39
+ });
40
+ } else {
41
+ preGroupedFlatRows.forEach((row) => {
42
+ delete rowSelection[row.id];
43
+ });
44
+ }
45
+ return rowSelection;
46
+ });
47
+ };
48
+ table.toggleAllPageRowsSelected = (value) => table.setRowSelection((old) => {
49
+ const resolvedValue = typeof value !== "undefined" ? value : !table.getIsAllPageRowsSelected();
50
+ const rowSelection = { ...old };
51
+ table.getRowModel().rows.forEach((row) => {
52
+ mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table);
53
+ });
54
+ return rowSelection;
55
+ });
56
+ table.getPreSelectedRowModel = () => table.getCoreRowModel();
57
+ table.getSelectedRowModel = memo(
58
+ () => [table.getState().rowSelection, table.getCoreRowModel()],
59
+ (rowSelection, rowModel) => {
60
+ if (!Object.keys(rowSelection).length) {
61
+ return {
62
+ rows: [],
63
+ flatRows: [],
64
+ rowsById: {}
65
+ };
66
+ }
67
+ return selectRowsFn(table, rowModel);
68
+ },
69
+ getMemoOptions(table.options, "debugTable", "getSelectedRowModel")
70
+ );
71
+ table.getFilteredSelectedRowModel = memo(
72
+ () => [table.getState().rowSelection, table.getFilteredRowModel()],
73
+ (rowSelection, rowModel) => {
74
+ if (!Object.keys(rowSelection).length) {
75
+ return {
76
+ rows: [],
77
+ flatRows: [],
78
+ rowsById: {}
79
+ };
80
+ }
81
+ return selectRowsFn(table, rowModel);
82
+ },
83
+ getMemoOptions(table.options, "debugTable", "getFilteredSelectedRowModel")
84
+ );
85
+ table.getGroupedSelectedRowModel = memo(
86
+ () => [table.getState().rowSelection, table.getSortedRowModel()],
87
+ (rowSelection, rowModel) => {
88
+ if (!Object.keys(rowSelection).length) {
89
+ return {
90
+ rows: [],
91
+ flatRows: [],
92
+ rowsById: {}
93
+ };
94
+ }
95
+ return selectRowsFn(table, rowModel);
96
+ },
97
+ getMemoOptions(table.options, "debugTable", "getGroupedSelectedRowModel")
98
+ );
99
+ table.getIsAllRowsSelected = () => {
100
+ const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
101
+ const { rowSelection } = table.getState();
102
+ let isAllRowsSelected = Boolean(
103
+ preGroupedFlatRows.length && Object.keys(rowSelection).length
104
+ );
105
+ if (isAllRowsSelected) {
106
+ if (preGroupedFlatRows.some(
107
+ (row) => row.getCanSelect() && !rowSelection[row.id]
108
+ )) {
109
+ isAllRowsSelected = false;
110
+ }
111
+ }
112
+ return isAllRowsSelected;
113
+ };
114
+ table.getIsAllPageRowsSelected = () => {
115
+ const paginationFlatRows = table.getPaginationRowModel().flatRows.filter((row) => row.getCanSelect());
116
+ const { rowSelection } = table.getState();
117
+ let isAllPageRowsSelected = !!paginationFlatRows.length;
118
+ if (isAllPageRowsSelected && paginationFlatRows.some((row) => !rowSelection[row.id])) {
119
+ isAllPageRowsSelected = false;
120
+ }
121
+ return isAllPageRowsSelected;
122
+ };
123
+ table.getIsSomeRowsSelected = () => {
124
+ const totalSelected = Object.keys(
125
+ table.getState().rowSelection ?? {}
126
+ ).length;
127
+ return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
128
+ };
129
+ table.getIsSomePageRowsSelected = () => {
130
+ const paginationFlatRows = table.getPaginationRowModel().flatRows;
131
+ return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.filter((row) => row.getCanSelect()).some((d) => d.getIsSelected() || d.getIsSomeSelected());
132
+ };
133
+ table.getToggleAllRowsSelectedHandler = () => {
134
+ return (e) => {
135
+ table.toggleAllRowsSelected(
136
+ e.target.checked
137
+ );
138
+ };
139
+ };
140
+ table.getToggleAllPageRowsSelectedHandler = () => {
141
+ return (e) => {
142
+ table.toggleAllPageRowsSelected(
143
+ e.target.checked
144
+ );
145
+ };
146
+ };
147
+ },
148
+ createRow: (row, table) => {
149
+ row.toggleSelected = (value, opts) => {
150
+ const isSelected = row.getIsSelected();
151
+ table.setRowSelection((old) => {
152
+ value = typeof value !== "undefined" ? value : !isSelected;
153
+ if (row.getCanSelect() && isSelected === value) {
154
+ return old;
155
+ }
156
+ const selectedRowIds = { ...old };
157
+ mutateRowIsSelected(
158
+ selectedRowIds,
159
+ row.id,
160
+ value,
161
+ (opts == null ? void 0 : opts.selectChildren) ?? true,
162
+ table
163
+ );
164
+ return selectedRowIds;
165
+ });
166
+ };
167
+ row.getIsSelected = () => {
168
+ const { rowSelection } = table.getState();
169
+ return isRowSelected(row, rowSelection);
170
+ };
171
+ row.getIsSomeSelected = () => {
172
+ const { rowSelection } = table.getState();
173
+ return isSubRowSelected(row, rowSelection) === "some";
174
+ };
175
+ row.getIsAllSubRowsSelected = () => {
176
+ const { rowSelection } = table.getState();
177
+ return isSubRowSelected(row, rowSelection) === "all";
178
+ };
179
+ row.getCanSelect = () => {
180
+ if (typeof table.options.enableRowSelection === "function") {
181
+ return table.options.enableRowSelection(row);
182
+ }
183
+ return table.options.enableRowSelection ?? true;
184
+ };
185
+ row.getCanSelectSubRows = () => {
186
+ if (typeof table.options.enableSubRowSelection === "function") {
187
+ return table.options.enableSubRowSelection(row);
188
+ }
189
+ return table.options.enableSubRowSelection ?? true;
190
+ };
191
+ row.getCanMultiSelect = () => {
192
+ if (typeof table.options.enableMultiRowSelection === "function") {
193
+ return table.options.enableMultiRowSelection(row);
194
+ }
195
+ return table.options.enableMultiRowSelection ?? true;
196
+ };
197
+ row.getToggleSelectedHandler = () => {
198
+ const canSelect = row.getCanSelect();
199
+ return (e) => {
200
+ var _a;
201
+ if (!canSelect)
202
+ return;
203
+ row.toggleSelected(
204
+ (_a = e.target) == null ? void 0 : _a.checked
205
+ );
206
+ };
207
+ };
208
+ }
209
+ };
210
+ const mutateRowIsSelected = (selectedRowIds, id, value, includeChildren, table) => {
211
+ var _a;
212
+ const row = table.getRow(id, true);
213
+ if (value) {
214
+ if (!row.getCanMultiSelect()) {
215
+ Object.keys(selectedRowIds).forEach((key) => delete selectedRowIds[key]);
216
+ }
217
+ if (row.getCanSelect()) {
218
+ selectedRowIds[id] = true;
219
+ }
220
+ } else {
221
+ delete selectedRowIds[id];
222
+ }
223
+ if (includeChildren && ((_a = row.subRows) == null ? void 0 : _a.length) && row.getCanSelectSubRows()) {
224
+ row.subRows.forEach(
225
+ (row2) => mutateRowIsSelected(selectedRowIds, row2.id, value, includeChildren, table)
226
+ );
227
+ }
228
+ };
229
+ function selectRowsFn(table, rowModel) {
230
+ const rowSelection = table.getState().rowSelection;
231
+ const newSelectedFlatRows = [];
232
+ const newSelectedRowsById = {};
233
+ const recurseRows = (rows, depth = 0) => {
234
+ return rows.map((row) => {
235
+ var _a;
236
+ const isSelected = isRowSelected(row, rowSelection);
237
+ if (isSelected) {
238
+ newSelectedFlatRows.push(row);
239
+ newSelectedRowsById[row.id] = row;
240
+ }
241
+ if ((_a = row.subRows) == null ? void 0 : _a.length) {
242
+ row = {
243
+ ...row,
244
+ subRows: recurseRows(row.subRows, depth + 1)
245
+ };
246
+ }
247
+ if (isSelected) {
248
+ return row;
249
+ }
250
+ }).filter(Boolean);
251
+ };
252
+ return {
253
+ rows: recurseRows(rowModel.rows),
254
+ flatRows: newSelectedFlatRows,
255
+ rowsById: newSelectedRowsById
256
+ };
257
+ }
258
+ function isRowSelected(row, selection) {
259
+ return selection[row.id] ?? false;
260
+ }
261
+ function isSubRowSelected(row, selection, table) {
262
+ var _a;
263
+ if (!((_a = row.subRows) == null ? void 0 : _a.length))
264
+ return false;
265
+ let allChildrenSelected = true;
266
+ let someSelected = false;
267
+ row.subRows.forEach((subRow) => {
268
+ if (someSelected && !allChildrenSelected) {
269
+ return;
270
+ }
271
+ if (subRow.getCanSelect()) {
272
+ if (isRowSelected(subRow, selection)) {
273
+ someSelected = true;
274
+ } else {
275
+ allChildrenSelected = false;
276
+ }
277
+ }
278
+ if (subRow.subRows && subRow.subRows.length) {
279
+ const subRowChildrenSelected = isSubRowSelected(subRow, selection);
280
+ if (subRowChildrenSelected === "all") {
281
+ someSelected = true;
282
+ } else if (subRowChildrenSelected === "some") {
283
+ someSelected = true;
284
+ allChildrenSelected = false;
285
+ } else {
286
+ allChildrenSelected = false;
287
+ }
288
+ }
289
+ });
290
+ return allChildrenSelected ? "all" : someSelected ? "some" : false;
291
+ }
292
+ export {
293
+ RowSelection,
294
+ isRowSelected,
295
+ isSubRowSelected,
296
+ selectRowsFn
297
+ };
298
+ //# sourceMappingURL=RowSelection.js.map