@tanstack/table-core 8.19.2 → 9.0.0-alpha.10

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 (302) hide show
  1. package/dist/cjs/aggregationFns.cjs +94 -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 +92 -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 +232 -0
  20. package/dist/cjs/core/table.cjs.map +1 -0
  21. package/dist/cjs/core/table.d.cts +229 -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 +133 -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 +307 -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 +152 -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 +161 -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 +132 -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 +296 -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 +200 -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} +41 -53
  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 +35 -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 +37 -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 +88 -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} +26 -39
  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 +94 -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 +2 -1
  114. package/dist/esm/core/cell.js +38 -0
  115. package/dist/esm/core/cell.js.map +1 -0
  116. package/{build/lib → dist/esm}/core/column.d.ts +2 -1
  117. package/dist/esm/core/column.js +81 -0
  118. package/dist/esm/core/column.js.map +1 -0
  119. package/{build/lib → dist/esm}/core/headers.d.ts +1 -0
  120. package/dist/esm/core/headers.js +310 -0
  121. package/dist/esm/core/headers.js.map +1 -0
  122. package/{build/lib → dist/esm}/core/row.d.ts +2 -1
  123. package/dist/esm/core/row.js +92 -0
  124. package/dist/esm/core/row.js.map +1 -0
  125. package/{build/lib → dist/esm}/core/table.d.ts +10 -1
  126. package/dist/esm/core/table.js +232 -0
  127. package/dist/esm/core/table.js.map +1 -0
  128. package/{build/lib → dist/esm}/features/ColumnFaceting.d.ts +1 -0
  129. package/{build/lib → dist/esm}/features/ColumnFaceting.js +6 -19
  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/dist/esm/features/ColumnFiltering.js.map +1 -0
  134. package/{build/lib → dist/esm}/features/ColumnGrouping.d.ts +1 -0
  135. package/dist/esm/features/ColumnGrouping.js +133 -0
  136. package/dist/esm/features/ColumnGrouping.js.map +1 -0
  137. package/{build/lib → dist/esm}/features/ColumnOrdering.d.ts +1 -0
  138. package/dist/esm/features/ColumnOrdering.js +76 -0
  139. package/dist/esm/features/ColumnOrdering.js.map +1 -0
  140. package/{build/lib → dist/esm}/features/ColumnPinning.d.ts +1 -0
  141. package/dist/esm/features/ColumnPinning.js +145 -0
  142. package/dist/esm/features/ColumnPinning.js.map +1 -0
  143. package/{build/lib → dist/esm}/features/ColumnSizing.d.ts +2 -1
  144. package/dist/esm/features/ColumnSizing.js +307 -0
  145. package/dist/esm/features/ColumnSizing.js.map +1 -0
  146. package/{build/lib → dist/esm}/features/ColumnVisibility.d.ts +1 -0
  147. package/dist/esm/features/ColumnVisibility.js +144 -0
  148. package/dist/esm/features/ColumnVisibility.js.map +1 -0
  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/dist/esm/features/GlobalFaceting.js.map +1 -0
  152. package/{build/lib → dist/esm}/features/GlobalFiltering.d.ts +1 -0
  153. package/dist/esm/features/GlobalFiltering.js +50 -0
  154. package/dist/esm/features/GlobalFiltering.js.map +1 -0
  155. package/{build/lib → dist/esm}/features/RowExpanding.d.ts +1 -0
  156. package/{build/lib → dist/esm}/features/RowExpanding.js +37 -58
  157. package/dist/esm/features/RowExpanding.js.map +1 -0
  158. package/{build/lib → dist/esm}/features/RowPagination.d.ts +1 -0
  159. package/dist/esm/features/RowPagination.js +161 -0
  160. package/dist/esm/features/RowPagination.js.map +1 -0
  161. package/{build/lib → dist/esm}/features/RowPinning.d.ts +1 -0
  162. package/dist/esm/features/RowPinning.js +132 -0
  163. package/dist/esm/features/RowPinning.js.map +1 -0
  164. package/{build/lib → dist/esm}/features/RowSelection.d.ts +1 -0
  165. package/dist/esm/features/RowSelection.js +296 -0
  166. package/dist/esm/features/RowSelection.js.map +1 -0
  167. package/{build/lib → dist/esm}/features/RowSorting.d.ts +1 -0
  168. package/dist/esm/features/RowSorting.js +200 -0
  169. package/dist/esm/features/RowSorting.js.map +1 -0
  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 +88 -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 +29 -28
  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/dist/esm/utils/getCoreRowModel.js.map +1 -0
  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 +35 -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 +37 -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/{build/lib → dist/esm}/utils/getFilteredRowModel.js.map +1 -1
  201. package/{build/lib → dist/esm}/utils/getGroupedRowModel.d.ts +1 -0
  202. package/dist/esm/utils/getGroupedRowModel.js +118 -0
  203. package/dist/esm/utils/getGroupedRowModel.js.map +1 -0
  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 +88 -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 +98 -0
  212. package/{build/lib → dist/esm}/utils.js.map +1 -1
  213. package/package.json +14 -10
  214. package/src/core/cell.ts +2 -2
  215. package/src/core/column.ts +2 -2
  216. package/src/core/headers.ts +5 -5
  217. package/src/core/row.ts +4 -4
  218. package/src/core/table.ts +43 -7
  219. package/src/features/ColumnFaceting.ts +1 -1
  220. package/src/features/ColumnFiltering.ts +6 -6
  221. package/src/features/ColumnGrouping.ts +7 -7
  222. package/src/features/ColumnOrdering.ts +4 -4
  223. package/src/features/ColumnPinning.ts +5 -5
  224. package/src/features/ColumnSizing.ts +6 -6
  225. package/src/features/ColumnVisibility.ts +5 -5
  226. package/src/features/GlobalFaceting.ts +1 -1
  227. package/src/features/GlobalFiltering.ts +4 -4
  228. package/src/features/RowExpanding.ts +4 -4
  229. package/src/features/RowPagination.ts +3 -3
  230. package/src/features/RowPinning.ts +4 -4
  231. package/src/features/RowSelection.ts +4 -4
  232. package/src/features/RowSorting.ts +5 -5
  233. package/src/types.ts +8 -8
  234. package/src/utils/filterRowsUtils.ts +3 -3
  235. package/src/utils/getCoreRowModel.ts +2 -2
  236. package/src/utils/getGroupedRowModel.ts +2 -2
  237. package/build/lib/aggregationFns.js +0 -108
  238. package/build/lib/aggregationFns.js.map +0 -1
  239. package/build/lib/columnHelper.js +0 -71
  240. package/build/lib/core/cell.js +0 -42
  241. package/build/lib/core/cell.js.map +0 -1
  242. package/build/lib/core/column.js +0 -80
  243. package/build/lib/core/column.js.map +0 -1
  244. package/build/lib/core/headers.js +0 -270
  245. package/build/lib/core/headers.js.map +0 -1
  246. package/build/lib/core/row.js +0 -89
  247. package/build/lib/core/row.js.map +0 -1
  248. package/build/lib/core/table.js +0 -212
  249. package/build/lib/core/table.js.map +0 -1
  250. package/build/lib/features/ColumnFiltering.js +0 -151
  251. package/build/lib/features/ColumnFiltering.js.map +0 -1
  252. package/build/lib/features/ColumnGrouping.js +0 -142
  253. package/build/lib/features/ColumnGrouping.js.map +0 -1
  254. package/build/lib/features/ColumnOrdering.js +0 -84
  255. package/build/lib/features/ColumnOrdering.js.map +0 -1
  256. package/build/lib/features/ColumnPinning.js +0 -130
  257. package/build/lib/features/ColumnPinning.js.map +0 -1
  258. package/build/lib/features/ColumnSizing.js +0 -270
  259. package/build/lib/features/ColumnSizing.js.map +0 -1
  260. package/build/lib/features/ColumnVisibility.js +0 -99
  261. package/build/lib/features/ColumnVisibility.js.map +0 -1
  262. package/build/lib/features/GlobalFaceting.js.map +0 -1
  263. package/build/lib/features/GlobalFiltering.js +0 -63
  264. package/build/lib/features/GlobalFiltering.js.map +0 -1
  265. package/build/lib/features/RowExpanding.js.map +0 -1
  266. package/build/lib/features/RowPagination.js +0 -169
  267. package/build/lib/features/RowPagination.js.map +0 -1
  268. package/build/lib/features/RowPinning.js +0 -145
  269. package/build/lib/features/RowPinning.js.map +0 -1
  270. package/build/lib/features/RowSelection.js +0 -391
  271. package/build/lib/features/RowSelection.js.map +0 -1
  272. package/build/lib/features/RowSorting.js +0 -226
  273. package/build/lib/features/RowSorting.js.map +0 -1
  274. package/build/lib/filterFns.js +0 -96
  275. package/build/lib/filterFns.js.map +0 -1
  276. package/build/lib/index.d.ts +0 -34
  277. package/build/lib/index.esm.js +0 -3522
  278. package/build/lib/index.esm.js.map +0 -1
  279. package/build/lib/index.js.map +0 -1
  280. package/build/lib/index.mjs +0 -3522
  281. package/build/lib/index.mjs.map +0 -1
  282. package/build/lib/sortingFns.js.map +0 -1
  283. package/build/lib/utils/filterRowsUtils.js.map +0 -1
  284. package/build/lib/utils/getCoreRowModel.js +0 -65
  285. package/build/lib/utils/getCoreRowModel.js.map +0 -1
  286. package/build/lib/utils/getExpandedRowModel.js +0 -46
  287. package/build/lib/utils/getExpandedRowModel.js.map +0 -1
  288. package/build/lib/utils/getFacetedMinMaxValues.js +0 -43
  289. package/build/lib/utils/getFacetedMinMaxValues.js.map +0 -1
  290. package/build/lib/utils/getFacetedRowModel.js +0 -36
  291. package/build/lib/utils/getFacetedUniqueValues.js +0 -39
  292. package/build/lib/utils/getFacetedUniqueValues.js.map +0 -1
  293. package/build/lib/utils/getFilteredRowModel.js +0 -111
  294. package/build/lib/utils/getGroupedRowModel.js +0 -150
  295. package/build/lib/utils/getGroupedRowModel.js.map +0 -1
  296. package/build/lib/utils/getPaginationRowModel.js +0 -60
  297. package/build/lib/utils/getPaginationRowModel.js.map +0 -1
  298. package/build/lib/utils/getSortedRowModel.js +0 -102
  299. package/build/umd/index.development.js +0 -3578
  300. package/build/umd/index.development.js.map +0 -1
  301. package/build/umd/index.production.js +0 -12
  302. package/build/umd/index.production.js.map +0 -1
@@ -1,3522 +0,0 @@
1
- /**
2
- * table-core
3
- *
4
- * Copyright (c) TanStack
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE.md file in the root directory of this source tree.
8
- *
9
- * @license MIT
10
- */
11
- // type Person = {
12
- // firstName: string
13
- // lastName: string
14
- // age: number
15
- // visits: number
16
- // status: string
17
- // progress: number
18
- // createdAt: Date
19
- // nested: {
20
- // foo: [
21
- // {
22
- // bar: 'bar'
23
- // }
24
- // ]
25
- // bar: { subBar: boolean }[]
26
- // baz: {
27
- // foo: 'foo'
28
- // bar: {
29
- // baz: 'baz'
30
- // }
31
- // }
32
- // }
33
- // }
34
-
35
- // const test: DeepKeys<Person> = 'nested.foo.0.bar'
36
- // const test2: DeepKeys<Person> = 'nested.bar'
37
-
38
- // const helper = createColumnHelper<Person>()
39
-
40
- // helper.accessor('nested.foo', {
41
- // cell: info => info.getValue(),
42
- // })
43
-
44
- // helper.accessor('nested.foo.0.bar', {
45
- // cell: info => info.getValue(),
46
- // })
47
-
48
- // helper.accessor('nested.bar', {
49
- // cell: info => info.getValue(),
50
- // })
51
-
52
- function createColumnHelper() {
53
- return {
54
- accessor: (accessor, column) => {
55
- return typeof accessor === 'function' ? {
56
- ...column,
57
- accessorFn: accessor
58
- } : {
59
- ...column,
60
- accessorKey: accessor
61
- };
62
- },
63
- display: column => column,
64
- group: column => column
65
- };
66
- }
67
-
68
- // Is this type a tuple?
69
-
70
- // If this type is a tuple, what indices are allowed?
71
-
72
- ///
73
-
74
- function functionalUpdate(updater, input) {
75
- return typeof updater === 'function' ? updater(input) : updater;
76
- }
77
- function noop() {
78
- //
79
- }
80
- function makeStateUpdater(key, instance) {
81
- return updater => {
82
- instance.setState(old => {
83
- return {
84
- ...old,
85
- [key]: functionalUpdate(updater, old[key])
86
- };
87
- });
88
- };
89
- }
90
- function isFunction(d) {
91
- return d instanceof Function;
92
- }
93
- function isNumberArray(d) {
94
- return Array.isArray(d) && d.every(val => typeof val === 'number');
95
- }
96
- function flattenBy(arr, getChildren) {
97
- const flat = [];
98
- const recurse = subArr => {
99
- subArr.forEach(item => {
100
- flat.push(item);
101
- const children = getChildren(item);
102
- if (children != null && children.length) {
103
- recurse(children);
104
- }
105
- });
106
- };
107
- recurse(arr);
108
- return flat;
109
- }
110
- function memo(getDeps, fn, opts) {
111
- let deps = [];
112
- let result;
113
- return depArgs => {
114
- let depTime;
115
- if (opts.key && opts.debug) depTime = Date.now();
116
- const newDeps = getDeps(depArgs);
117
- const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
118
- if (!depsChanged) {
119
- return result;
120
- }
121
- deps = newDeps;
122
- let resultTime;
123
- if (opts.key && opts.debug) resultTime = Date.now();
124
- result = fn(...newDeps);
125
- opts == null || opts.onChange == null || opts.onChange(result);
126
- if (opts.key && opts.debug) {
127
- if (opts != null && opts.debug()) {
128
- const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
129
- const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
130
- const resultFpsPercentage = resultEndTime / 16;
131
- const pad = (str, num) => {
132
- str = String(str);
133
- while (str.length < num) {
134
- str = ' ' + str;
135
- }
136
- return str;
137
- };
138
- console.info(`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`, `
139
- font-size: .6rem;
140
- font-weight: bold;
141
- color: hsl(${Math.max(0, Math.min(120 - 120 * resultFpsPercentage, 120))}deg 100% 31%);`, opts == null ? void 0 : opts.key);
142
- }
143
- }
144
- return result;
145
- };
146
- }
147
- function getMemoOptions(tableOptions, debugLevel, key, onChange) {
148
- return {
149
- debug: () => {
150
- var _tableOptions$debugAl;
151
- return (_tableOptions$debugAl = tableOptions == null ? void 0 : tableOptions.debugAll) != null ? _tableOptions$debugAl : tableOptions[debugLevel];
152
- },
153
- key: process.env.NODE_ENV === 'development' && key,
154
- onChange
155
- };
156
- }
157
-
158
- function createCell(table, row, column, columnId) {
159
- const getRenderValue = () => {
160
- var _cell$getValue;
161
- return (_cell$getValue = cell.getValue()) != null ? _cell$getValue : table.options.renderFallbackValue;
162
- };
163
- const cell = {
164
- id: `${row.id}_${column.id}`,
165
- row,
166
- column,
167
- getValue: () => row.getValue(columnId),
168
- renderValue: getRenderValue,
169
- getContext: memo(() => [table, column, row, cell], (table, column, row, cell) => ({
170
- table,
171
- column,
172
- row,
173
- cell: cell,
174
- getValue: cell.getValue,
175
- renderValue: cell.renderValue
176
- }), getMemoOptions(table.options, 'debugCells', 'cell.getContext'))
177
- };
178
- table._features.forEach(feature => {
179
- feature.createCell == null || feature.createCell(cell, column, row, table);
180
- }, {});
181
- return cell;
182
- }
183
-
184
- function createColumn(table, columnDef, depth, parent) {
185
- var _ref, _resolvedColumnDef$id;
186
- const defaultColumn = table._getDefaultColumnDef();
187
- const resolvedColumnDef = {
188
- ...defaultColumn,
189
- ...columnDef
190
- };
191
- const accessorKey = resolvedColumnDef.accessorKey;
192
- let id = (_ref = (_resolvedColumnDef$id = resolvedColumnDef.id) != null ? _resolvedColumnDef$id : accessorKey ? accessorKey.replace('.', '_') : undefined) != null ? _ref : typeof resolvedColumnDef.header === 'string' ? resolvedColumnDef.header : undefined;
193
- let accessorFn;
194
- if (resolvedColumnDef.accessorFn) {
195
- accessorFn = resolvedColumnDef.accessorFn;
196
- } else if (accessorKey) {
197
- // Support deep accessor keys
198
- if (accessorKey.includes('.')) {
199
- accessorFn = originalRow => {
200
- let result = originalRow;
201
- for (const key of accessorKey.split('.')) {
202
- var _result;
203
- result = (_result = result) == null ? void 0 : _result[key];
204
- if (process.env.NODE_ENV !== 'production' && result === undefined) {
205
- console.warn(`"${key}" in deeply nested key "${accessorKey}" returned undefined.`);
206
- }
207
- }
208
- return result;
209
- };
210
- } else {
211
- accessorFn = originalRow => originalRow[resolvedColumnDef.accessorKey];
212
- }
213
- }
214
- if (!id) {
215
- if (process.env.NODE_ENV !== 'production') {
216
- throw new Error(resolvedColumnDef.accessorFn ? `Columns require an id when using an accessorFn` : `Columns require an id when using a non-string header`);
217
- }
218
- throw new Error();
219
- }
220
- let column = {
221
- id: `${String(id)}`,
222
- accessorFn,
223
- parent: parent,
224
- depth,
225
- columnDef: resolvedColumnDef,
226
- columns: [],
227
- getFlatColumns: memo(() => [true], () => {
228
- var _column$columns;
229
- return [column, ...((_column$columns = column.columns) == null ? void 0 : _column$columns.flatMap(d => d.getFlatColumns()))];
230
- }, getMemoOptions(table.options, 'debugColumns', 'column.getFlatColumns')),
231
- getLeafColumns: memo(() => [table._getOrderColumnsFn()], orderColumns => {
232
- var _column$columns2;
233
- if ((_column$columns2 = column.columns) != null && _column$columns2.length) {
234
- let leafColumns = column.columns.flatMap(column => column.getLeafColumns());
235
- return orderColumns(leafColumns);
236
- }
237
- return [column];
238
- }, getMemoOptions(table.options, 'debugColumns', 'column.getLeafColumns'))
239
- };
240
- for (const feature of table._features) {
241
- feature.createColumn == null || feature.createColumn(column, table);
242
- }
243
-
244
- // Yes, we have to convert table to unknown, because we know more than the compiler here.
245
- return column;
246
- }
247
-
248
- const debug = 'debugHeaders';
249
- //
250
-
251
- function createHeader(table, column, options) {
252
- var _options$id;
253
- const id = (_options$id = options.id) != null ? _options$id : column.id;
254
- let header = {
255
- id,
256
- column,
257
- index: options.index,
258
- isPlaceholder: !!options.isPlaceholder,
259
- placeholderId: options.placeholderId,
260
- depth: options.depth,
261
- subHeaders: [],
262
- colSpan: 0,
263
- rowSpan: 0,
264
- headerGroup: null,
265
- getLeafHeaders: () => {
266
- const leafHeaders = [];
267
- const recurseHeader = h => {
268
- if (h.subHeaders && h.subHeaders.length) {
269
- h.subHeaders.map(recurseHeader);
270
- }
271
- leafHeaders.push(h);
272
- };
273
- recurseHeader(header);
274
- return leafHeaders;
275
- },
276
- getContext: () => ({
277
- table,
278
- header: header,
279
- column
280
- })
281
- };
282
- table._features.forEach(feature => {
283
- feature.createHeader == null || feature.createHeader(header, table);
284
- });
285
- return header;
286
- }
287
- const Headers = {
288
- createTable: table => {
289
- // Header Groups
290
-
291
- table.getHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
292
- var _left$map$filter, _right$map$filter;
293
- const leftColumns = (_left$map$filter = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter : [];
294
- const rightColumns = (_right$map$filter = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter : [];
295
- const centerColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
296
- const headerGroups = buildHeaderGroups(allColumns, [...leftColumns, ...centerColumns, ...rightColumns], table);
297
- return headerGroups;
298
- }, getMemoOptions(table.options, debug, 'getHeaderGroups'));
299
- table.getCenterHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, leafColumns, left, right) => {
300
- leafColumns = leafColumns.filter(column => !(left != null && left.includes(column.id)) && !(right != null && right.includes(column.id)));
301
- return buildHeaderGroups(allColumns, leafColumns, table, 'center');
302
- }, getMemoOptions(table.options, debug, 'getCenterHeaderGroups'));
303
- table.getLeftHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.left], (allColumns, leafColumns, left) => {
304
- var _left$map$filter2;
305
- const orderedLeafColumns = (_left$map$filter2 = left == null ? void 0 : left.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _left$map$filter2 : [];
306
- return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'left');
307
- }, getMemoOptions(table.options, debug, 'getLeftHeaderGroups'));
308
- table.getRightHeaderGroups = memo(() => [table.getAllColumns(), table.getVisibleLeafColumns(), table.getState().columnPinning.right], (allColumns, leafColumns, right) => {
309
- var _right$map$filter2;
310
- const orderedLeafColumns = (_right$map$filter2 = right == null ? void 0 : right.map(columnId => leafColumns.find(d => d.id === columnId)).filter(Boolean)) != null ? _right$map$filter2 : [];
311
- return buildHeaderGroups(allColumns, orderedLeafColumns, table, 'right');
312
- }, getMemoOptions(table.options, debug, 'getRightHeaderGroups'));
313
-
314
- // Footer Groups
315
-
316
- table.getFooterGroups = memo(() => [table.getHeaderGroups()], headerGroups => {
317
- return [...headerGroups].reverse();
318
- }, getMemoOptions(table.options, debug, 'getFooterGroups'));
319
- table.getLeftFooterGroups = memo(() => [table.getLeftHeaderGroups()], headerGroups => {
320
- return [...headerGroups].reverse();
321
- }, getMemoOptions(table.options, debug, 'getLeftFooterGroups'));
322
- table.getCenterFooterGroups = memo(() => [table.getCenterHeaderGroups()], headerGroups => {
323
- return [...headerGroups].reverse();
324
- }, getMemoOptions(table.options, debug, 'getCenterFooterGroups'));
325
- table.getRightFooterGroups = memo(() => [table.getRightHeaderGroups()], headerGroups => {
326
- return [...headerGroups].reverse();
327
- }, getMemoOptions(table.options, debug, 'getRightFooterGroups'));
328
-
329
- // Flat Headers
330
-
331
- table.getFlatHeaders = memo(() => [table.getHeaderGroups()], headerGroups => {
332
- return headerGroups.map(headerGroup => {
333
- return headerGroup.headers;
334
- }).flat();
335
- }, getMemoOptions(table.options, debug, 'getFlatHeaders'));
336
- table.getLeftFlatHeaders = memo(() => [table.getLeftHeaderGroups()], left => {
337
- return left.map(headerGroup => {
338
- return headerGroup.headers;
339
- }).flat();
340
- }, getMemoOptions(table.options, debug, 'getLeftFlatHeaders'));
341
- table.getCenterFlatHeaders = memo(() => [table.getCenterHeaderGroups()], left => {
342
- return left.map(headerGroup => {
343
- return headerGroup.headers;
344
- }).flat();
345
- }, getMemoOptions(table.options, debug, 'getCenterFlatHeaders'));
346
- table.getRightFlatHeaders = memo(() => [table.getRightHeaderGroups()], left => {
347
- return left.map(headerGroup => {
348
- return headerGroup.headers;
349
- }).flat();
350
- }, getMemoOptions(table.options, debug, 'getRightFlatHeaders'));
351
-
352
- // Leaf Headers
353
-
354
- table.getCenterLeafHeaders = memo(() => [table.getCenterFlatHeaders()], flatHeaders => {
355
- return flatHeaders.filter(header => {
356
- var _header$subHeaders;
357
- return !((_header$subHeaders = header.subHeaders) != null && _header$subHeaders.length);
358
- });
359
- }, getMemoOptions(table.options, debug, 'getCenterLeafHeaders'));
360
- table.getLeftLeafHeaders = memo(() => [table.getLeftFlatHeaders()], flatHeaders => {
361
- return flatHeaders.filter(header => {
362
- var _header$subHeaders2;
363
- return !((_header$subHeaders2 = header.subHeaders) != null && _header$subHeaders2.length);
364
- });
365
- }, getMemoOptions(table.options, debug, 'getLeftLeafHeaders'));
366
- table.getRightLeafHeaders = memo(() => [table.getRightFlatHeaders()], flatHeaders => {
367
- return flatHeaders.filter(header => {
368
- var _header$subHeaders3;
369
- return !((_header$subHeaders3 = header.subHeaders) != null && _header$subHeaders3.length);
370
- });
371
- }, getMemoOptions(table.options, debug, 'getRightLeafHeaders'));
372
- table.getLeafHeaders = memo(() => [table.getLeftHeaderGroups(), table.getCenterHeaderGroups(), table.getRightHeaderGroups()], (left, center, right) => {
373
- var _left$0$headers, _left$, _center$0$headers, _center$, _right$0$headers, _right$;
374
- return [...((_left$0$headers = (_left$ = left[0]) == null ? void 0 : _left$.headers) != null ? _left$0$headers : []), ...((_center$0$headers = (_center$ = center[0]) == null ? void 0 : _center$.headers) != null ? _center$0$headers : []), ...((_right$0$headers = (_right$ = right[0]) == null ? void 0 : _right$.headers) != null ? _right$0$headers : [])].map(header => {
375
- return header.getLeafHeaders();
376
- }).flat();
377
- }, getMemoOptions(table.options, debug, 'getLeafHeaders'));
378
- }
379
- };
380
- function buildHeaderGroups(allColumns, columnsToGroup, table, headerFamily) {
381
- var _headerGroups$0$heade, _headerGroups$;
382
- // Find the max depth of the columns:
383
- // build the leaf column row
384
- // build each buffer row going up
385
- // placeholder for non-existent level
386
- // real column for existing level
387
-
388
- let maxDepth = 0;
389
- const findMaxDepth = function (columns, depth) {
390
- if (depth === void 0) {
391
- depth = 1;
392
- }
393
- maxDepth = Math.max(maxDepth, depth);
394
- columns.filter(column => column.getIsVisible()).forEach(column => {
395
- var _column$columns;
396
- if ((_column$columns = column.columns) != null && _column$columns.length) {
397
- findMaxDepth(column.columns, depth + 1);
398
- }
399
- }, 0);
400
- };
401
- findMaxDepth(allColumns);
402
- let headerGroups = [];
403
- const createHeaderGroup = (headersToGroup, depth) => {
404
- // The header group we are creating
405
- const headerGroup = {
406
- depth,
407
- id: [headerFamily, `${depth}`].filter(Boolean).join('_'),
408
- headers: []
409
- };
410
-
411
- // The parent columns we're going to scan next
412
- const pendingParentHeaders = [];
413
-
414
- // Scan each column for parents
415
- headersToGroup.forEach(headerToGroup => {
416
- // What is the latest (last) parent column?
417
-
418
- const latestPendingParentHeader = [...pendingParentHeaders].reverse()[0];
419
- const isLeafHeader = headerToGroup.column.depth === headerGroup.depth;
420
- let column;
421
- let isPlaceholder = false;
422
- if (isLeafHeader && headerToGroup.column.parent) {
423
- // The parent header is new
424
- column = headerToGroup.column.parent;
425
- } else {
426
- // The parent header is repeated
427
- column = headerToGroup.column;
428
- isPlaceholder = true;
429
- }
430
- if (latestPendingParentHeader && (latestPendingParentHeader == null ? void 0 : latestPendingParentHeader.column) === column) {
431
- // This column is repeated. Add it as a sub header to the next batch
432
- latestPendingParentHeader.subHeaders.push(headerToGroup);
433
- } else {
434
- // This is a new header. Let's create it
435
- const header = createHeader(table, column, {
436
- id: [headerFamily, depth, column.id, headerToGroup == null ? void 0 : headerToGroup.id].filter(Boolean).join('_'),
437
- isPlaceholder,
438
- placeholderId: isPlaceholder ? `${pendingParentHeaders.filter(d => d.column === column).length}` : undefined,
439
- depth,
440
- index: pendingParentHeaders.length
441
- });
442
-
443
- // Add the headerToGroup as a subHeader of the new header
444
- header.subHeaders.push(headerToGroup);
445
- // Add the new header to the pendingParentHeaders to get grouped
446
- // in the next batch
447
- pendingParentHeaders.push(header);
448
- }
449
- headerGroup.headers.push(headerToGroup);
450
- headerToGroup.headerGroup = headerGroup;
451
- });
452
- headerGroups.push(headerGroup);
453
- if (depth > 0) {
454
- createHeaderGroup(pendingParentHeaders, depth - 1);
455
- }
456
- };
457
- const bottomHeaders = columnsToGroup.map((column, index) => createHeader(table, column, {
458
- depth: maxDepth,
459
- index
460
- }));
461
- createHeaderGroup(bottomHeaders, maxDepth - 1);
462
- headerGroups.reverse();
463
-
464
- // headerGroups = headerGroups.filter(headerGroup => {
465
- // return !headerGroup.headers.every(header => header.isPlaceholder)
466
- // })
467
-
468
- const recurseHeadersForSpans = headers => {
469
- const filteredHeaders = headers.filter(header => header.column.getIsVisible());
470
- return filteredHeaders.map(header => {
471
- let colSpan = 0;
472
- let rowSpan = 0;
473
- let childRowSpans = [0];
474
- if (header.subHeaders && header.subHeaders.length) {
475
- childRowSpans = [];
476
- recurseHeadersForSpans(header.subHeaders).forEach(_ref => {
477
- let {
478
- colSpan: childColSpan,
479
- rowSpan: childRowSpan
480
- } = _ref;
481
- colSpan += childColSpan;
482
- childRowSpans.push(childRowSpan);
483
- });
484
- } else {
485
- colSpan = 1;
486
- }
487
- const minChildRowSpan = Math.min(...childRowSpans);
488
- rowSpan = rowSpan + minChildRowSpan;
489
- header.colSpan = colSpan;
490
- header.rowSpan = rowSpan;
491
- return {
492
- colSpan,
493
- rowSpan
494
- };
495
- });
496
- };
497
- recurseHeadersForSpans((_headerGroups$0$heade = (_headerGroups$ = headerGroups[0]) == null ? void 0 : _headerGroups$.headers) != null ? _headerGroups$0$heade : []);
498
- return headerGroups;
499
- }
500
-
501
- const createRow = (table, id, original, rowIndex, depth, subRows, parentId) => {
502
- let row = {
503
- id,
504
- index: rowIndex,
505
- original,
506
- depth,
507
- parentId,
508
- _valuesCache: {},
509
- _uniqueValuesCache: {},
510
- getValue: columnId => {
511
- if (row._valuesCache.hasOwnProperty(columnId)) {
512
- return row._valuesCache[columnId];
513
- }
514
- const column = table.getColumn(columnId);
515
- if (!(column != null && column.accessorFn)) {
516
- return undefined;
517
- }
518
- row._valuesCache[columnId] = column.accessorFn(row.original, rowIndex);
519
- return row._valuesCache[columnId];
520
- },
521
- getUniqueValues: columnId => {
522
- if (row._uniqueValuesCache.hasOwnProperty(columnId)) {
523
- return row._uniqueValuesCache[columnId];
524
- }
525
- const column = table.getColumn(columnId);
526
- if (!(column != null && column.accessorFn)) {
527
- return undefined;
528
- }
529
- if (!column.columnDef.getUniqueValues) {
530
- row._uniqueValuesCache[columnId] = [row.getValue(columnId)];
531
- return row._uniqueValuesCache[columnId];
532
- }
533
- row._uniqueValuesCache[columnId] = column.columnDef.getUniqueValues(row.original, rowIndex);
534
- return row._uniqueValuesCache[columnId];
535
- },
536
- renderValue: columnId => {
537
- var _row$getValue;
538
- return (_row$getValue = row.getValue(columnId)) != null ? _row$getValue : table.options.renderFallbackValue;
539
- },
540
- subRows: subRows != null ? subRows : [],
541
- getLeafRows: () => flattenBy(row.subRows, d => d.subRows),
542
- getParentRow: () => row.parentId ? table.getRow(row.parentId, true) : undefined,
543
- getParentRows: () => {
544
- let parentRows = [];
545
- let currentRow = row;
546
- while (true) {
547
- const parentRow = currentRow.getParentRow();
548
- if (!parentRow) break;
549
- parentRows.push(parentRow);
550
- currentRow = parentRow;
551
- }
552
- return parentRows.reverse();
553
- },
554
- getAllCells: memo(() => [table.getAllLeafColumns()], leafColumns => {
555
- return leafColumns.map(column => {
556
- return createCell(table, row, column, column.id);
557
- });
558
- }, getMemoOptions(table.options, 'debugRows', 'getAllCells')),
559
- _getAllCellsByColumnId: memo(() => [row.getAllCells()], allCells => {
560
- return allCells.reduce((acc, cell) => {
561
- acc[cell.column.id] = cell;
562
- return acc;
563
- }, {});
564
- }, getMemoOptions(table.options, 'debugRows', 'getAllCellsByColumnId'))
565
- };
566
- for (let i = 0; i < table._features.length; i++) {
567
- const feature = table._features[i];
568
- feature == null || feature.createRow == null || feature.createRow(row, table);
569
- }
570
- return row;
571
- };
572
-
573
- //
574
-
575
- const ColumnFaceting = {
576
- createColumn: (column, table) => {
577
- column._getFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, column.id);
578
- column.getFacetedRowModel = () => {
579
- if (!column._getFacetedRowModel) {
580
- return table.getPreFilteredRowModel();
581
- }
582
- return column._getFacetedRowModel();
583
- };
584
- column._getFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, column.id);
585
- column.getFacetedUniqueValues = () => {
586
- if (!column._getFacetedUniqueValues) {
587
- return new Map();
588
- }
589
- return column._getFacetedUniqueValues();
590
- };
591
- column._getFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, column.id);
592
- column.getFacetedMinMaxValues = () => {
593
- if (!column._getFacetedMinMaxValues) {
594
- return undefined;
595
- }
596
- return column._getFacetedMinMaxValues();
597
- };
598
- }
599
- };
600
-
601
- const includesString = (row, columnId, filterValue) => {
602
- var _row$getValue;
603
- const search = filterValue.toLowerCase();
604
- return Boolean((_row$getValue = row.getValue(columnId)) == null || (_row$getValue = _row$getValue.toString()) == null || (_row$getValue = _row$getValue.toLowerCase()) == null ? void 0 : _row$getValue.includes(search));
605
- };
606
- includesString.autoRemove = val => testFalsey(val);
607
- const includesStringSensitive = (row, columnId, filterValue) => {
608
- var _row$getValue2;
609
- return Boolean((_row$getValue2 = row.getValue(columnId)) == null || (_row$getValue2 = _row$getValue2.toString()) == null ? void 0 : _row$getValue2.includes(filterValue));
610
- };
611
- includesStringSensitive.autoRemove = val => testFalsey(val);
612
- const equalsString = (row, columnId, filterValue) => {
613
- var _row$getValue3;
614
- return ((_row$getValue3 = row.getValue(columnId)) == null || (_row$getValue3 = _row$getValue3.toString()) == null ? void 0 : _row$getValue3.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
615
- };
616
- equalsString.autoRemove = val => testFalsey(val);
617
- const arrIncludes = (row, columnId, filterValue) => {
618
- var _row$getValue4;
619
- return (_row$getValue4 = row.getValue(columnId)) == null ? void 0 : _row$getValue4.includes(filterValue);
620
- };
621
- arrIncludes.autoRemove = val => testFalsey(val) || !(val != null && val.length);
622
- const arrIncludesAll = (row, columnId, filterValue) => {
623
- return !filterValue.some(val => {
624
- var _row$getValue5;
625
- return !((_row$getValue5 = row.getValue(columnId)) != null && _row$getValue5.includes(val));
626
- });
627
- };
628
- arrIncludesAll.autoRemove = val => testFalsey(val) || !(val != null && val.length);
629
- const arrIncludesSome = (row, columnId, filterValue) => {
630
- return filterValue.some(val => {
631
- var _row$getValue6;
632
- return (_row$getValue6 = row.getValue(columnId)) == null ? void 0 : _row$getValue6.includes(val);
633
- });
634
- };
635
- arrIncludesSome.autoRemove = val => testFalsey(val) || !(val != null && val.length);
636
- const equals = (row, columnId, filterValue) => {
637
- return row.getValue(columnId) === filterValue;
638
- };
639
- equals.autoRemove = val => testFalsey(val);
640
- const weakEquals = (row, columnId, filterValue) => {
641
- return row.getValue(columnId) == filterValue;
642
- };
643
- weakEquals.autoRemove = val => testFalsey(val);
644
- const inNumberRange = (row, columnId, filterValue) => {
645
- let [min, max] = filterValue;
646
- const rowValue = row.getValue(columnId);
647
- return rowValue >= min && rowValue <= max;
648
- };
649
- inNumberRange.resolveFilterValue = val => {
650
- let [unsafeMin, unsafeMax] = val;
651
- let parsedMin = typeof unsafeMin !== 'number' ? parseFloat(unsafeMin) : unsafeMin;
652
- let parsedMax = typeof unsafeMax !== 'number' ? parseFloat(unsafeMax) : unsafeMax;
653
- let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
654
- let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
655
- if (min > max) {
656
- const temp = min;
657
- min = max;
658
- max = temp;
659
- }
660
- return [min, max];
661
- };
662
- inNumberRange.autoRemove = val => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
663
-
664
- // Export
665
-
666
- const filterFns = {
667
- includesString,
668
- includesStringSensitive,
669
- equalsString,
670
- arrIncludes,
671
- arrIncludesAll,
672
- arrIncludesSome,
673
- equals,
674
- weakEquals,
675
- inNumberRange
676
- };
677
- // Utils
678
-
679
- function testFalsey(val) {
680
- return val === undefined || val === null || val === '';
681
- }
682
-
683
- //
684
-
685
- const ColumnFiltering = {
686
- getDefaultColumnDef: () => {
687
- return {
688
- filterFn: 'auto'
689
- };
690
- },
691
- getInitialState: state => {
692
- return {
693
- columnFilters: [],
694
- ...state
695
- };
696
- },
697
- getDefaultOptions: table => {
698
- return {
699
- onColumnFiltersChange: makeStateUpdater('columnFilters', table),
700
- filterFromLeafRows: false,
701
- maxLeafRowFilterDepth: 100
702
- };
703
- },
704
- createColumn: (column, table) => {
705
- column.getAutoFilterFn = () => {
706
- const firstRow = table.getCoreRowModel().flatRows[0];
707
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
708
- if (typeof value === 'string') {
709
- return filterFns.includesString;
710
- }
711
- if (typeof value === 'number') {
712
- return filterFns.inNumberRange;
713
- }
714
- if (typeof value === 'boolean') {
715
- return filterFns.equals;
716
- }
717
- if (value !== null && typeof value === 'object') {
718
- return filterFns.equals;
719
- }
720
- if (Array.isArray(value)) {
721
- return filterFns.arrIncludes;
722
- }
723
- return filterFns.weakEquals;
724
- };
725
- column.getFilterFn = () => {
726
- var _table$options$filter, _table$options$filter2;
727
- return isFunction(column.columnDef.filterFn) ? column.columnDef.filterFn : column.columnDef.filterFn === 'auto' ? column.getAutoFilterFn() : // @ts-ignore
728
- (_table$options$filter = (_table$options$filter2 = table.options.filterFns) == null ? void 0 : _table$options$filter2[column.columnDef.filterFn]) != null ? _table$options$filter : filterFns[column.columnDef.filterFn];
729
- };
730
- column.getCanFilter = () => {
731
- var _column$columnDef$ena, _table$options$enable, _table$options$enable2;
732
- return ((_column$columnDef$ena = column.columnDef.enableColumnFilter) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnFilters) != null ? _table$options$enable : true) && ((_table$options$enable2 = table.options.enableFilters) != null ? _table$options$enable2 : true) && !!column.accessorFn;
733
- };
734
- column.getIsFiltered = () => column.getFilterIndex() > -1;
735
- column.getFilterValue = () => {
736
- var _table$getState$colum;
737
- return (_table$getState$colum = table.getState().columnFilters) == null || (_table$getState$colum = _table$getState$colum.find(d => d.id === column.id)) == null ? void 0 : _table$getState$colum.value;
738
- };
739
- column.getFilterIndex = () => {
740
- var _table$getState$colum2, _table$getState$colum3;
741
- return (_table$getState$colum2 = (_table$getState$colum3 = table.getState().columnFilters) == null ? void 0 : _table$getState$colum3.findIndex(d => d.id === column.id)) != null ? _table$getState$colum2 : -1;
742
- };
743
- column.setFilterValue = value => {
744
- table.setColumnFilters(old => {
745
- const filterFn = column.getFilterFn();
746
- const previousFilter = old == null ? void 0 : old.find(d => d.id === column.id);
747
- const newFilter = functionalUpdate(value, previousFilter ? previousFilter.value : undefined);
748
-
749
- //
750
- if (shouldAutoRemoveFilter(filterFn, newFilter, column)) {
751
- var _old$filter;
752
- return (_old$filter = old == null ? void 0 : old.filter(d => d.id !== column.id)) != null ? _old$filter : [];
753
- }
754
- const newFilterObj = {
755
- id: column.id,
756
- value: newFilter
757
- };
758
- if (previousFilter) {
759
- var _old$map;
760
- return (_old$map = old == null ? void 0 : old.map(d => {
761
- if (d.id === column.id) {
762
- return newFilterObj;
763
- }
764
- return d;
765
- })) != null ? _old$map : [];
766
- }
767
- if (old != null && old.length) {
768
- return [...old, newFilterObj];
769
- }
770
- return [newFilterObj];
771
- });
772
- };
773
- },
774
- createRow: (row, _table) => {
775
- row.columnFilters = {};
776
- row.columnFiltersMeta = {};
777
- },
778
- createTable: table => {
779
- table.setColumnFilters = updater => {
780
- const leafColumns = table.getAllLeafColumns();
781
- const updateFn = old => {
782
- var _functionalUpdate;
783
- return (_functionalUpdate = functionalUpdate(updater, old)) == null ? void 0 : _functionalUpdate.filter(filter => {
784
- const column = leafColumns.find(d => d.id === filter.id);
785
- if (column) {
786
- const filterFn = column.getFilterFn();
787
- if (shouldAutoRemoveFilter(filterFn, filter.value, column)) {
788
- return false;
789
- }
790
- }
791
- return true;
792
- });
793
- };
794
- table.options.onColumnFiltersChange == null || table.options.onColumnFiltersChange(updateFn);
795
- };
796
- table.resetColumnFilters = defaultState => {
797
- var _table$initialState$c, _table$initialState;
798
- table.setColumnFilters(defaultState ? [] : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnFilters) != null ? _table$initialState$c : []);
799
- };
800
- table.getPreFilteredRowModel = () => table.getCoreRowModel();
801
- table.getFilteredRowModel = () => {
802
- if (!table._getFilteredRowModel && table.options.getFilteredRowModel) {
803
- table._getFilteredRowModel = table.options.getFilteredRowModel(table);
804
- }
805
- if (table.options.manualFiltering || !table._getFilteredRowModel) {
806
- return table.getPreFilteredRowModel();
807
- }
808
- return table._getFilteredRowModel();
809
- };
810
- }
811
- };
812
- function shouldAutoRemoveFilter(filterFn, value, column) {
813
- return (filterFn && filterFn.autoRemove ? filterFn.autoRemove(value, column) : false) || typeof value === 'undefined' || typeof value === 'string' && !value;
814
- }
815
-
816
- const sum = (columnId, _leafRows, childRows) => {
817
- // It's faster to just add the aggregations together instead of
818
- // process leaf nodes individually
819
- return childRows.reduce((sum, next) => {
820
- const nextValue = next.getValue(columnId);
821
- return sum + (typeof nextValue === 'number' ? nextValue : 0);
822
- }, 0);
823
- };
824
- const min = (columnId, _leafRows, childRows) => {
825
- let min;
826
- childRows.forEach(row => {
827
- const value = row.getValue(columnId);
828
- if (value != null && (min > value || min === undefined && value >= value)) {
829
- min = value;
830
- }
831
- });
832
- return min;
833
- };
834
- const max = (columnId, _leafRows, childRows) => {
835
- let max;
836
- childRows.forEach(row => {
837
- const value = row.getValue(columnId);
838
- if (value != null && (max < value || max === undefined && value >= value)) {
839
- max = value;
840
- }
841
- });
842
- return max;
843
- };
844
- const extent = (columnId, _leafRows, childRows) => {
845
- let min;
846
- let max;
847
- childRows.forEach(row => {
848
- const value = row.getValue(columnId);
849
- if (value != null) {
850
- if (min === undefined) {
851
- if (value >= value) min = max = value;
852
- } else {
853
- if (min > value) min = value;
854
- if (max < value) max = value;
855
- }
856
- }
857
- });
858
- return [min, max];
859
- };
860
- const mean = (columnId, leafRows) => {
861
- let count = 0;
862
- let sum = 0;
863
- leafRows.forEach(row => {
864
- let value = row.getValue(columnId);
865
- if (value != null && (value = +value) >= value) {
866
- ++count, sum += value;
867
- }
868
- });
869
- if (count) return sum / count;
870
- return;
871
- };
872
- const median = (columnId, leafRows) => {
873
- if (!leafRows.length) {
874
- return;
875
- }
876
- const values = leafRows.map(row => row.getValue(columnId));
877
- if (!isNumberArray(values)) {
878
- return;
879
- }
880
- if (values.length === 1) {
881
- return values[0];
882
- }
883
- const mid = Math.floor(values.length / 2);
884
- const nums = values.sort((a, b) => a - b);
885
- return values.length % 2 !== 0 ? nums[mid] : (nums[mid - 1] + nums[mid]) / 2;
886
- };
887
- const unique = (columnId, leafRows) => {
888
- return Array.from(new Set(leafRows.map(d => d.getValue(columnId))).values());
889
- };
890
- const uniqueCount = (columnId, leafRows) => {
891
- return new Set(leafRows.map(d => d.getValue(columnId))).size;
892
- };
893
- const count = (_columnId, leafRows) => {
894
- return leafRows.length;
895
- };
896
- const aggregationFns = {
897
- sum,
898
- min,
899
- max,
900
- extent,
901
- mean,
902
- median,
903
- unique,
904
- uniqueCount,
905
- count
906
- };
907
-
908
- //
909
-
910
- const ColumnGrouping = {
911
- getDefaultColumnDef: () => {
912
- return {
913
- aggregatedCell: props => {
914
- var _toString, _props$getValue;
915
- return (_toString = (_props$getValue = props.getValue()) == null || _props$getValue.toString == null ? void 0 : _props$getValue.toString()) != null ? _toString : null;
916
- },
917
- aggregationFn: 'auto'
918
- };
919
- },
920
- getInitialState: state => {
921
- return {
922
- grouping: [],
923
- ...state
924
- };
925
- },
926
- getDefaultOptions: table => {
927
- return {
928
- onGroupingChange: makeStateUpdater('grouping', table),
929
- groupedColumnMode: 'reorder'
930
- };
931
- },
932
- createColumn: (column, table) => {
933
- column.toggleGrouping = () => {
934
- table.setGrouping(old => {
935
- // Find any existing grouping for this column
936
- if (old != null && old.includes(column.id)) {
937
- return old.filter(d => d !== column.id);
938
- }
939
- return [...(old != null ? old : []), column.id];
940
- });
941
- };
942
- column.getCanGroup = () => {
943
- var _column$columnDef$ena, _table$options$enable;
944
- return ((_column$columnDef$ena = column.columnDef.enableGrouping) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableGrouping) != null ? _table$options$enable : true) && (!!column.accessorFn || !!column.columnDef.getGroupingValue);
945
- };
946
- column.getIsGrouped = () => {
947
- var _table$getState$group;
948
- return (_table$getState$group = table.getState().grouping) == null ? void 0 : _table$getState$group.includes(column.id);
949
- };
950
- column.getGroupedIndex = () => {
951
- var _table$getState$group2;
952
- return (_table$getState$group2 = table.getState().grouping) == null ? void 0 : _table$getState$group2.indexOf(column.id);
953
- };
954
- column.getToggleGroupingHandler = () => {
955
- const canGroup = column.getCanGroup();
956
- return () => {
957
- if (!canGroup) return;
958
- column.toggleGrouping();
959
- };
960
- };
961
- column.getAutoAggregationFn = () => {
962
- const firstRow = table.getCoreRowModel().flatRows[0];
963
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
964
- if (typeof value === 'number') {
965
- return aggregationFns.sum;
966
- }
967
- if (Object.prototype.toString.call(value) === '[object Date]') {
968
- return aggregationFns.extent;
969
- }
970
- };
971
- column.getAggregationFn = () => {
972
- var _table$options$aggreg, _table$options$aggreg2;
973
- if (!column) {
974
- throw new Error();
975
- }
976
- return isFunction(column.columnDef.aggregationFn) ? column.columnDef.aggregationFn : column.columnDef.aggregationFn === 'auto' ? column.getAutoAggregationFn() : (_table$options$aggreg = (_table$options$aggreg2 = table.options.aggregationFns) == null ? void 0 : _table$options$aggreg2[column.columnDef.aggregationFn]) != null ? _table$options$aggreg : aggregationFns[column.columnDef.aggregationFn];
977
- };
978
- },
979
- createTable: table => {
980
- table.setGrouping = updater => table.options.onGroupingChange == null ? void 0 : table.options.onGroupingChange(updater);
981
- table.resetGrouping = defaultState => {
982
- var _table$initialState$g, _table$initialState;
983
- table.setGrouping(defaultState ? [] : (_table$initialState$g = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.grouping) != null ? _table$initialState$g : []);
984
- };
985
- table.getPreGroupedRowModel = () => table.getFilteredRowModel();
986
- table.getGroupedRowModel = () => {
987
- if (!table._getGroupedRowModel && table.options.getGroupedRowModel) {
988
- table._getGroupedRowModel = table.options.getGroupedRowModel(table);
989
- }
990
- if (table.options.manualGrouping || !table._getGroupedRowModel) {
991
- return table.getPreGroupedRowModel();
992
- }
993
- return table._getGroupedRowModel();
994
- };
995
- },
996
- createRow: (row, table) => {
997
- row.getIsGrouped = () => !!row.groupingColumnId;
998
- row.getGroupingValue = columnId => {
999
- if (row._groupingValuesCache.hasOwnProperty(columnId)) {
1000
- return row._groupingValuesCache[columnId];
1001
- }
1002
- const column = table.getColumn(columnId);
1003
- if (!(column != null && column.columnDef.getGroupingValue)) {
1004
- return row.getValue(columnId);
1005
- }
1006
- row._groupingValuesCache[columnId] = column.columnDef.getGroupingValue(row.original);
1007
- return row._groupingValuesCache[columnId];
1008
- };
1009
- row._groupingValuesCache = {};
1010
- },
1011
- createCell: (cell, column, row, table) => {
1012
- cell.getIsGrouped = () => column.getIsGrouped() && column.id === row.groupingColumnId;
1013
- cell.getIsPlaceholder = () => !cell.getIsGrouped() && column.getIsGrouped();
1014
- cell.getIsAggregated = () => {
1015
- var _row$subRows;
1016
- return !cell.getIsGrouped() && !cell.getIsPlaceholder() && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
1017
- };
1018
- }
1019
- };
1020
- function orderColumns(leafColumns, grouping, groupedColumnMode) {
1021
- if (!(grouping != null && grouping.length) || !groupedColumnMode) {
1022
- return leafColumns;
1023
- }
1024
- const nonGroupingColumns = leafColumns.filter(col => !grouping.includes(col.id));
1025
- if (groupedColumnMode === 'remove') {
1026
- return nonGroupingColumns;
1027
- }
1028
- const groupingColumns = grouping.map(g => leafColumns.find(col => col.id === g)).filter(Boolean);
1029
- return [...groupingColumns, ...nonGroupingColumns];
1030
- }
1031
-
1032
- //
1033
-
1034
- const ColumnOrdering = {
1035
- getInitialState: state => {
1036
- return {
1037
- columnOrder: [],
1038
- ...state
1039
- };
1040
- },
1041
- getDefaultOptions: table => {
1042
- return {
1043
- onColumnOrderChange: makeStateUpdater('columnOrder', table)
1044
- };
1045
- },
1046
- createColumn: (column, table) => {
1047
- column.getIndex = memo(position => [_getVisibleLeafColumns(table, position)], columns => columns.findIndex(d => d.id === column.id), getMemoOptions(table.options, 'debugColumns', 'getIndex'));
1048
- column.getIsFirstColumn = position => {
1049
- var _columns$;
1050
- const columns = _getVisibleLeafColumns(table, position);
1051
- return ((_columns$ = columns[0]) == null ? void 0 : _columns$.id) === column.id;
1052
- };
1053
- column.getIsLastColumn = position => {
1054
- var _columns;
1055
- const columns = _getVisibleLeafColumns(table, position);
1056
- return ((_columns = columns[columns.length - 1]) == null ? void 0 : _columns.id) === column.id;
1057
- };
1058
- },
1059
- createTable: table => {
1060
- table.setColumnOrder = updater => table.options.onColumnOrderChange == null ? void 0 : table.options.onColumnOrderChange(updater);
1061
- table.resetColumnOrder = defaultState => {
1062
- var _table$initialState$c;
1063
- table.setColumnOrder(defaultState ? [] : (_table$initialState$c = table.initialState.columnOrder) != null ? _table$initialState$c : []);
1064
- };
1065
- table._getOrderColumnsFn = memo(() => [table.getState().columnOrder, table.getState().grouping, table.options.groupedColumnMode], (columnOrder, grouping, groupedColumnMode) => columns => {
1066
- // Sort grouped columns to the start of the column list
1067
- // before the headers are built
1068
- let orderedColumns = [];
1069
-
1070
- // If there is no order, return the normal columns
1071
- if (!(columnOrder != null && columnOrder.length)) {
1072
- orderedColumns = columns;
1073
- } else {
1074
- const columnOrderCopy = [...columnOrder];
1075
-
1076
- // If there is an order, make a copy of the columns
1077
- const columnsCopy = [...columns];
1078
-
1079
- // And make a new ordered array of the columns
1080
-
1081
- // Loop over the columns and place them in order into the new array
1082
- while (columnsCopy.length && columnOrderCopy.length) {
1083
- const targetColumnId = columnOrderCopy.shift();
1084
- const foundIndex = columnsCopy.findIndex(d => d.id === targetColumnId);
1085
- if (foundIndex > -1) {
1086
- orderedColumns.push(columnsCopy.splice(foundIndex, 1)[0]);
1087
- }
1088
- }
1089
-
1090
- // If there are any columns left, add them to the end
1091
- orderedColumns = [...orderedColumns, ...columnsCopy];
1092
- }
1093
- return orderColumns(orderedColumns, grouping, groupedColumnMode);
1094
- }, getMemoOptions(table.options, 'debugTable', '_getOrderColumnsFn'));
1095
- }
1096
- };
1097
-
1098
- //
1099
-
1100
- const getDefaultColumnPinningState = () => ({
1101
- left: [],
1102
- right: []
1103
- });
1104
- const ColumnPinning = {
1105
- getInitialState: state => {
1106
- return {
1107
- columnPinning: getDefaultColumnPinningState(),
1108
- ...state
1109
- };
1110
- },
1111
- getDefaultOptions: table => {
1112
- return {
1113
- onColumnPinningChange: makeStateUpdater('columnPinning', table)
1114
- };
1115
- },
1116
- createColumn: (column, table) => {
1117
- column.pin = position => {
1118
- const columnIds = column.getLeafColumns().map(d => d.id).filter(Boolean);
1119
- table.setColumnPinning(old => {
1120
- var _old$left3, _old$right3;
1121
- if (position === 'right') {
1122
- var _old$left, _old$right;
1123
- return {
1124
- left: ((_old$left = old == null ? void 0 : old.left) != null ? _old$left : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1125
- right: [...((_old$right = old == null ? void 0 : old.right) != null ? _old$right : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds]
1126
- };
1127
- }
1128
- if (position === 'left') {
1129
- var _old$left2, _old$right2;
1130
- return {
1131
- left: [...((_old$left2 = old == null ? void 0 : old.left) != null ? _old$left2 : []).filter(d => !(columnIds != null && columnIds.includes(d))), ...columnIds],
1132
- right: ((_old$right2 = old == null ? void 0 : old.right) != null ? _old$right2 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1133
- };
1134
- }
1135
- return {
1136
- left: ((_old$left3 = old == null ? void 0 : old.left) != null ? _old$left3 : []).filter(d => !(columnIds != null && columnIds.includes(d))),
1137
- right: ((_old$right3 = old == null ? void 0 : old.right) != null ? _old$right3 : []).filter(d => !(columnIds != null && columnIds.includes(d)))
1138
- };
1139
- });
1140
- };
1141
- column.getCanPin = () => {
1142
- const leafColumns = column.getLeafColumns();
1143
- return leafColumns.some(d => {
1144
- var _d$columnDef$enablePi, _ref, _table$options$enable;
1145
- return ((_d$columnDef$enablePi = d.columnDef.enablePinning) != null ? _d$columnDef$enablePi : true) && ((_ref = (_table$options$enable = table.options.enableColumnPinning) != null ? _table$options$enable : table.options.enablePinning) != null ? _ref : true);
1146
- });
1147
- };
1148
- column.getIsPinned = () => {
1149
- const leafColumnIds = column.getLeafColumns().map(d => d.id);
1150
- const {
1151
- left,
1152
- right
1153
- } = table.getState().columnPinning;
1154
- const isLeft = leafColumnIds.some(d => left == null ? void 0 : left.includes(d));
1155
- const isRight = leafColumnIds.some(d => right == null ? void 0 : right.includes(d));
1156
- return isLeft ? 'left' : isRight ? 'right' : false;
1157
- };
1158
- column.getPinnedIndex = () => {
1159
- var _table$getState$colum, _table$getState$colum2;
1160
- const position = column.getIsPinned();
1161
- return position ? (_table$getState$colum = (_table$getState$colum2 = table.getState().columnPinning) == null || (_table$getState$colum2 = _table$getState$colum2[position]) == null ? void 0 : _table$getState$colum2.indexOf(column.id)) != null ? _table$getState$colum : -1 : 0;
1162
- };
1163
- },
1164
- createRow: (row, table) => {
1165
- row.getCenterVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allCells, left, right) => {
1166
- const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1167
- return allCells.filter(d => !leftAndRight.includes(d.column.id));
1168
- }, getMemoOptions(table.options, 'debugRows', 'getCenterVisibleCells'));
1169
- row.getLeftVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.left], (allCells, left) => {
1170
- const cells = (left != null ? left : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1171
- ...d,
1172
- position: 'left'
1173
- }));
1174
- return cells;
1175
- }, getMemoOptions(table.options, 'debugRows', 'getLeftVisibleCells'));
1176
- row.getRightVisibleCells = memo(() => [row._getAllVisibleCells(), table.getState().columnPinning.right], (allCells, right) => {
1177
- const cells = (right != null ? right : []).map(columnId => allCells.find(cell => cell.column.id === columnId)).filter(Boolean).map(d => ({
1178
- ...d,
1179
- position: 'right'
1180
- }));
1181
- return cells;
1182
- }, getMemoOptions(table.options, 'debugRows', 'getRightVisibleCells'));
1183
- },
1184
- createTable: table => {
1185
- table.setColumnPinning = updater => table.options.onColumnPinningChange == null ? void 0 : table.options.onColumnPinningChange(updater);
1186
- table.resetColumnPinning = defaultState => {
1187
- var _table$initialState$c, _table$initialState;
1188
- return table.setColumnPinning(defaultState ? getDefaultColumnPinningState() : (_table$initialState$c = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.columnPinning) != null ? _table$initialState$c : getDefaultColumnPinningState());
1189
- };
1190
- table.getIsSomeColumnsPinned = position => {
1191
- var _pinningState$positio;
1192
- const pinningState = table.getState().columnPinning;
1193
- if (!position) {
1194
- var _pinningState$left, _pinningState$right;
1195
- return Boolean(((_pinningState$left = pinningState.left) == null ? void 0 : _pinningState$left.length) || ((_pinningState$right = pinningState.right) == null ? void 0 : _pinningState$right.length));
1196
- }
1197
- return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
1198
- };
1199
- table.getLeftLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left], (allColumns, left) => {
1200
- return (left != null ? left : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1201
- }, getMemoOptions(table.options, 'debugColumns', 'getLeftLeafColumns'));
1202
- table.getRightLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.right], (allColumns, right) => {
1203
- return (right != null ? right : []).map(columnId => allColumns.find(column => column.id === columnId)).filter(Boolean);
1204
- }, getMemoOptions(table.options, 'debugColumns', 'getRightLeafColumns'));
1205
- table.getCenterLeafColumns = memo(() => [table.getAllLeafColumns(), table.getState().columnPinning.left, table.getState().columnPinning.right], (allColumns, left, right) => {
1206
- const leftAndRight = [...(left != null ? left : []), ...(right != null ? right : [])];
1207
- return allColumns.filter(d => !leftAndRight.includes(d.id));
1208
- }, getMemoOptions(table.options, 'debugColumns', 'getCenterLeafColumns'));
1209
- }
1210
- };
1211
-
1212
- //
1213
-
1214
- //
1215
-
1216
- const defaultColumnSizing = {
1217
- size: 150,
1218
- minSize: 20,
1219
- maxSize: Number.MAX_SAFE_INTEGER
1220
- };
1221
- const getDefaultColumnSizingInfoState = () => ({
1222
- startOffset: null,
1223
- startSize: null,
1224
- deltaOffset: null,
1225
- deltaPercentage: null,
1226
- isResizingColumn: false,
1227
- columnSizingStart: []
1228
- });
1229
- const ColumnSizing = {
1230
- getDefaultColumnDef: () => {
1231
- return defaultColumnSizing;
1232
- },
1233
- getInitialState: state => {
1234
- return {
1235
- columnSizing: {},
1236
- columnSizingInfo: getDefaultColumnSizingInfoState(),
1237
- ...state
1238
- };
1239
- },
1240
- getDefaultOptions: table => {
1241
- return {
1242
- columnResizeMode: 'onEnd',
1243
- columnResizeDirection: 'ltr',
1244
- onColumnSizingChange: makeStateUpdater('columnSizing', table),
1245
- onColumnSizingInfoChange: makeStateUpdater('columnSizingInfo', table)
1246
- };
1247
- },
1248
- createColumn: (column, table) => {
1249
- column.getSize = () => {
1250
- var _column$columnDef$min, _ref, _column$columnDef$max;
1251
- const columnSize = table.getState().columnSizing[column.id];
1252
- return Math.min(Math.max((_column$columnDef$min = column.columnDef.minSize) != null ? _column$columnDef$min : defaultColumnSizing.minSize, (_ref = columnSize != null ? columnSize : column.columnDef.size) != null ? _ref : defaultColumnSizing.size), (_column$columnDef$max = column.columnDef.maxSize) != null ? _column$columnDef$max : defaultColumnSizing.maxSize);
1253
- };
1254
- column.getStart = memo(position => [position, _getVisibleLeafColumns(table, position), table.getState().columnSizing], (position, columns) => columns.slice(0, column.getIndex(position)).reduce((sum, column) => sum + column.getSize(), 0), getMemoOptions(table.options, 'debugColumns', 'getStart'));
1255
- column.getAfter = memo(position => [position, _getVisibleLeafColumns(table, position), table.getState().columnSizing], (position, columns) => columns.slice(column.getIndex(position) + 1).reduce((sum, column) => sum + column.getSize(), 0), getMemoOptions(table.options, 'debugColumns', 'getAfter'));
1256
- column.resetSize = () => {
1257
- table.setColumnSizing(_ref2 => {
1258
- let {
1259
- [column.id]: _,
1260
- ...rest
1261
- } = _ref2;
1262
- return rest;
1263
- });
1264
- };
1265
- column.getCanResize = () => {
1266
- var _column$columnDef$ena, _table$options$enable;
1267
- return ((_column$columnDef$ena = column.columnDef.enableResizing) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableColumnResizing) != null ? _table$options$enable : true);
1268
- };
1269
- column.getIsResizing = () => {
1270
- return table.getState().columnSizingInfo.isResizingColumn === column.id;
1271
- };
1272
- },
1273
- createHeader: (header, table) => {
1274
- header.getSize = () => {
1275
- let sum = 0;
1276
- const recurse = header => {
1277
- if (header.subHeaders.length) {
1278
- header.subHeaders.forEach(recurse);
1279
- } else {
1280
- var _header$column$getSiz;
1281
- sum += (_header$column$getSiz = header.column.getSize()) != null ? _header$column$getSiz : 0;
1282
- }
1283
- };
1284
- recurse(header);
1285
- return sum;
1286
- };
1287
- header.getStart = () => {
1288
- if (header.index > 0) {
1289
- const prevSiblingHeader = header.headerGroup.headers[header.index - 1];
1290
- return prevSiblingHeader.getStart() + prevSiblingHeader.getSize();
1291
- }
1292
- return 0;
1293
- };
1294
- header.getResizeHandler = _contextDocument => {
1295
- const column = table.getColumn(header.column.id);
1296
- const canResize = column == null ? void 0 : column.getCanResize();
1297
- return e => {
1298
- if (!column || !canResize) {
1299
- return;
1300
- }
1301
- e.persist == null || e.persist();
1302
- if (isTouchStartEvent(e)) {
1303
- // lets not respond to multiple touches (e.g. 2 or 3 fingers)
1304
- if (e.touches && e.touches.length > 1) {
1305
- return;
1306
- }
1307
- }
1308
- const startSize = header.getSize();
1309
- const columnSizingStart = header ? header.getLeafHeaders().map(d => [d.column.id, d.column.getSize()]) : [[column.id, column.getSize()]];
1310
- const clientX = isTouchStartEvent(e) ? Math.round(e.touches[0].clientX) : e.clientX;
1311
- const newColumnSizing = {};
1312
- const updateOffset = (eventType, clientXPos) => {
1313
- if (typeof clientXPos !== 'number') {
1314
- return;
1315
- }
1316
- table.setColumnSizingInfo(old => {
1317
- var _old$startOffset, _old$startSize;
1318
- const deltaDirection = table.options.columnResizeDirection === 'rtl' ? -1 : 1;
1319
- const deltaOffset = (clientXPos - ((_old$startOffset = old == null ? void 0 : old.startOffset) != null ? _old$startOffset : 0)) * deltaDirection;
1320
- const deltaPercentage = Math.max(deltaOffset / ((_old$startSize = old == null ? void 0 : old.startSize) != null ? _old$startSize : 0), -0.999999);
1321
- old.columnSizingStart.forEach(_ref3 => {
1322
- let [columnId, headerSize] = _ref3;
1323
- newColumnSizing[columnId] = Math.round(Math.max(headerSize + headerSize * deltaPercentage, 0) * 100) / 100;
1324
- });
1325
- return {
1326
- ...old,
1327
- deltaOffset,
1328
- deltaPercentage
1329
- };
1330
- });
1331
- if (table.options.columnResizeMode === 'onChange' || eventType === 'end') {
1332
- table.setColumnSizing(old => ({
1333
- ...old,
1334
- ...newColumnSizing
1335
- }));
1336
- }
1337
- };
1338
- const onMove = clientXPos => updateOffset('move', clientXPos);
1339
- const onEnd = clientXPos => {
1340
- updateOffset('end', clientXPos);
1341
- table.setColumnSizingInfo(old => ({
1342
- ...old,
1343
- isResizingColumn: false,
1344
- startOffset: null,
1345
- startSize: null,
1346
- deltaOffset: null,
1347
- deltaPercentage: null,
1348
- columnSizingStart: []
1349
- }));
1350
- };
1351
- const contextDocument = _contextDocument || typeof document !== 'undefined' ? document : null;
1352
- const mouseEvents = {
1353
- moveHandler: e => onMove(e.clientX),
1354
- upHandler: e => {
1355
- contextDocument == null || contextDocument.removeEventListener('mousemove', mouseEvents.moveHandler);
1356
- contextDocument == null || contextDocument.removeEventListener('mouseup', mouseEvents.upHandler);
1357
- onEnd(e.clientX);
1358
- }
1359
- };
1360
- const touchEvents = {
1361
- moveHandler: e => {
1362
- if (e.cancelable) {
1363
- e.preventDefault();
1364
- e.stopPropagation();
1365
- }
1366
- onMove(e.touches[0].clientX);
1367
- return false;
1368
- },
1369
- upHandler: e => {
1370
- var _e$touches$;
1371
- contextDocument == null || contextDocument.removeEventListener('touchmove', touchEvents.moveHandler);
1372
- contextDocument == null || contextDocument.removeEventListener('touchend', touchEvents.upHandler);
1373
- if (e.cancelable) {
1374
- e.preventDefault();
1375
- e.stopPropagation();
1376
- }
1377
- onEnd((_e$touches$ = e.touches[0]) == null ? void 0 : _e$touches$.clientX);
1378
- }
1379
- };
1380
- const passiveIfSupported = passiveEventSupported() ? {
1381
- passive: false
1382
- } : false;
1383
- if (isTouchStartEvent(e)) {
1384
- contextDocument == null || contextDocument.addEventListener('touchmove', touchEvents.moveHandler, passiveIfSupported);
1385
- contextDocument == null || contextDocument.addEventListener('touchend', touchEvents.upHandler, passiveIfSupported);
1386
- } else {
1387
- contextDocument == null || contextDocument.addEventListener('mousemove', mouseEvents.moveHandler, passiveIfSupported);
1388
- contextDocument == null || contextDocument.addEventListener('mouseup', mouseEvents.upHandler, passiveIfSupported);
1389
- }
1390
- table.setColumnSizingInfo(old => ({
1391
- ...old,
1392
- startOffset: clientX,
1393
- startSize,
1394
- deltaOffset: 0,
1395
- deltaPercentage: 0,
1396
- columnSizingStart,
1397
- isResizingColumn: column.id
1398
- }));
1399
- };
1400
- };
1401
- },
1402
- createTable: table => {
1403
- table.setColumnSizing = updater => table.options.onColumnSizingChange == null ? void 0 : table.options.onColumnSizingChange(updater);
1404
- table.setColumnSizingInfo = updater => table.options.onColumnSizingInfoChange == null ? void 0 : table.options.onColumnSizingInfoChange(updater);
1405
- table.resetColumnSizing = defaultState => {
1406
- var _table$initialState$c;
1407
- table.setColumnSizing(defaultState ? {} : (_table$initialState$c = table.initialState.columnSizing) != null ? _table$initialState$c : {});
1408
- };
1409
- table.resetHeaderSizeInfo = defaultState => {
1410
- var _table$initialState$c2;
1411
- table.setColumnSizingInfo(defaultState ? getDefaultColumnSizingInfoState() : (_table$initialState$c2 = table.initialState.columnSizingInfo) != null ? _table$initialState$c2 : getDefaultColumnSizingInfoState());
1412
- };
1413
- table.getTotalSize = () => {
1414
- var _table$getHeaderGroup, _table$getHeaderGroup2;
1415
- return (_table$getHeaderGroup = (_table$getHeaderGroup2 = table.getHeaderGroups()[0]) == null ? void 0 : _table$getHeaderGroup2.headers.reduce((sum, header) => {
1416
- return sum + header.getSize();
1417
- }, 0)) != null ? _table$getHeaderGroup : 0;
1418
- };
1419
- table.getLeftTotalSize = () => {
1420
- var _table$getLeftHeaderG, _table$getLeftHeaderG2;
1421
- return (_table$getLeftHeaderG = (_table$getLeftHeaderG2 = table.getLeftHeaderGroups()[0]) == null ? void 0 : _table$getLeftHeaderG2.headers.reduce((sum, header) => {
1422
- return sum + header.getSize();
1423
- }, 0)) != null ? _table$getLeftHeaderG : 0;
1424
- };
1425
- table.getCenterTotalSize = () => {
1426
- var _table$getCenterHeade, _table$getCenterHeade2;
1427
- return (_table$getCenterHeade = (_table$getCenterHeade2 = table.getCenterHeaderGroups()[0]) == null ? void 0 : _table$getCenterHeade2.headers.reduce((sum, header) => {
1428
- return sum + header.getSize();
1429
- }, 0)) != null ? _table$getCenterHeade : 0;
1430
- };
1431
- table.getRightTotalSize = () => {
1432
- var _table$getRightHeader, _table$getRightHeader2;
1433
- return (_table$getRightHeader = (_table$getRightHeader2 = table.getRightHeaderGroups()[0]) == null ? void 0 : _table$getRightHeader2.headers.reduce((sum, header) => {
1434
- return sum + header.getSize();
1435
- }, 0)) != null ? _table$getRightHeader : 0;
1436
- };
1437
- }
1438
- };
1439
- let passiveSupported = null;
1440
- function passiveEventSupported() {
1441
- if (typeof passiveSupported === 'boolean') return passiveSupported;
1442
- let supported = false;
1443
- try {
1444
- const options = {
1445
- get passive() {
1446
- supported = true;
1447
- return false;
1448
- }
1449
- };
1450
- const noop = () => {};
1451
- window.addEventListener('test', noop, options);
1452
- window.removeEventListener('test', noop);
1453
- } catch (err) {
1454
- supported = false;
1455
- }
1456
- passiveSupported = supported;
1457
- return passiveSupported;
1458
- }
1459
- function isTouchStartEvent(e) {
1460
- return e.type === 'touchstart';
1461
- }
1462
-
1463
- //
1464
-
1465
- const ColumnVisibility = {
1466
- getInitialState: state => {
1467
- return {
1468
- columnVisibility: {},
1469
- ...state
1470
- };
1471
- },
1472
- getDefaultOptions: table => {
1473
- return {
1474
- onColumnVisibilityChange: makeStateUpdater('columnVisibility', table)
1475
- };
1476
- },
1477
- createColumn: (column, table) => {
1478
- column.toggleVisibility = value => {
1479
- if (column.getCanHide()) {
1480
- table.setColumnVisibility(old => ({
1481
- ...old,
1482
- [column.id]: value != null ? value : !column.getIsVisible()
1483
- }));
1484
- }
1485
- };
1486
- column.getIsVisible = () => {
1487
- var _ref, _table$getState$colum;
1488
- const childColumns = column.columns;
1489
- return (_ref = childColumns.length ? childColumns.some(c => c.getIsVisible()) : (_table$getState$colum = table.getState().columnVisibility) == null ? void 0 : _table$getState$colum[column.id]) != null ? _ref : true;
1490
- };
1491
- column.getCanHide = () => {
1492
- var _column$columnDef$ena, _table$options$enable;
1493
- return ((_column$columnDef$ena = column.columnDef.enableHiding) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableHiding) != null ? _table$options$enable : true);
1494
- };
1495
- column.getToggleVisibilityHandler = () => {
1496
- return e => {
1497
- column.toggleVisibility == null || column.toggleVisibility(e.target.checked);
1498
- };
1499
- };
1500
- },
1501
- createRow: (row, table) => {
1502
- row._getAllVisibleCells = memo(() => [row.getAllCells(), table.getState().columnVisibility], cells => {
1503
- return cells.filter(cell => cell.column.getIsVisible());
1504
- }, getMemoOptions(table.options, 'debugRows', '_getAllVisibleCells'));
1505
- row.getVisibleCells = memo(() => [row.getLeftVisibleCells(), row.getCenterVisibleCells(), row.getRightVisibleCells()], (left, center, right) => [...left, ...center, ...right], getMemoOptions(table.options, 'debugRows', 'getVisibleCells'));
1506
- },
1507
- createTable: table => {
1508
- const makeVisibleColumnsMethod = (key, getColumns) => {
1509
- return memo(() => [getColumns(), getColumns().filter(d => d.getIsVisible()).map(d => d.id).join('_')], columns => {
1510
- return columns.filter(d => d.getIsVisible == null ? void 0 : d.getIsVisible());
1511
- }, getMemoOptions(table.options, 'debugColumns', key));
1512
- };
1513
- table.getVisibleFlatColumns = makeVisibleColumnsMethod('getVisibleFlatColumns', () => table.getAllFlatColumns());
1514
- table.getVisibleLeafColumns = makeVisibleColumnsMethod('getVisibleLeafColumns', () => table.getAllLeafColumns());
1515
- table.getLeftVisibleLeafColumns = makeVisibleColumnsMethod('getLeftVisibleLeafColumns', () => table.getLeftLeafColumns());
1516
- table.getRightVisibleLeafColumns = makeVisibleColumnsMethod('getRightVisibleLeafColumns', () => table.getRightLeafColumns());
1517
- table.getCenterVisibleLeafColumns = makeVisibleColumnsMethod('getCenterVisibleLeafColumns', () => table.getCenterLeafColumns());
1518
- table.setColumnVisibility = updater => table.options.onColumnVisibilityChange == null ? void 0 : table.options.onColumnVisibilityChange(updater);
1519
- table.resetColumnVisibility = defaultState => {
1520
- var _table$initialState$c;
1521
- table.setColumnVisibility(defaultState ? {} : (_table$initialState$c = table.initialState.columnVisibility) != null ? _table$initialState$c : {});
1522
- };
1523
- table.toggleAllColumnsVisible = value => {
1524
- var _value;
1525
- value = (_value = value) != null ? _value : !table.getIsAllColumnsVisible();
1526
- table.setColumnVisibility(table.getAllLeafColumns().reduce((obj, column) => ({
1527
- ...obj,
1528
- [column.id]: !value ? !(column.getCanHide != null && column.getCanHide()) : value
1529
- }), {}));
1530
- };
1531
- table.getIsAllColumnsVisible = () => !table.getAllLeafColumns().some(column => !(column.getIsVisible != null && column.getIsVisible()));
1532
- table.getIsSomeColumnsVisible = () => table.getAllLeafColumns().some(column => column.getIsVisible == null ? void 0 : column.getIsVisible());
1533
- table.getToggleAllColumnsVisibilityHandler = () => {
1534
- return e => {
1535
- var _target;
1536
- table.toggleAllColumnsVisible((_target = e.target) == null ? void 0 : _target.checked);
1537
- };
1538
- };
1539
- }
1540
- };
1541
- function _getVisibleLeafColumns(table, position) {
1542
- return !position ? table.getVisibleLeafColumns() : position === 'center' ? table.getCenterVisibleLeafColumns() : position === 'left' ? table.getLeftVisibleLeafColumns() : table.getRightVisibleLeafColumns();
1543
- }
1544
-
1545
- //
1546
-
1547
- const GlobalFaceting = {
1548
- createTable: table => {
1549
- table._getGlobalFacetedRowModel = table.options.getFacetedRowModel && table.options.getFacetedRowModel(table, '__global__');
1550
- table.getGlobalFacetedRowModel = () => {
1551
- if (table.options.manualFiltering || !table._getGlobalFacetedRowModel) {
1552
- return table.getPreFilteredRowModel();
1553
- }
1554
- return table._getGlobalFacetedRowModel();
1555
- };
1556
- table._getGlobalFacetedUniqueValues = table.options.getFacetedUniqueValues && table.options.getFacetedUniqueValues(table, '__global__');
1557
- table.getGlobalFacetedUniqueValues = () => {
1558
- if (!table._getGlobalFacetedUniqueValues) {
1559
- return new Map();
1560
- }
1561
- return table._getGlobalFacetedUniqueValues();
1562
- };
1563
- table._getGlobalFacetedMinMaxValues = table.options.getFacetedMinMaxValues && table.options.getFacetedMinMaxValues(table, '__global__');
1564
- table.getGlobalFacetedMinMaxValues = () => {
1565
- if (!table._getGlobalFacetedMinMaxValues) {
1566
- return;
1567
- }
1568
- return table._getGlobalFacetedMinMaxValues();
1569
- };
1570
- }
1571
- };
1572
-
1573
- //
1574
-
1575
- const GlobalFiltering = {
1576
- getInitialState: state => {
1577
- return {
1578
- globalFilter: undefined,
1579
- ...state
1580
- };
1581
- },
1582
- getDefaultOptions: table => {
1583
- return {
1584
- onGlobalFilterChange: makeStateUpdater('globalFilter', table),
1585
- globalFilterFn: 'auto',
1586
- getColumnCanGlobalFilter: column => {
1587
- var _table$getCoreRowMode;
1588
- const value = (_table$getCoreRowMode = table.getCoreRowModel().flatRows[0]) == null || (_table$getCoreRowMode = _table$getCoreRowMode._getAllCellsByColumnId()[column.id]) == null ? void 0 : _table$getCoreRowMode.getValue();
1589
- return typeof value === 'string' || typeof value === 'number';
1590
- }
1591
- };
1592
- },
1593
- createColumn: (column, table) => {
1594
- column.getCanGlobalFilter = () => {
1595
- var _column$columnDef$ena, _table$options$enable, _table$options$enable2, _table$options$getCol;
1596
- return ((_column$columnDef$ena = column.columnDef.enableGlobalFilter) != null ? _column$columnDef$ena : true) && ((_table$options$enable = table.options.enableGlobalFilter) != null ? _table$options$enable : true) && ((_table$options$enable2 = table.options.enableFilters) != null ? _table$options$enable2 : true) && ((_table$options$getCol = table.options.getColumnCanGlobalFilter == null ? void 0 : table.options.getColumnCanGlobalFilter(column)) != null ? _table$options$getCol : true) && !!column.accessorFn;
1597
- };
1598
- },
1599
- createTable: table => {
1600
- table.getGlobalAutoFilterFn = () => {
1601
- return filterFns.includesString;
1602
- };
1603
- table.getGlobalFilterFn = () => {
1604
- var _table$options$filter, _table$options$filter2;
1605
- const {
1606
- globalFilterFn: globalFilterFn
1607
- } = table.options;
1608
- return isFunction(globalFilterFn) ? globalFilterFn : globalFilterFn === 'auto' ? table.getGlobalAutoFilterFn() : (_table$options$filter = (_table$options$filter2 = table.options.filterFns) == null ? void 0 : _table$options$filter2[globalFilterFn]) != null ? _table$options$filter : filterFns[globalFilterFn];
1609
- };
1610
- table.setGlobalFilter = updater => {
1611
- table.options.onGlobalFilterChange == null || table.options.onGlobalFilterChange(updater);
1612
- };
1613
- table.resetGlobalFilter = defaultState => {
1614
- table.setGlobalFilter(defaultState ? undefined : table.initialState.globalFilter);
1615
- };
1616
- }
1617
- };
1618
-
1619
- //
1620
-
1621
- const RowExpanding = {
1622
- getInitialState: state => {
1623
- return {
1624
- expanded: {},
1625
- ...state
1626
- };
1627
- },
1628
- getDefaultOptions: table => {
1629
- return {
1630
- onExpandedChange: makeStateUpdater('expanded', table),
1631
- paginateExpandedRows: true
1632
- };
1633
- },
1634
- createTable: table => {
1635
- let registered = false;
1636
- let queued = false;
1637
- table._autoResetExpanded = () => {
1638
- var _ref, _table$options$autoRe;
1639
- if (!registered) {
1640
- table._queue(() => {
1641
- registered = true;
1642
- });
1643
- return;
1644
- }
1645
- if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetExpanded) != null ? _ref : !table.options.manualExpanding) {
1646
- if (queued) return;
1647
- queued = true;
1648
- table._queue(() => {
1649
- table.resetExpanded();
1650
- queued = false;
1651
- });
1652
- }
1653
- };
1654
- table.setExpanded = updater => table.options.onExpandedChange == null ? void 0 : table.options.onExpandedChange(updater);
1655
- table.toggleAllRowsExpanded = expanded => {
1656
- if (expanded != null ? expanded : !table.getIsAllRowsExpanded()) {
1657
- table.setExpanded(true);
1658
- } else {
1659
- table.setExpanded({});
1660
- }
1661
- };
1662
- table.resetExpanded = defaultState => {
1663
- var _table$initialState$e, _table$initialState;
1664
- table.setExpanded(defaultState ? {} : (_table$initialState$e = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.expanded) != null ? _table$initialState$e : {});
1665
- };
1666
- table.getCanSomeRowsExpand = () => {
1667
- return table.getPrePaginationRowModel().flatRows.some(row => row.getCanExpand());
1668
- };
1669
- table.getToggleAllRowsExpandedHandler = () => {
1670
- return e => {
1671
- e.persist == null || e.persist();
1672
- table.toggleAllRowsExpanded();
1673
- };
1674
- };
1675
- table.getIsSomeRowsExpanded = () => {
1676
- const expanded = table.getState().expanded;
1677
- return expanded === true || Object.values(expanded).some(Boolean);
1678
- };
1679
- table.getIsAllRowsExpanded = () => {
1680
- const expanded = table.getState().expanded;
1681
-
1682
- // If expanded is true, save some cycles and return true
1683
- if (typeof expanded === 'boolean') {
1684
- return expanded === true;
1685
- }
1686
- if (!Object.keys(expanded).length) {
1687
- return false;
1688
- }
1689
-
1690
- // If any row is not expanded, return false
1691
- if (table.getRowModel().flatRows.some(row => !row.getIsExpanded())) {
1692
- return false;
1693
- }
1694
-
1695
- // They must all be expanded :shrug:
1696
- return true;
1697
- };
1698
- table.getExpandedDepth = () => {
1699
- let maxDepth = 0;
1700
- const rowIds = table.getState().expanded === true ? Object.keys(table.getRowModel().rowsById) : Object.keys(table.getState().expanded);
1701
- rowIds.forEach(id => {
1702
- const splitId = id.split('.');
1703
- maxDepth = Math.max(maxDepth, splitId.length);
1704
- });
1705
- return maxDepth;
1706
- };
1707
- table.getPreExpandedRowModel = () => table.getSortedRowModel();
1708
- table.getExpandedRowModel = () => {
1709
- if (!table._getExpandedRowModel && table.options.getExpandedRowModel) {
1710
- table._getExpandedRowModel = table.options.getExpandedRowModel(table);
1711
- }
1712
- if (table.options.manualExpanding || !table._getExpandedRowModel) {
1713
- return table.getPreExpandedRowModel();
1714
- }
1715
- return table._getExpandedRowModel();
1716
- };
1717
- },
1718
- createRow: (row, table) => {
1719
- row.toggleExpanded = expanded => {
1720
- table.setExpanded(old => {
1721
- var _expanded;
1722
- const exists = old === true ? true : !!(old != null && old[row.id]);
1723
- let oldExpanded = {};
1724
- if (old === true) {
1725
- Object.keys(table.getRowModel().rowsById).forEach(rowId => {
1726
- oldExpanded[rowId] = true;
1727
- });
1728
- } else {
1729
- oldExpanded = old;
1730
- }
1731
- expanded = (_expanded = expanded) != null ? _expanded : !exists;
1732
- if (!exists && expanded) {
1733
- return {
1734
- ...oldExpanded,
1735
- [row.id]: true
1736
- };
1737
- }
1738
- if (exists && !expanded) {
1739
- const {
1740
- [row.id]: _,
1741
- ...rest
1742
- } = oldExpanded;
1743
- return rest;
1744
- }
1745
- return old;
1746
- });
1747
- };
1748
- row.getIsExpanded = () => {
1749
- var _table$options$getIsR;
1750
- const expanded = table.getState().expanded;
1751
- return !!((_table$options$getIsR = table.options.getIsRowExpanded == null ? void 0 : table.options.getIsRowExpanded(row)) != null ? _table$options$getIsR : expanded === true || (expanded == null ? void 0 : expanded[row.id]));
1752
- };
1753
- row.getCanExpand = () => {
1754
- var _table$options$getRow, _table$options$enable, _row$subRows;
1755
- return (_table$options$getRow = table.options.getRowCanExpand == null ? void 0 : table.options.getRowCanExpand(row)) != null ? _table$options$getRow : ((_table$options$enable = table.options.enableExpanding) != null ? _table$options$enable : true) && !!((_row$subRows = row.subRows) != null && _row$subRows.length);
1756
- };
1757
- row.getIsAllParentsExpanded = () => {
1758
- let isFullyExpanded = true;
1759
- let currentRow = row;
1760
- while (isFullyExpanded && currentRow.parentId) {
1761
- currentRow = table.getRow(currentRow.parentId, true);
1762
- isFullyExpanded = currentRow.getIsExpanded();
1763
- }
1764
- return isFullyExpanded;
1765
- };
1766
- row.getToggleExpandedHandler = () => {
1767
- const canExpand = row.getCanExpand();
1768
- return () => {
1769
- if (!canExpand) return;
1770
- row.toggleExpanded();
1771
- };
1772
- };
1773
- }
1774
- };
1775
-
1776
- //
1777
-
1778
- const defaultPageIndex = 0;
1779
- const defaultPageSize = 10;
1780
- const getDefaultPaginationState = () => ({
1781
- pageIndex: defaultPageIndex,
1782
- pageSize: defaultPageSize
1783
- });
1784
- const RowPagination = {
1785
- getInitialState: state => {
1786
- return {
1787
- ...state,
1788
- pagination: {
1789
- ...getDefaultPaginationState(),
1790
- ...(state == null ? void 0 : state.pagination)
1791
- }
1792
- };
1793
- },
1794
- getDefaultOptions: table => {
1795
- return {
1796
- onPaginationChange: makeStateUpdater('pagination', table)
1797
- };
1798
- },
1799
- createTable: table => {
1800
- let registered = false;
1801
- let queued = false;
1802
- table._autoResetPageIndex = () => {
1803
- var _ref, _table$options$autoRe;
1804
- if (!registered) {
1805
- table._queue(() => {
1806
- registered = true;
1807
- });
1808
- return;
1809
- }
1810
- if ((_ref = (_table$options$autoRe = table.options.autoResetAll) != null ? _table$options$autoRe : table.options.autoResetPageIndex) != null ? _ref : !table.options.manualPagination) {
1811
- if (queued) return;
1812
- queued = true;
1813
- table._queue(() => {
1814
- table.resetPageIndex();
1815
- queued = false;
1816
- });
1817
- }
1818
- };
1819
- table.setPagination = updater => {
1820
- const safeUpdater = old => {
1821
- let newState = functionalUpdate(updater, old);
1822
- return newState;
1823
- };
1824
- return table.options.onPaginationChange == null ? void 0 : table.options.onPaginationChange(safeUpdater);
1825
- };
1826
- table.resetPagination = defaultState => {
1827
- var _table$initialState$p;
1828
- table.setPagination(defaultState ? getDefaultPaginationState() : (_table$initialState$p = table.initialState.pagination) != null ? _table$initialState$p : getDefaultPaginationState());
1829
- };
1830
- table.setPageIndex = updater => {
1831
- table.setPagination(old => {
1832
- let pageIndex = functionalUpdate(updater, old.pageIndex);
1833
- const maxPageIndex = typeof table.options.pageCount === 'undefined' || table.options.pageCount === -1 ? Number.MAX_SAFE_INTEGER : table.options.pageCount - 1;
1834
- pageIndex = Math.max(0, Math.min(pageIndex, maxPageIndex));
1835
- return {
1836
- ...old,
1837
- pageIndex
1838
- };
1839
- });
1840
- };
1841
- table.resetPageIndex = defaultState => {
1842
- var _table$initialState$p2, _table$initialState;
1843
- table.setPageIndex(defaultState ? defaultPageIndex : (_table$initialState$p2 = (_table$initialState = table.initialState) == null || (_table$initialState = _table$initialState.pagination) == null ? void 0 : _table$initialState.pageIndex) != null ? _table$initialState$p2 : defaultPageIndex);
1844
- };
1845
- table.resetPageSize = defaultState => {
1846
- var _table$initialState$p3, _table$initialState2;
1847
- table.setPageSize(defaultState ? defaultPageSize : (_table$initialState$p3 = (_table$initialState2 = table.initialState) == null || (_table$initialState2 = _table$initialState2.pagination) == null ? void 0 : _table$initialState2.pageSize) != null ? _table$initialState$p3 : defaultPageSize);
1848
- };
1849
- table.setPageSize = updater => {
1850
- table.setPagination(old => {
1851
- const pageSize = Math.max(1, functionalUpdate(updater, old.pageSize));
1852
- const topRowIndex = old.pageSize * old.pageIndex;
1853
- const pageIndex = Math.floor(topRowIndex / pageSize);
1854
- return {
1855
- ...old,
1856
- pageIndex,
1857
- pageSize
1858
- };
1859
- });
1860
- };
1861
- //deprecated
1862
- table.setPageCount = updater => table.setPagination(old => {
1863
- var _table$options$pageCo;
1864
- let newPageCount = functionalUpdate(updater, (_table$options$pageCo = table.options.pageCount) != null ? _table$options$pageCo : -1);
1865
- if (typeof newPageCount === 'number') {
1866
- newPageCount = Math.max(-1, newPageCount);
1867
- }
1868
- return {
1869
- ...old,
1870
- pageCount: newPageCount
1871
- };
1872
- });
1873
- table.getPageOptions = memo(() => [table.getPageCount()], pageCount => {
1874
- let pageOptions = [];
1875
- if (pageCount && pageCount > 0) {
1876
- pageOptions = [...new Array(pageCount)].fill(null).map((_, i) => i);
1877
- }
1878
- return pageOptions;
1879
- }, getMemoOptions(table.options, 'debugTable', 'getPageOptions'));
1880
- table.getCanPreviousPage = () => table.getState().pagination.pageIndex > 0;
1881
- table.getCanNextPage = () => {
1882
- const {
1883
- pageIndex
1884
- } = table.getState().pagination;
1885
- const pageCount = table.getPageCount();
1886
- if (pageCount === -1) {
1887
- return true;
1888
- }
1889
- if (pageCount === 0) {
1890
- return false;
1891
- }
1892
- return pageIndex < pageCount - 1;
1893
- };
1894
- table.previousPage = () => {
1895
- return table.setPageIndex(old => old - 1);
1896
- };
1897
- table.nextPage = () => {
1898
- return table.setPageIndex(old => {
1899
- return old + 1;
1900
- });
1901
- };
1902
- table.firstPage = () => {
1903
- return table.setPageIndex(0);
1904
- };
1905
- table.lastPage = () => {
1906
- return table.setPageIndex(table.getPageCount() - 1);
1907
- };
1908
- table.getPrePaginationRowModel = () => table.getExpandedRowModel();
1909
- table.getPaginationRowModel = () => {
1910
- if (!table._getPaginationRowModel && table.options.getPaginationRowModel) {
1911
- table._getPaginationRowModel = table.options.getPaginationRowModel(table);
1912
- }
1913
- if (table.options.manualPagination || !table._getPaginationRowModel) {
1914
- return table.getPrePaginationRowModel();
1915
- }
1916
- return table._getPaginationRowModel();
1917
- };
1918
- table.getPageCount = () => {
1919
- var _table$options$pageCo2;
1920
- return (_table$options$pageCo2 = table.options.pageCount) != null ? _table$options$pageCo2 : Math.ceil(table.getRowCount() / table.getState().pagination.pageSize);
1921
- };
1922
- table.getRowCount = () => {
1923
- var _table$options$rowCou;
1924
- return (_table$options$rowCou = table.options.rowCount) != null ? _table$options$rowCou : table.getPrePaginationRowModel().rows.length;
1925
- };
1926
- }
1927
- };
1928
-
1929
- //
1930
-
1931
- const getDefaultRowPinningState = () => ({
1932
- top: [],
1933
- bottom: []
1934
- });
1935
- const RowPinning = {
1936
- getInitialState: state => {
1937
- return {
1938
- rowPinning: getDefaultRowPinningState(),
1939
- ...state
1940
- };
1941
- },
1942
- getDefaultOptions: table => {
1943
- return {
1944
- onRowPinningChange: makeStateUpdater('rowPinning', table)
1945
- };
1946
- },
1947
- createRow: (row, table) => {
1948
- row.pin = (position, includeLeafRows, includeParentRows) => {
1949
- const leafRowIds = includeLeafRows ? row.getLeafRows().map(_ref => {
1950
- let {
1951
- id
1952
- } = _ref;
1953
- return id;
1954
- }) : [];
1955
- const parentRowIds = includeParentRows ? row.getParentRows().map(_ref2 => {
1956
- let {
1957
- id
1958
- } = _ref2;
1959
- return id;
1960
- }) : [];
1961
- const rowIds = new Set([...parentRowIds, row.id, ...leafRowIds]);
1962
- table.setRowPinning(old => {
1963
- var _old$top3, _old$bottom3;
1964
- if (position === 'bottom') {
1965
- var _old$top, _old$bottom;
1966
- return {
1967
- top: ((_old$top = old == null ? void 0 : old.top) != null ? _old$top : []).filter(d => !(rowIds != null && rowIds.has(d))),
1968
- bottom: [...((_old$bottom = old == null ? void 0 : old.bottom) != null ? _old$bottom : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)]
1969
- };
1970
- }
1971
- if (position === 'top') {
1972
- var _old$top2, _old$bottom2;
1973
- return {
1974
- top: [...((_old$top2 = old == null ? void 0 : old.top) != null ? _old$top2 : []).filter(d => !(rowIds != null && rowIds.has(d))), ...Array.from(rowIds)],
1975
- bottom: ((_old$bottom2 = old == null ? void 0 : old.bottom) != null ? _old$bottom2 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1976
- };
1977
- }
1978
- return {
1979
- top: ((_old$top3 = old == null ? void 0 : old.top) != null ? _old$top3 : []).filter(d => !(rowIds != null && rowIds.has(d))),
1980
- bottom: ((_old$bottom3 = old == null ? void 0 : old.bottom) != null ? _old$bottom3 : []).filter(d => !(rowIds != null && rowIds.has(d)))
1981
- };
1982
- });
1983
- };
1984
- row.getCanPin = () => {
1985
- var _ref3;
1986
- const {
1987
- enableRowPinning,
1988
- enablePinning
1989
- } = table.options;
1990
- if (typeof enableRowPinning === 'function') {
1991
- return enableRowPinning(row);
1992
- }
1993
- return (_ref3 = enableRowPinning != null ? enableRowPinning : enablePinning) != null ? _ref3 : true;
1994
- };
1995
- row.getIsPinned = () => {
1996
- const rowIds = [row.id];
1997
- const {
1998
- top,
1999
- bottom
2000
- } = table.getState().rowPinning;
2001
- const isTop = rowIds.some(d => top == null ? void 0 : top.includes(d));
2002
- const isBottom = rowIds.some(d => bottom == null ? void 0 : bottom.includes(d));
2003
- return isTop ? 'top' : isBottom ? 'bottom' : false;
2004
- };
2005
- row.getPinnedIndex = () => {
2006
- var _ref4, _visiblePinnedRowIds$;
2007
- const position = row.getIsPinned();
2008
- if (!position) return -1;
2009
- const visiblePinnedRowIds = (_ref4 = position === 'top' ? table.getTopRows() : table.getBottomRows()) == null ? void 0 : _ref4.map(_ref5 => {
2010
- let {
2011
- id
2012
- } = _ref5;
2013
- return id;
2014
- });
2015
- return (_visiblePinnedRowIds$ = visiblePinnedRowIds == null ? void 0 : visiblePinnedRowIds.indexOf(row.id)) != null ? _visiblePinnedRowIds$ : -1;
2016
- };
2017
- },
2018
- createTable: table => {
2019
- table.setRowPinning = updater => table.options.onRowPinningChange == null ? void 0 : table.options.onRowPinningChange(updater);
2020
- table.resetRowPinning = defaultState => {
2021
- var _table$initialState$r, _table$initialState;
2022
- return table.setRowPinning(defaultState ? getDefaultRowPinningState() : (_table$initialState$r = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.rowPinning) != null ? _table$initialState$r : getDefaultRowPinningState());
2023
- };
2024
- table.getIsSomeRowsPinned = position => {
2025
- var _pinningState$positio;
2026
- const pinningState = table.getState().rowPinning;
2027
- if (!position) {
2028
- var _pinningState$top, _pinningState$bottom;
2029
- return Boolean(((_pinningState$top = pinningState.top) == null ? void 0 : _pinningState$top.length) || ((_pinningState$bottom = pinningState.bottom) == null ? void 0 : _pinningState$bottom.length));
2030
- }
2031
- return Boolean((_pinningState$positio = pinningState[position]) == null ? void 0 : _pinningState$positio.length);
2032
- };
2033
- table._getPinnedRows = (visibleRows, pinnedRowIds, position) => {
2034
- var _table$options$keepPi;
2035
- const rows = ((_table$options$keepPi = table.options.keepPinnedRows) != null ? _table$options$keepPi : true) ?
2036
- //get all rows that are pinned even if they would not be otherwise visible
2037
- //account for expanded parent rows, but not pagination or filtering
2038
- (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => {
2039
- const row = table.getRow(rowId, true);
2040
- return row.getIsAllParentsExpanded() ? row : null;
2041
- }) :
2042
- //else get only visible rows that are pinned
2043
- (pinnedRowIds != null ? pinnedRowIds : []).map(rowId => visibleRows.find(row => row.id === rowId));
2044
- return rows.filter(Boolean).map(d => ({
2045
- ...d,
2046
- position
2047
- }));
2048
- };
2049
- table.getTopRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top], (allRows, topPinnedRowIds) => table._getPinnedRows(allRows, topPinnedRowIds, 'top'), getMemoOptions(table.options, 'debugRows', 'getTopRows'));
2050
- table.getBottomRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.bottom], (allRows, bottomPinnedRowIds) => table._getPinnedRows(allRows, bottomPinnedRowIds, 'bottom'), getMemoOptions(table.options, 'debugRows', 'getBottomRows'));
2051
- table.getCenterRows = memo(() => [table.getRowModel().rows, table.getState().rowPinning.top, table.getState().rowPinning.bottom], (allRows, top, bottom) => {
2052
- const topAndBottom = new Set([...(top != null ? top : []), ...(bottom != null ? bottom : [])]);
2053
- return allRows.filter(d => !topAndBottom.has(d.id));
2054
- }, getMemoOptions(table.options, 'debugRows', 'getCenterRows'));
2055
- }
2056
- };
2057
-
2058
- //
2059
-
2060
- const RowSelection = {
2061
- getInitialState: state => {
2062
- return {
2063
- rowSelection: {},
2064
- ...state
2065
- };
2066
- },
2067
- getDefaultOptions: table => {
2068
- return {
2069
- onRowSelectionChange: makeStateUpdater('rowSelection', table),
2070
- enableRowSelection: true,
2071
- enableMultiRowSelection: true,
2072
- enableSubRowSelection: true
2073
- // enableGroupingRowSelection: false,
2074
- // isAdditiveSelectEvent: (e: unknown) => !!e.metaKey,
2075
- // isInclusiveSelectEvent: (e: unknown) => !!e.shiftKey,
2076
- };
2077
- },
2078
- createTable: table => {
2079
- table.setRowSelection = updater => table.options.onRowSelectionChange == null ? void 0 : table.options.onRowSelectionChange(updater);
2080
- table.resetRowSelection = defaultState => {
2081
- var _table$initialState$r;
2082
- return table.setRowSelection(defaultState ? {} : (_table$initialState$r = table.initialState.rowSelection) != null ? _table$initialState$r : {});
2083
- };
2084
- table.toggleAllRowsSelected = value => {
2085
- table.setRowSelection(old => {
2086
- value = typeof value !== 'undefined' ? value : !table.getIsAllRowsSelected();
2087
- const rowSelection = {
2088
- ...old
2089
- };
2090
- const preGroupedFlatRows = table.getPreGroupedRowModel().flatRows;
2091
-
2092
- // We don't use `mutateRowIsSelected` here for performance reasons.
2093
- // All of the rows are flat already, so it wouldn't be worth it
2094
- if (value) {
2095
- preGroupedFlatRows.forEach(row => {
2096
- if (!row.getCanSelect()) {
2097
- return;
2098
- }
2099
- rowSelection[row.id] = true;
2100
- });
2101
- } else {
2102
- preGroupedFlatRows.forEach(row => {
2103
- delete rowSelection[row.id];
2104
- });
2105
- }
2106
- return rowSelection;
2107
- });
2108
- };
2109
- table.toggleAllPageRowsSelected = value => table.setRowSelection(old => {
2110
- const resolvedValue = typeof value !== 'undefined' ? value : !table.getIsAllPageRowsSelected();
2111
- const rowSelection = {
2112
- ...old
2113
- };
2114
- table.getRowModel().rows.forEach(row => {
2115
- mutateRowIsSelected(rowSelection, row.id, resolvedValue, true, table);
2116
- });
2117
- return rowSelection;
2118
- });
2119
-
2120
- // addRowSelectionRange: rowId => {
2121
- // const {
2122
- // rows,
2123
- // rowsById,
2124
- // options: { selectGroupingRows, selectSubRows },
2125
- // } = table
2126
-
2127
- // const findSelectedRow = (rows: Row[]) => {
2128
- // let found
2129
- // rows.find(d => {
2130
- // if (d.getIsSelected()) {
2131
- // found = d
2132
- // return true
2133
- // }
2134
- // const subFound = findSelectedRow(d.subRows || [])
2135
- // if (subFound) {
2136
- // found = subFound
2137
- // return true
2138
- // }
2139
- // return false
2140
- // })
2141
- // return found
2142
- // }
2143
-
2144
- // const firstRow = findSelectedRow(rows) || rows[0]
2145
- // const lastRow = rowsById[rowId]
2146
-
2147
- // let include = false
2148
- // const selectedRowIds = {}
2149
-
2150
- // const addRow = (row: Row) => {
2151
- // mutateRowIsSelected(selectedRowIds, row.id, true, {
2152
- // rowsById,
2153
- // selectGroupingRows: selectGroupingRows!,
2154
- // selectSubRows: selectSubRows!,
2155
- // })
2156
- // }
2157
-
2158
- // table.rows.forEach(row => {
2159
- // const isFirstRow = row.id === firstRow.id
2160
- // const isLastRow = row.id === lastRow.id
2161
-
2162
- // if (isFirstRow || isLastRow) {
2163
- // if (!include) {
2164
- // include = true
2165
- // } else if (include) {
2166
- // addRow(row)
2167
- // include = false
2168
- // }
2169
- // }
2170
-
2171
- // if (include) {
2172
- // addRow(row)
2173
- // }
2174
- // })
2175
-
2176
- // table.setRowSelection(selectedRowIds)
2177
- // },
2178
- table.getPreSelectedRowModel = () => table.getCoreRowModel();
2179
- table.getSelectedRowModel = memo(() => [table.getState().rowSelection, table.getCoreRowModel()], (rowSelection, rowModel) => {
2180
- if (!Object.keys(rowSelection).length) {
2181
- return {
2182
- rows: [],
2183
- flatRows: [],
2184
- rowsById: {}
2185
- };
2186
- }
2187
- return selectRowsFn(table, rowModel);
2188
- }, getMemoOptions(table.options, 'debugTable', 'getSelectedRowModel'));
2189
- table.getFilteredSelectedRowModel = memo(() => [table.getState().rowSelection, table.getFilteredRowModel()], (rowSelection, rowModel) => {
2190
- if (!Object.keys(rowSelection).length) {
2191
- return {
2192
- rows: [],
2193
- flatRows: [],
2194
- rowsById: {}
2195
- };
2196
- }
2197
- return selectRowsFn(table, rowModel);
2198
- }, getMemoOptions(table.options, 'debugTable', 'getFilteredSelectedRowModel'));
2199
- table.getGroupedSelectedRowModel = memo(() => [table.getState().rowSelection, table.getSortedRowModel()], (rowSelection, rowModel) => {
2200
- if (!Object.keys(rowSelection).length) {
2201
- return {
2202
- rows: [],
2203
- flatRows: [],
2204
- rowsById: {}
2205
- };
2206
- }
2207
- return selectRowsFn(table, rowModel);
2208
- }, getMemoOptions(table.options, 'debugTable', 'getGroupedSelectedRowModel'));
2209
-
2210
- ///
2211
-
2212
- // getGroupingRowCanSelect: rowId => {
2213
- // const row = table.getRow(rowId)
2214
-
2215
- // if (!row) {
2216
- // throw new Error()
2217
- // }
2218
-
2219
- // if (typeof table.options.enableGroupingRowSelection === 'function') {
2220
- // return table.options.enableGroupingRowSelection(row)
2221
- // }
2222
-
2223
- // return table.options.enableGroupingRowSelection ?? false
2224
- // },
2225
-
2226
- table.getIsAllRowsSelected = () => {
2227
- const preGroupedFlatRows = table.getFilteredRowModel().flatRows;
2228
- const {
2229
- rowSelection
2230
- } = table.getState();
2231
- let isAllRowsSelected = Boolean(preGroupedFlatRows.length && Object.keys(rowSelection).length);
2232
- if (isAllRowsSelected) {
2233
- if (preGroupedFlatRows.some(row => row.getCanSelect() && !rowSelection[row.id])) {
2234
- isAllRowsSelected = false;
2235
- }
2236
- }
2237
- return isAllRowsSelected;
2238
- };
2239
- table.getIsAllPageRowsSelected = () => {
2240
- const paginationFlatRows = table.getPaginationRowModel().flatRows.filter(row => row.getCanSelect());
2241
- const {
2242
- rowSelection
2243
- } = table.getState();
2244
- let isAllPageRowsSelected = !!paginationFlatRows.length;
2245
- if (isAllPageRowsSelected && paginationFlatRows.some(row => !rowSelection[row.id])) {
2246
- isAllPageRowsSelected = false;
2247
- }
2248
- return isAllPageRowsSelected;
2249
- };
2250
- table.getIsSomeRowsSelected = () => {
2251
- var _table$getState$rowSe;
2252
- const totalSelected = Object.keys((_table$getState$rowSe = table.getState().rowSelection) != null ? _table$getState$rowSe : {}).length;
2253
- return totalSelected > 0 && totalSelected < table.getFilteredRowModel().flatRows.length;
2254
- };
2255
- table.getIsSomePageRowsSelected = () => {
2256
- const paginationFlatRows = table.getPaginationRowModel().flatRows;
2257
- return table.getIsAllPageRowsSelected() ? false : paginationFlatRows.filter(row => row.getCanSelect()).some(d => d.getIsSelected() || d.getIsSomeSelected());
2258
- };
2259
- table.getToggleAllRowsSelectedHandler = () => {
2260
- return e => {
2261
- table.toggleAllRowsSelected(e.target.checked);
2262
- };
2263
- };
2264
- table.getToggleAllPageRowsSelectedHandler = () => {
2265
- return e => {
2266
- table.toggleAllPageRowsSelected(e.target.checked);
2267
- };
2268
- };
2269
- },
2270
- createRow: (row, table) => {
2271
- row.toggleSelected = (value, opts) => {
2272
- const isSelected = row.getIsSelected();
2273
- table.setRowSelection(old => {
2274
- var _opts$selectChildren;
2275
- value = typeof value !== 'undefined' ? value : !isSelected;
2276
- if (row.getCanSelect() && isSelected === value) {
2277
- return old;
2278
- }
2279
- const selectedRowIds = {
2280
- ...old
2281
- };
2282
- mutateRowIsSelected(selectedRowIds, row.id, value, (_opts$selectChildren = opts == null ? void 0 : opts.selectChildren) != null ? _opts$selectChildren : true, table);
2283
- return selectedRowIds;
2284
- });
2285
- };
2286
- row.getIsSelected = () => {
2287
- const {
2288
- rowSelection
2289
- } = table.getState();
2290
- return isRowSelected(row, rowSelection);
2291
- };
2292
- row.getIsSomeSelected = () => {
2293
- const {
2294
- rowSelection
2295
- } = table.getState();
2296
- return isSubRowSelected(row, rowSelection) === 'some';
2297
- };
2298
- row.getIsAllSubRowsSelected = () => {
2299
- const {
2300
- rowSelection
2301
- } = table.getState();
2302
- return isSubRowSelected(row, rowSelection) === 'all';
2303
- };
2304
- row.getCanSelect = () => {
2305
- var _table$options$enable;
2306
- if (typeof table.options.enableRowSelection === 'function') {
2307
- return table.options.enableRowSelection(row);
2308
- }
2309
- return (_table$options$enable = table.options.enableRowSelection) != null ? _table$options$enable : true;
2310
- };
2311
- row.getCanSelectSubRows = () => {
2312
- var _table$options$enable2;
2313
- if (typeof table.options.enableSubRowSelection === 'function') {
2314
- return table.options.enableSubRowSelection(row);
2315
- }
2316
- return (_table$options$enable2 = table.options.enableSubRowSelection) != null ? _table$options$enable2 : true;
2317
- };
2318
- row.getCanMultiSelect = () => {
2319
- var _table$options$enable3;
2320
- if (typeof table.options.enableMultiRowSelection === 'function') {
2321
- return table.options.enableMultiRowSelection(row);
2322
- }
2323
- return (_table$options$enable3 = table.options.enableMultiRowSelection) != null ? _table$options$enable3 : true;
2324
- };
2325
- row.getToggleSelectedHandler = () => {
2326
- const canSelect = row.getCanSelect();
2327
- return e => {
2328
- var _target;
2329
- if (!canSelect) return;
2330
- row.toggleSelected((_target = e.target) == null ? void 0 : _target.checked);
2331
- };
2332
- };
2333
- }
2334
- };
2335
- const mutateRowIsSelected = (selectedRowIds, id, value, includeChildren, table) => {
2336
- var _row$subRows;
2337
- const row = table.getRow(id, true);
2338
-
2339
- // const isGrouped = row.getIsGrouped()
2340
-
2341
- // if ( // TODO: enforce grouping row selection rules
2342
- // !isGrouped ||
2343
- // (isGrouped && table.options.enableGroupingRowSelection)
2344
- // ) {
2345
- if (value) {
2346
- if (!row.getCanMultiSelect()) {
2347
- Object.keys(selectedRowIds).forEach(key => delete selectedRowIds[key]);
2348
- }
2349
- if (row.getCanSelect()) {
2350
- selectedRowIds[id] = true;
2351
- }
2352
- } else {
2353
- delete selectedRowIds[id];
2354
- }
2355
- // }
2356
-
2357
- if (includeChildren && (_row$subRows = row.subRows) != null && _row$subRows.length && row.getCanSelectSubRows()) {
2358
- row.subRows.forEach(row => mutateRowIsSelected(selectedRowIds, row.id, value, includeChildren, table));
2359
- }
2360
- };
2361
- function selectRowsFn(table, rowModel) {
2362
- const rowSelection = table.getState().rowSelection;
2363
- const newSelectedFlatRows = [];
2364
- const newSelectedRowsById = {};
2365
-
2366
- // Filters top level and nested rows
2367
- const recurseRows = function (rows, depth) {
2368
- return rows.map(row => {
2369
- var _row$subRows2;
2370
- const isSelected = isRowSelected(row, rowSelection);
2371
- if (isSelected) {
2372
- newSelectedFlatRows.push(row);
2373
- newSelectedRowsById[row.id] = row;
2374
- }
2375
- if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length) {
2376
- row = {
2377
- ...row,
2378
- subRows: recurseRows(row.subRows)
2379
- };
2380
- }
2381
- if (isSelected) {
2382
- return row;
2383
- }
2384
- }).filter(Boolean);
2385
- };
2386
- return {
2387
- rows: recurseRows(rowModel.rows),
2388
- flatRows: newSelectedFlatRows,
2389
- rowsById: newSelectedRowsById
2390
- };
2391
- }
2392
- function isRowSelected(row, selection) {
2393
- var _selection$row$id;
2394
- return (_selection$row$id = selection[row.id]) != null ? _selection$row$id : false;
2395
- }
2396
- function isSubRowSelected(row, selection, table) {
2397
- var _row$subRows3;
2398
- if (!((_row$subRows3 = row.subRows) != null && _row$subRows3.length)) return false;
2399
- let allChildrenSelected = true;
2400
- let someSelected = false;
2401
- row.subRows.forEach(subRow => {
2402
- // Bail out early if we know both of these
2403
- if (someSelected && !allChildrenSelected) {
2404
- return;
2405
- }
2406
- if (subRow.getCanSelect()) {
2407
- if (isRowSelected(subRow, selection)) {
2408
- someSelected = true;
2409
- } else {
2410
- allChildrenSelected = false;
2411
- }
2412
- }
2413
-
2414
- // Check row selection of nested subrows
2415
- if (subRow.subRows && subRow.subRows.length) {
2416
- const subRowChildrenSelected = isSubRowSelected(subRow, selection);
2417
- if (subRowChildrenSelected === 'all') {
2418
- someSelected = true;
2419
- } else if (subRowChildrenSelected === 'some') {
2420
- someSelected = true;
2421
- allChildrenSelected = false;
2422
- } else {
2423
- allChildrenSelected = false;
2424
- }
2425
- }
2426
- });
2427
- return allChildrenSelected ? 'all' : someSelected ? 'some' : false;
2428
- }
2429
-
2430
- const reSplitAlphaNumeric = /([0-9]+)/gm;
2431
- const alphanumeric = (rowA, rowB, columnId) => {
2432
- return compareAlphanumeric(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2433
- };
2434
- const alphanumericCaseSensitive = (rowA, rowB, columnId) => {
2435
- return compareAlphanumeric(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2436
- };
2437
-
2438
- // The text filter is more basic (less numeric support)
2439
- // but is much faster
2440
- const text = (rowA, rowB, columnId) => {
2441
- return compareBasic(toString(rowA.getValue(columnId)).toLowerCase(), toString(rowB.getValue(columnId)).toLowerCase());
2442
- };
2443
-
2444
- // The text filter is more basic (less numeric support)
2445
- // but is much faster
2446
- const textCaseSensitive = (rowA, rowB, columnId) => {
2447
- return compareBasic(toString(rowA.getValue(columnId)), toString(rowB.getValue(columnId)));
2448
- };
2449
- const datetime = (rowA, rowB, columnId) => {
2450
- const a = rowA.getValue(columnId);
2451
- const b = rowB.getValue(columnId);
2452
-
2453
- // Can handle nullish values
2454
- // Use > and < because == (and ===) doesn't work with
2455
- // Date objects (would require calling getTime()).
2456
- return a > b ? 1 : a < b ? -1 : 0;
2457
- };
2458
- const basic = (rowA, rowB, columnId) => {
2459
- return compareBasic(rowA.getValue(columnId), rowB.getValue(columnId));
2460
- };
2461
-
2462
- // Utils
2463
-
2464
- function compareBasic(a, b) {
2465
- return a === b ? 0 : a > b ? 1 : -1;
2466
- }
2467
- function toString(a) {
2468
- if (typeof a === 'number') {
2469
- if (isNaN(a) || a === Infinity || a === -Infinity) {
2470
- return '';
2471
- }
2472
- return String(a);
2473
- }
2474
- if (typeof a === 'string') {
2475
- return a;
2476
- }
2477
- return '';
2478
- }
2479
-
2480
- // Mixed sorting is slow, but very inclusive of many edge cases.
2481
- // It handles numbers, mixed alphanumeric combinations, and even
2482
- // null, undefined, and Infinity
2483
- function compareAlphanumeric(aStr, bStr) {
2484
- // Split on number groups, but keep the delimiter
2485
- // Then remove falsey split values
2486
- const a = aStr.split(reSplitAlphaNumeric).filter(Boolean);
2487
- const b = bStr.split(reSplitAlphaNumeric).filter(Boolean);
2488
-
2489
- // While
2490
- while (a.length && b.length) {
2491
- const aa = a.shift();
2492
- const bb = b.shift();
2493
- const an = parseInt(aa, 10);
2494
- const bn = parseInt(bb, 10);
2495
- const combo = [an, bn].sort();
2496
-
2497
- // Both are string
2498
- if (isNaN(combo[0])) {
2499
- if (aa > bb) {
2500
- return 1;
2501
- }
2502
- if (bb > aa) {
2503
- return -1;
2504
- }
2505
- continue;
2506
- }
2507
-
2508
- // One is a string, one is a number
2509
- if (isNaN(combo[1])) {
2510
- return isNaN(an) ? -1 : 1;
2511
- }
2512
-
2513
- // Both are numbers
2514
- if (an > bn) {
2515
- return 1;
2516
- }
2517
- if (bn > an) {
2518
- return -1;
2519
- }
2520
- }
2521
- return a.length - b.length;
2522
- }
2523
-
2524
- // Exports
2525
-
2526
- const sortingFns = {
2527
- alphanumeric,
2528
- alphanumericCaseSensitive,
2529
- text,
2530
- textCaseSensitive,
2531
- datetime,
2532
- basic
2533
- };
2534
-
2535
- //
2536
-
2537
- const RowSorting = {
2538
- getInitialState: state => {
2539
- return {
2540
- sorting: [],
2541
- ...state
2542
- };
2543
- },
2544
- getDefaultColumnDef: () => {
2545
- return {
2546
- sortingFn: 'auto',
2547
- sortUndefined: 1
2548
- };
2549
- },
2550
- getDefaultOptions: table => {
2551
- return {
2552
- onSortingChange: makeStateUpdater('sorting', table),
2553
- isMultiSortEvent: e => {
2554
- return e.shiftKey;
2555
- }
2556
- };
2557
- },
2558
- createColumn: (column, table) => {
2559
- column.getAutoSortingFn = () => {
2560
- const firstRows = table.getFilteredRowModel().flatRows.slice(10);
2561
- let isString = false;
2562
- for (const row of firstRows) {
2563
- const value = row == null ? void 0 : row.getValue(column.id);
2564
- if (Object.prototype.toString.call(value) === '[object Date]') {
2565
- return sortingFns.datetime;
2566
- }
2567
- if (typeof value === 'string') {
2568
- isString = true;
2569
- if (value.split(reSplitAlphaNumeric).length > 1) {
2570
- return sortingFns.alphanumeric;
2571
- }
2572
- }
2573
- }
2574
- if (isString) {
2575
- return sortingFns.text;
2576
- }
2577
- return sortingFns.basic;
2578
- };
2579
- column.getAutoSortDir = () => {
2580
- const firstRow = table.getFilteredRowModel().flatRows[0];
2581
- const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
2582
- if (typeof value === 'string') {
2583
- return 'asc';
2584
- }
2585
- return 'desc';
2586
- };
2587
- column.getSortingFn = () => {
2588
- var _table$options$sortin, _table$options$sortin2;
2589
- if (!column) {
2590
- throw new Error();
2591
- }
2592
- return isFunction(column.columnDef.sortingFn) ? column.columnDef.sortingFn : column.columnDef.sortingFn === 'auto' ? column.getAutoSortingFn() : (_table$options$sortin = (_table$options$sortin2 = table.options.sortingFns) == null ? void 0 : _table$options$sortin2[column.columnDef.sortingFn]) != null ? _table$options$sortin : sortingFns[column.columnDef.sortingFn];
2593
- };
2594
- column.toggleSorting = (desc, multi) => {
2595
- // if (column.columns.length) {
2596
- // column.columns.forEach((c, i) => {
2597
- // if (c.id) {
2598
- // table.toggleColumnSorting(c.id, undefined, multi || !!i)
2599
- // }
2600
- // })
2601
- // return
2602
- // }
2603
-
2604
- // this needs to be outside of table.setSorting to be in sync with rerender
2605
- const nextSortingOrder = column.getNextSortingOrder();
2606
- const hasManualValue = typeof desc !== 'undefined' && desc !== null;
2607
- table.setSorting(old => {
2608
- // Find any existing sorting for this column
2609
- const existingSorting = old == null ? void 0 : old.find(d => d.id === column.id);
2610
- const existingIndex = old == null ? void 0 : old.findIndex(d => d.id === column.id);
2611
- let newSorting = [];
2612
-
2613
- // What should we do with this sort action?
2614
- let sortAction;
2615
- let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc';
2616
-
2617
- // Multi-mode
2618
- if (old != null && old.length && column.getCanMultiSort() && multi) {
2619
- if (existingSorting) {
2620
- sortAction = 'toggle';
2621
- } else {
2622
- sortAction = 'add';
2623
- }
2624
- } else {
2625
- // Normal mode
2626
- if (old != null && old.length && existingIndex !== old.length - 1) {
2627
- sortAction = 'replace';
2628
- } else if (existingSorting) {
2629
- sortAction = 'toggle';
2630
- } else {
2631
- sortAction = 'replace';
2632
- }
2633
- }
2634
-
2635
- // Handle toggle states that will remove the sorting
2636
- if (sortAction === 'toggle') {
2637
- // If we are "actually" toggling (not a manual set value), should we remove the sorting?
2638
- if (!hasManualValue) {
2639
- // Is our intention to remove?
2640
- if (!nextSortingOrder) {
2641
- sortAction = 'remove';
2642
- }
2643
- }
2644
- }
2645
- if (sortAction === 'add') {
2646
- var _table$options$maxMul;
2647
- newSorting = [...old, {
2648
- id: column.id,
2649
- desc: nextDesc
2650
- }];
2651
- // Take latest n columns
2652
- newSorting.splice(0, newSorting.length - ((_table$options$maxMul = table.options.maxMultiSortColCount) != null ? _table$options$maxMul : Number.MAX_SAFE_INTEGER));
2653
- } else if (sortAction === 'toggle') {
2654
- // This flips (or sets) the
2655
- newSorting = old.map(d => {
2656
- if (d.id === column.id) {
2657
- return {
2658
- ...d,
2659
- desc: nextDesc
2660
- };
2661
- }
2662
- return d;
2663
- });
2664
- } else if (sortAction === 'remove') {
2665
- newSorting = old.filter(d => d.id !== column.id);
2666
- } else {
2667
- newSorting = [{
2668
- id: column.id,
2669
- desc: nextDesc
2670
- }];
2671
- }
2672
- return newSorting;
2673
- });
2674
- };
2675
- column.getFirstSortDir = () => {
2676
- var _ref, _column$columnDef$sor;
2677
- const sortDescFirst = (_ref = (_column$columnDef$sor = column.columnDef.sortDescFirst) != null ? _column$columnDef$sor : table.options.sortDescFirst) != null ? _ref : column.getAutoSortDir() === 'desc';
2678
- return sortDescFirst ? 'desc' : 'asc';
2679
- };
2680
- column.getNextSortingOrder = multi => {
2681
- var _table$options$enable, _table$options$enable2;
2682
- const firstSortDirection = column.getFirstSortDir();
2683
- const isSorted = column.getIsSorted();
2684
- if (!isSorted) {
2685
- return firstSortDirection;
2686
- }
2687
- if (isSorted !== firstSortDirection && ((_table$options$enable = table.options.enableSortingRemoval) != null ? _table$options$enable : true) && (
2688
- // If enableSortRemove, enable in general
2689
- multi ? (_table$options$enable2 = table.options.enableMultiRemove) != null ? _table$options$enable2 : true : true) // If multi, don't allow if enableMultiRemove))
2690
- ) {
2691
- return false;
2692
- }
2693
- return isSorted === 'desc' ? 'asc' : 'desc';
2694
- };
2695
- column.getCanSort = () => {
2696
- var _column$columnDef$ena, _table$options$enable3;
2697
- return ((_column$columnDef$ena = column.columnDef.enableSorting) != null ? _column$columnDef$ena : true) && ((_table$options$enable3 = table.options.enableSorting) != null ? _table$options$enable3 : true) && !!column.accessorFn;
2698
- };
2699
- column.getCanMultiSort = () => {
2700
- var _ref2, _column$columnDef$ena2;
2701
- return (_ref2 = (_column$columnDef$ena2 = column.columnDef.enableMultiSort) != null ? _column$columnDef$ena2 : table.options.enableMultiSort) != null ? _ref2 : !!column.accessorFn;
2702
- };
2703
- column.getIsSorted = () => {
2704
- var _table$getState$sorti;
2705
- const columnSort = (_table$getState$sorti = table.getState().sorting) == null ? void 0 : _table$getState$sorti.find(d => d.id === column.id);
2706
- return !columnSort ? false : columnSort.desc ? 'desc' : 'asc';
2707
- };
2708
- column.getSortIndex = () => {
2709
- var _table$getState$sorti2, _table$getState$sorti3;
2710
- return (_table$getState$sorti2 = (_table$getState$sorti3 = table.getState().sorting) == null ? void 0 : _table$getState$sorti3.findIndex(d => d.id === column.id)) != null ? _table$getState$sorti2 : -1;
2711
- };
2712
- column.clearSorting = () => {
2713
- //clear sorting for just 1 column
2714
- table.setSorting(old => old != null && old.length ? old.filter(d => d.id !== column.id) : []);
2715
- };
2716
- column.getToggleSortingHandler = () => {
2717
- const canSort = column.getCanSort();
2718
- return e => {
2719
- if (!canSort) return;
2720
- e.persist == null || e.persist();
2721
- column.toggleSorting == null || column.toggleSorting(undefined, column.getCanMultiSort() ? table.options.isMultiSortEvent == null ? void 0 : table.options.isMultiSortEvent(e) : false);
2722
- };
2723
- };
2724
- },
2725
- createTable: table => {
2726
- table.setSorting = updater => table.options.onSortingChange == null ? void 0 : table.options.onSortingChange(updater);
2727
- table.resetSorting = defaultState => {
2728
- var _table$initialState$s, _table$initialState;
2729
- table.setSorting(defaultState ? [] : (_table$initialState$s = (_table$initialState = table.initialState) == null ? void 0 : _table$initialState.sorting) != null ? _table$initialState$s : []);
2730
- };
2731
- table.getPreSortedRowModel = () => table.getGroupedRowModel();
2732
- table.getSortedRowModel = () => {
2733
- if (!table._getSortedRowModel && table.options.getSortedRowModel) {
2734
- table._getSortedRowModel = table.options.getSortedRowModel(table);
2735
- }
2736
- if (table.options.manualSorting || !table._getSortedRowModel) {
2737
- return table.getPreSortedRowModel();
2738
- }
2739
- return table._getSortedRowModel();
2740
- };
2741
- }
2742
- };
2743
-
2744
- const builtInFeatures = [Headers, ColumnVisibility, ColumnOrdering, ColumnPinning, ColumnFaceting, ColumnFiltering, GlobalFaceting,
2745
- //depends on ColumnFaceting
2746
- GlobalFiltering,
2747
- //depends on ColumnFiltering
2748
- RowSorting, ColumnGrouping,
2749
- //depends on RowSorting
2750
- RowExpanding, RowPagination, RowPinning, RowSelection, ColumnSizing];
2751
-
2752
- //
2753
-
2754
- function createTable(options) {
2755
- var _options$_features, _options$initialState;
2756
- if (process.env.NODE_ENV !== 'production' && (options.debugAll || options.debugTable)) {
2757
- console.info('Creating Table Instance...');
2758
- }
2759
- const _features = [...builtInFeatures, ...((_options$_features = options._features) != null ? _options$_features : [])];
2760
- let table = {
2761
- _features
2762
- };
2763
- const defaultOptions = table._features.reduce((obj, feature) => {
2764
- return Object.assign(obj, feature.getDefaultOptions == null ? void 0 : feature.getDefaultOptions(table));
2765
- }, {});
2766
- const mergeOptions = options => {
2767
- if (table.options.mergeOptions) {
2768
- return table.options.mergeOptions(defaultOptions, options);
2769
- }
2770
- return {
2771
- ...defaultOptions,
2772
- ...options
2773
- };
2774
- };
2775
- const coreInitialState = {};
2776
- let initialState = {
2777
- ...coreInitialState,
2778
- ...((_options$initialState = options.initialState) != null ? _options$initialState : {})
2779
- };
2780
- table._features.forEach(feature => {
2781
- var _feature$getInitialSt;
2782
- initialState = (_feature$getInitialSt = feature.getInitialState == null ? void 0 : feature.getInitialState(initialState)) != null ? _feature$getInitialSt : initialState;
2783
- });
2784
- const queued = [];
2785
- let queuedTimeout = false;
2786
- const coreInstance = {
2787
- _features,
2788
- options: {
2789
- ...defaultOptions,
2790
- ...options
2791
- },
2792
- initialState,
2793
- _queue: cb => {
2794
- queued.push(cb);
2795
- if (!queuedTimeout) {
2796
- queuedTimeout = true;
2797
-
2798
- // Schedule a microtask to run the queued callbacks after
2799
- // the current call stack (render, etc) has finished.
2800
- Promise.resolve().then(() => {
2801
- while (queued.length) {
2802
- queued.shift()();
2803
- }
2804
- queuedTimeout = false;
2805
- }).catch(error => setTimeout(() => {
2806
- throw error;
2807
- }));
2808
- }
2809
- },
2810
- reset: () => {
2811
- table.setState(table.initialState);
2812
- },
2813
- setOptions: updater => {
2814
- const newOptions = functionalUpdate(updater, table.options);
2815
- table.options = mergeOptions(newOptions);
2816
- },
2817
- getState: () => {
2818
- return table.options.state;
2819
- },
2820
- setState: updater => {
2821
- table.options.onStateChange == null || table.options.onStateChange(updater);
2822
- },
2823
- _getRowId: (row, index, parent) => {
2824
- var _table$options$getRow;
2825
- return (_table$options$getRow = table.options.getRowId == null ? void 0 : table.options.getRowId(row, index, parent)) != null ? _table$options$getRow : `${parent ? [parent.id, index].join('.') : index}`;
2826
- },
2827
- getCoreRowModel: () => {
2828
- if (!table._getCoreRowModel) {
2829
- table._getCoreRowModel = table.options.getCoreRowModel(table);
2830
- }
2831
- return table._getCoreRowModel();
2832
- },
2833
- // The final calls start at the bottom of the model,
2834
- // expanded rows, which then work their way up
2835
-
2836
- getRowModel: () => {
2837
- return table.getPaginationRowModel();
2838
- },
2839
- //in next version, we should just pass in the row model as the optional 2nd arg
2840
- getRow: (id, searchAll) => {
2841
- let row = (searchAll ? table.getPrePaginationRowModel() : table.getRowModel()).rowsById[id];
2842
- if (!row) {
2843
- row = table.getCoreRowModel().rowsById[id];
2844
- if (!row) {
2845
- if (process.env.NODE_ENV !== 'production') {
2846
- throw new Error(`getRow could not find row with ID: ${id}`);
2847
- }
2848
- throw new Error();
2849
- }
2850
- }
2851
- return row;
2852
- },
2853
- _getDefaultColumnDef: memo(() => [table.options.defaultColumn], defaultColumn => {
2854
- var _defaultColumn;
2855
- defaultColumn = (_defaultColumn = defaultColumn) != null ? _defaultColumn : {};
2856
- return {
2857
- header: props => {
2858
- const resolvedColumnDef = props.header.column.columnDef;
2859
- if (resolvedColumnDef.accessorKey) {
2860
- return resolvedColumnDef.accessorKey;
2861
- }
2862
- if (resolvedColumnDef.accessorFn) {
2863
- return resolvedColumnDef.id;
2864
- }
2865
- return null;
2866
- },
2867
- // footer: props => props.header.column.id,
2868
- cell: props => {
2869
- var _props$renderValue$to, _props$renderValue;
2870
- return (_props$renderValue$to = (_props$renderValue = props.renderValue()) == null || _props$renderValue.toString == null ? void 0 : _props$renderValue.toString()) != null ? _props$renderValue$to : null;
2871
- },
2872
- ...table._features.reduce((obj, feature) => {
2873
- return Object.assign(obj, feature.getDefaultColumnDef == null ? void 0 : feature.getDefaultColumnDef());
2874
- }, {}),
2875
- ...defaultColumn
2876
- };
2877
- }, getMemoOptions(options, 'debugColumns', '_getDefaultColumnDef')),
2878
- _getColumnDefs: () => table.options.columns,
2879
- getAllColumns: memo(() => [table._getColumnDefs()], columnDefs => {
2880
- const recurseColumns = function (columnDefs, parent, depth) {
2881
- if (depth === void 0) {
2882
- depth = 0;
2883
- }
2884
- return columnDefs.map(columnDef => {
2885
- const column = createColumn(table, columnDef, depth, parent);
2886
- const groupingColumnDef = columnDef;
2887
- column.columns = groupingColumnDef.columns ? recurseColumns(groupingColumnDef.columns, column, depth + 1) : [];
2888
- return column;
2889
- });
2890
- };
2891
- return recurseColumns(columnDefs);
2892
- }, getMemoOptions(options, 'debugColumns', 'getAllColumns')),
2893
- getAllFlatColumns: memo(() => [table.getAllColumns()], allColumns => {
2894
- return allColumns.flatMap(column => {
2895
- return column.getFlatColumns();
2896
- });
2897
- }, getMemoOptions(options, 'debugColumns', 'getAllFlatColumns')),
2898
- _getAllFlatColumnsById: memo(() => [table.getAllFlatColumns()], flatColumns => {
2899
- return flatColumns.reduce((acc, column) => {
2900
- acc[column.id] = column;
2901
- return acc;
2902
- }, {});
2903
- }, getMemoOptions(options, 'debugColumns', 'getAllFlatColumnsById')),
2904
- getAllLeafColumns: memo(() => [table.getAllColumns(), table._getOrderColumnsFn()], (allColumns, orderColumns) => {
2905
- let leafColumns = allColumns.flatMap(column => column.getLeafColumns());
2906
- return orderColumns(leafColumns);
2907
- }, getMemoOptions(options, 'debugColumns', 'getAllLeafColumns')),
2908
- getColumn: columnId => {
2909
- const column = table._getAllFlatColumnsById()[columnId];
2910
- if (process.env.NODE_ENV !== 'production' && !column) {
2911
- console.error(`[Table] Column with id '${columnId}' does not exist.`);
2912
- }
2913
- return column;
2914
- }
2915
- };
2916
- Object.assign(table, coreInstance);
2917
- for (let index = 0; index < table._features.length; index++) {
2918
- const feature = table._features[index];
2919
- feature == null || feature.createTable == null || feature.createTable(table);
2920
- }
2921
- return table;
2922
- }
2923
-
2924
- function getCoreRowModel() {
2925
- return table => memo(() => [table.options.data], data => {
2926
- const rowModel = {
2927
- rows: [],
2928
- flatRows: [],
2929
- rowsById: {}
2930
- };
2931
- const accessRows = function (originalRows, depth, parentRow) {
2932
- if (depth === void 0) {
2933
- depth = 0;
2934
- }
2935
- const rows = [];
2936
- for (let i = 0; i < originalRows.length; i++) {
2937
- // This could be an expensive check at scale, so we should move it somewhere else, but where?
2938
- // if (!id) {
2939
- // if (process.env.NODE_ENV !== 'production') {
2940
- // throw new Error(`getRowId expected an ID, but got ${id}`)
2941
- // }
2942
- // }
2943
-
2944
- // Make the row
2945
- const row = createRow(table, table._getRowId(originalRows[i], i, parentRow), originalRows[i], i, depth, undefined, parentRow == null ? void 0 : parentRow.id);
2946
-
2947
- // Keep track of every row in a flat array
2948
- rowModel.flatRows.push(row);
2949
- // Also keep track of every row by its ID
2950
- rowModel.rowsById[row.id] = row;
2951
- // Push table row into parent
2952
- rows.push(row);
2953
-
2954
- // Get the original subrows
2955
- if (table.options.getSubRows) {
2956
- var _row$originalSubRows;
2957
- row.originalSubRows = table.options.getSubRows(originalRows[i], i);
2958
-
2959
- // Then recursively access them
2960
- if ((_row$originalSubRows = row.originalSubRows) != null && _row$originalSubRows.length) {
2961
- row.subRows = accessRows(row.originalSubRows, depth + 1, row);
2962
- }
2963
- }
2964
- }
2965
- return rows;
2966
- };
2967
- rowModel.rows = accessRows(data);
2968
- return rowModel;
2969
- }, getMemoOptions(table.options, 'debugTable', 'getRowModel', () => table._autoResetPageIndex()));
2970
- }
2971
-
2972
- function getExpandedRowModel() {
2973
- return table => memo(() => [table.getState().expanded, table.getPreExpandedRowModel(), table.options.paginateExpandedRows], (expanded, rowModel, paginateExpandedRows) => {
2974
- if (!rowModel.rows.length || expanded !== true && !Object.keys(expanded != null ? expanded : {}).length) {
2975
- return rowModel;
2976
- }
2977
- if (!paginateExpandedRows) {
2978
- // Only expand rows at this point if they are being paginated
2979
- return rowModel;
2980
- }
2981
- return expandRows(rowModel);
2982
- }, getMemoOptions(table.options, 'debugTable', 'getExpandedRowModel'));
2983
- }
2984
- function expandRows(rowModel) {
2985
- const expandedRows = [];
2986
- const handleRow = row => {
2987
- var _row$subRows;
2988
- expandedRows.push(row);
2989
- if ((_row$subRows = row.subRows) != null && _row$subRows.length && row.getIsExpanded()) {
2990
- row.subRows.forEach(handleRow);
2991
- }
2992
- };
2993
- rowModel.rows.forEach(handleRow);
2994
- return {
2995
- rows: expandedRows,
2996
- flatRows: rowModel.flatRows,
2997
- rowsById: rowModel.rowsById
2998
- };
2999
- }
3000
-
3001
- function getFacetedMinMaxValues() {
3002
- return (table, columnId) => memo(() => {
3003
- var _table$getColumn;
3004
- return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.getFacetedRowModel()];
3005
- }, facetedRowModel => {
3006
- var _facetedRowModel$flat;
3007
- if (!facetedRowModel) return undefined;
3008
- const firstValue = (_facetedRowModel$flat = facetedRowModel.flatRows[0]) == null ? void 0 : _facetedRowModel$flat.getUniqueValues(columnId);
3009
- if (typeof firstValue === 'undefined') {
3010
- return undefined;
3011
- }
3012
- let facetedMinMaxValues = [firstValue, firstValue];
3013
- for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3014
- const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3015
- for (let j = 0; j < values.length; j++) {
3016
- const value = values[j];
3017
- if (value < facetedMinMaxValues[0]) {
3018
- facetedMinMaxValues[0] = value;
3019
- } else if (value > facetedMinMaxValues[1]) {
3020
- facetedMinMaxValues[1] = value;
3021
- }
3022
- }
3023
- }
3024
- return facetedMinMaxValues;
3025
- }, getMemoOptions(table.options, 'debugTable', 'getFacetedMinMaxValues'));
3026
- }
3027
-
3028
- function filterRows(rows, filterRowImpl, table) {
3029
- if (table.options.filterFromLeafRows) {
3030
- return filterRowModelFromLeafs(rows, filterRowImpl, table);
3031
- }
3032
- return filterRowModelFromRoot(rows, filterRowImpl, table);
3033
- }
3034
- function filterRowModelFromLeafs(rowsToFilter, filterRow, table) {
3035
- var _table$options$maxLea;
3036
- const newFilteredFlatRows = [];
3037
- const newFilteredRowsById = {};
3038
- const maxDepth = (_table$options$maxLea = table.options.maxLeafRowFilterDepth) != null ? _table$options$maxLea : 100;
3039
- const recurseFilterRows = function (rowsToFilter, depth) {
3040
- if (depth === void 0) {
3041
- depth = 0;
3042
- }
3043
- const rows = [];
3044
-
3045
- // Filter from children up first
3046
- for (let i = 0; i < rowsToFilter.length; i++) {
3047
- var _row$subRows;
3048
- let row = rowsToFilter[i];
3049
- const newRow = createRow(table, row.id, row.original, row.index, row.depth, undefined, row.parentId);
3050
- newRow.columnFilters = row.columnFilters;
3051
- if ((_row$subRows = row.subRows) != null && _row$subRows.length && depth < maxDepth) {
3052
- newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3053
- row = newRow;
3054
- if (filterRow(row) && !newRow.subRows.length) {
3055
- rows.push(row);
3056
- newFilteredRowsById[row.id] = row;
3057
- newFilteredFlatRows.push(row);
3058
- continue;
3059
- }
3060
- if (filterRow(row) || newRow.subRows.length) {
3061
- rows.push(row);
3062
- newFilteredRowsById[row.id] = row;
3063
- newFilteredFlatRows.push(row);
3064
- continue;
3065
- }
3066
- } else {
3067
- row = newRow;
3068
- if (filterRow(row)) {
3069
- rows.push(row);
3070
- newFilteredRowsById[row.id] = row;
3071
- newFilteredFlatRows.push(row);
3072
- }
3073
- }
3074
- }
3075
- return rows;
3076
- };
3077
- return {
3078
- rows: recurseFilterRows(rowsToFilter),
3079
- flatRows: newFilteredFlatRows,
3080
- rowsById: newFilteredRowsById
3081
- };
3082
- }
3083
- function filterRowModelFromRoot(rowsToFilter, filterRow, table) {
3084
- var _table$options$maxLea2;
3085
- const newFilteredFlatRows = [];
3086
- const newFilteredRowsById = {};
3087
- const maxDepth = (_table$options$maxLea2 = table.options.maxLeafRowFilterDepth) != null ? _table$options$maxLea2 : 100;
3088
-
3089
- // Filters top level and nested rows
3090
- const recurseFilterRows = function (rowsToFilter, depth) {
3091
- if (depth === void 0) {
3092
- depth = 0;
3093
- }
3094
- // Filter from parents downward first
3095
-
3096
- const rows = [];
3097
-
3098
- // Apply the filter to any subRows
3099
- for (let i = 0; i < rowsToFilter.length; i++) {
3100
- let row = rowsToFilter[i];
3101
- const pass = filterRow(row);
3102
- if (pass) {
3103
- var _row$subRows2;
3104
- if ((_row$subRows2 = row.subRows) != null && _row$subRows2.length && depth < maxDepth) {
3105
- const newRow = createRow(table, row.id, row.original, row.index, row.depth, undefined, row.parentId);
3106
- newRow.subRows = recurseFilterRows(row.subRows, depth + 1);
3107
- row = newRow;
3108
- }
3109
- rows.push(row);
3110
- newFilteredFlatRows.push(row);
3111
- newFilteredRowsById[row.id] = row;
3112
- }
3113
- }
3114
- return rows;
3115
- };
3116
- return {
3117
- rows: recurseFilterRows(rowsToFilter),
3118
- flatRows: newFilteredFlatRows,
3119
- rowsById: newFilteredRowsById
3120
- };
3121
- }
3122
-
3123
- function getFacetedRowModel() {
3124
- return (table, columnId) => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter, table.getFilteredRowModel()], (preRowModel, columnFilters, globalFilter) => {
3125
- if (!preRowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3126
- return preRowModel;
3127
- }
3128
- const filterableIds = [...columnFilters.map(d => d.id).filter(d => d !== columnId), globalFilter ? '__global__' : undefined].filter(Boolean);
3129
- const filterRowsImpl = row => {
3130
- // Horizontally filter rows through each column
3131
- for (let i = 0; i < filterableIds.length; i++) {
3132
- if (row.columnFilters[filterableIds[i]] === false) {
3133
- return false;
3134
- }
3135
- }
3136
- return true;
3137
- };
3138
- return filterRows(preRowModel.rows, filterRowsImpl, table);
3139
- }, getMemoOptions(table.options, 'debugTable', 'getFacetedRowModel'));
3140
- }
3141
-
3142
- function getFacetedUniqueValues() {
3143
- return (table, columnId) => memo(() => {
3144
- var _table$getColumn;
3145
- return [(_table$getColumn = table.getColumn(columnId)) == null ? void 0 : _table$getColumn.getFacetedRowModel()];
3146
- }, facetedRowModel => {
3147
- if (!facetedRowModel) return new Map();
3148
- let facetedUniqueValues = new Map();
3149
- for (let i = 0; i < facetedRowModel.flatRows.length; i++) {
3150
- const values = facetedRowModel.flatRows[i].getUniqueValues(columnId);
3151
- for (let j = 0; j < values.length; j++) {
3152
- const value = values[j];
3153
- if (facetedUniqueValues.has(value)) {
3154
- var _facetedUniqueValues$;
3155
- facetedUniqueValues.set(value, ((_facetedUniqueValues$ = facetedUniqueValues.get(value)) != null ? _facetedUniqueValues$ : 0) + 1);
3156
- } else {
3157
- facetedUniqueValues.set(value, 1);
3158
- }
3159
- }
3160
- }
3161
- return facetedUniqueValues;
3162
- }, getMemoOptions(table.options, 'debugTable', `getFacetedUniqueValues_${columnId}`));
3163
- }
3164
-
3165
- function getFilteredRowModel() {
3166
- return table => memo(() => [table.getPreFilteredRowModel(), table.getState().columnFilters, table.getState().globalFilter], (rowModel, columnFilters, globalFilter) => {
3167
- if (!rowModel.rows.length || !(columnFilters != null && columnFilters.length) && !globalFilter) {
3168
- for (let i = 0; i < rowModel.flatRows.length; i++) {
3169
- rowModel.flatRows[i].columnFilters = {};
3170
- rowModel.flatRows[i].columnFiltersMeta = {};
3171
- }
3172
- return rowModel;
3173
- }
3174
- const resolvedColumnFilters = [];
3175
- const resolvedGlobalFilters = [];
3176
- (columnFilters != null ? columnFilters : []).forEach(d => {
3177
- var _filterFn$resolveFilt;
3178
- const column = table.getColumn(d.id);
3179
- if (!column) {
3180
- return;
3181
- }
3182
- const filterFn = column.getFilterFn();
3183
- if (!filterFn) {
3184
- if (process.env.NODE_ENV !== 'production') {
3185
- console.warn(`Could not find a valid 'column.filterFn' for column with the ID: ${column.id}.`);
3186
- }
3187
- return;
3188
- }
3189
- resolvedColumnFilters.push({
3190
- id: d.id,
3191
- filterFn,
3192
- resolvedValue: (_filterFn$resolveFilt = filterFn.resolveFilterValue == null ? void 0 : filterFn.resolveFilterValue(d.value)) != null ? _filterFn$resolveFilt : d.value
3193
- });
3194
- });
3195
- const filterableIds = (columnFilters != null ? columnFilters : []).map(d => d.id);
3196
- const globalFilterFn = table.getGlobalFilterFn();
3197
- const globallyFilterableColumns = table.getAllLeafColumns().filter(column => column.getCanGlobalFilter());
3198
- if (globalFilter && globalFilterFn && globallyFilterableColumns.length) {
3199
- filterableIds.push('__global__');
3200
- globallyFilterableColumns.forEach(column => {
3201
- var _globalFilterFn$resol;
3202
- resolvedGlobalFilters.push({
3203
- id: column.id,
3204
- filterFn: globalFilterFn,
3205
- resolvedValue: (_globalFilterFn$resol = globalFilterFn.resolveFilterValue == null ? void 0 : globalFilterFn.resolveFilterValue(globalFilter)) != null ? _globalFilterFn$resol : globalFilter
3206
- });
3207
- });
3208
- }
3209
- let currentColumnFilter;
3210
- let currentGlobalFilter;
3211
-
3212
- // Flag the prefiltered row model with each filter state
3213
- for (let j = 0; j < rowModel.flatRows.length; j++) {
3214
- const row = rowModel.flatRows[j];
3215
- row.columnFilters = {};
3216
- if (resolvedColumnFilters.length) {
3217
- for (let i = 0; i < resolvedColumnFilters.length; i++) {
3218
- currentColumnFilter = resolvedColumnFilters[i];
3219
- const id = currentColumnFilter.id;
3220
-
3221
- // Tag the row with the column filter state
3222
- row.columnFilters[id] = currentColumnFilter.filterFn(row, id, currentColumnFilter.resolvedValue, filterMeta => {
3223
- row.columnFiltersMeta[id] = filterMeta;
3224
- });
3225
- }
3226
- }
3227
- if (resolvedGlobalFilters.length) {
3228
- for (let i = 0; i < resolvedGlobalFilters.length; i++) {
3229
- currentGlobalFilter = resolvedGlobalFilters[i];
3230
- const id = currentGlobalFilter.id;
3231
- // Tag the row with the first truthy global filter state
3232
- if (currentGlobalFilter.filterFn(row, id, currentGlobalFilter.resolvedValue, filterMeta => {
3233
- row.columnFiltersMeta[id] = filterMeta;
3234
- })) {
3235
- row.columnFilters.__global__ = true;
3236
- break;
3237
- }
3238
- }
3239
- if (row.columnFilters.__global__ !== true) {
3240
- row.columnFilters.__global__ = false;
3241
- }
3242
- }
3243
- }
3244
- const filterRowsImpl = row => {
3245
- // Horizontally filter rows through each column
3246
- for (let i = 0; i < filterableIds.length; i++) {
3247
- if (row.columnFilters[filterableIds[i]] === false) {
3248
- return false;
3249
- }
3250
- }
3251
- return true;
3252
- };
3253
-
3254
- // Filter final rows using all of the active filters
3255
- return filterRows(rowModel.rows, filterRowsImpl, table);
3256
- }, getMemoOptions(table.options, 'debugTable', 'getFilteredRowModel', () => table._autoResetPageIndex()));
3257
- }
3258
-
3259
- function getGroupedRowModel() {
3260
- return table => memo(() => [table.getState().grouping, table.getPreGroupedRowModel()], (grouping, rowModel) => {
3261
- if (!rowModel.rows.length || !grouping.length) {
3262
- return rowModel;
3263
- }
3264
-
3265
- // Filter the grouping list down to columns that exist
3266
- const existingGrouping = grouping.filter(columnId => table.getColumn(columnId));
3267
- const groupedFlatRows = [];
3268
- const groupedRowsById = {};
3269
- // const onlyGroupedFlatRows: Row[] = [];
3270
- // const onlyGroupedRowsById: Record<RowId, Row> = {};
3271
- // const nonGroupedFlatRows: Row[] = [];
3272
- // const nonGroupedRowsById: Record<RowId, Row> = {};
3273
-
3274
- // Recursively group the data
3275
- const groupUpRecursively = function (rows, depth, parentId) {
3276
- if (depth === void 0) {
3277
- depth = 0;
3278
- }
3279
- // Grouping depth has been been met
3280
- // Stop grouping and simply rewrite thd depth and row relationships
3281
- if (depth >= existingGrouping.length) {
3282
- return rows.map(row => {
3283
- row.depth = depth;
3284
- groupedFlatRows.push(row);
3285
- groupedRowsById[row.id] = row;
3286
- if (row.subRows) {
3287
- row.subRows = groupUpRecursively(row.subRows, depth + 1, row.id);
3288
- }
3289
- return row;
3290
- });
3291
- }
3292
- const columnId = existingGrouping[depth];
3293
-
3294
- // Group the rows together for this level
3295
- const rowGroupsMap = groupBy(rows, columnId);
3296
-
3297
- // Peform aggregations for each group
3298
- const aggregatedGroupedRows = Array.from(rowGroupsMap.entries()).map((_ref, index) => {
3299
- let [groupingValue, groupedRows] = _ref;
3300
- let id = `${columnId}:${groupingValue}`;
3301
- id = parentId ? `${parentId}>${id}` : id;
3302
-
3303
- // First, Recurse to group sub rows before aggregation
3304
- const subRows = groupUpRecursively(groupedRows, depth + 1, id);
3305
-
3306
- // Flatten the leaf rows of the rows in this group
3307
- const leafRows = depth ? flattenBy(groupedRows, row => row.subRows) : groupedRows;
3308
- const row = createRow(table, id, leafRows[0].original, index, depth, undefined, parentId);
3309
- Object.assign(row, {
3310
- groupingColumnId: columnId,
3311
- groupingValue,
3312
- subRows,
3313
- leafRows,
3314
- getValue: columnId => {
3315
- // Don't aggregate columns that are in the grouping
3316
- if (existingGrouping.includes(columnId)) {
3317
- if (row._valuesCache.hasOwnProperty(columnId)) {
3318
- return row._valuesCache[columnId];
3319
- }
3320
- if (groupedRows[0]) {
3321
- var _groupedRows$0$getVal;
3322
- row._valuesCache[columnId] = (_groupedRows$0$getVal = groupedRows[0].getValue(columnId)) != null ? _groupedRows$0$getVal : undefined;
3323
- }
3324
- return row._valuesCache[columnId];
3325
- }
3326
- if (row._groupingValuesCache.hasOwnProperty(columnId)) {
3327
- return row._groupingValuesCache[columnId];
3328
- }
3329
-
3330
- // Aggregate the values
3331
- const column = table.getColumn(columnId);
3332
- const aggregateFn = column == null ? void 0 : column.getAggregationFn();
3333
- if (aggregateFn) {
3334
- row._groupingValuesCache[columnId] = aggregateFn(columnId, leafRows, groupedRows);
3335
- return row._groupingValuesCache[columnId];
3336
- }
3337
- }
3338
- });
3339
- subRows.forEach(subRow => {
3340
- groupedFlatRows.push(subRow);
3341
- groupedRowsById[subRow.id] = subRow;
3342
- // if (subRow.getIsGrouped?.()) {
3343
- // onlyGroupedFlatRows.push(subRow);
3344
- // onlyGroupedRowsById[subRow.id] = subRow;
3345
- // } else {
3346
- // nonGroupedFlatRows.push(subRow);
3347
- // nonGroupedRowsById[subRow.id] = subRow;
3348
- // }
3349
- });
3350
- return row;
3351
- });
3352
- return aggregatedGroupedRows;
3353
- };
3354
- const groupedRows = groupUpRecursively(rowModel.rows, 0);
3355
- groupedRows.forEach(subRow => {
3356
- groupedFlatRows.push(subRow);
3357
- groupedRowsById[subRow.id] = subRow;
3358
- // if (subRow.getIsGrouped?.()) {
3359
- // onlyGroupedFlatRows.push(subRow);
3360
- // onlyGroupedRowsById[subRow.id] = subRow;
3361
- // } else {
3362
- // nonGroupedFlatRows.push(subRow);
3363
- // nonGroupedRowsById[subRow.id] = subRow;
3364
- // }
3365
- });
3366
- return {
3367
- rows: groupedRows,
3368
- flatRows: groupedFlatRows,
3369
- rowsById: groupedRowsById
3370
- };
3371
- }, getMemoOptions(table.options, 'debugTable', 'getGroupedRowModel', () => {
3372
- table._queue(() => {
3373
- table._autoResetExpanded();
3374
- table._autoResetPageIndex();
3375
- });
3376
- }));
3377
- }
3378
- function groupBy(rows, columnId) {
3379
- const groupMap = new Map();
3380
- return rows.reduce((map, row) => {
3381
- const resKey = `${row.getGroupingValue(columnId)}`;
3382
- const previous = map.get(resKey);
3383
- if (!previous) {
3384
- map.set(resKey, [row]);
3385
- } else {
3386
- previous.push(row);
3387
- }
3388
- return map;
3389
- }, groupMap);
3390
- }
3391
-
3392
- function getPaginationRowModel(opts) {
3393
- return table => memo(() => [table.getState().pagination, table.getPrePaginationRowModel(), table.options.paginateExpandedRows ? undefined : table.getState().expanded], (pagination, rowModel) => {
3394
- if (!rowModel.rows.length) {
3395
- return rowModel;
3396
- }
3397
- const {
3398
- pageSize,
3399
- pageIndex
3400
- } = pagination;
3401
- let {
3402
- rows,
3403
- flatRows,
3404
- rowsById
3405
- } = rowModel;
3406
- const pageStart = pageSize * pageIndex;
3407
- const pageEnd = pageStart + pageSize;
3408
- rows = rows.slice(pageStart, pageEnd);
3409
- let paginatedRowModel;
3410
- if (!table.options.paginateExpandedRows) {
3411
- paginatedRowModel = expandRows({
3412
- rows,
3413
- flatRows,
3414
- rowsById
3415
- });
3416
- } else {
3417
- paginatedRowModel = {
3418
- rows,
3419
- flatRows,
3420
- rowsById
3421
- };
3422
- }
3423
- paginatedRowModel.flatRows = [];
3424
- const handleRow = row => {
3425
- paginatedRowModel.flatRows.push(row);
3426
- if (row.subRows.length) {
3427
- row.subRows.forEach(handleRow);
3428
- }
3429
- };
3430
- paginatedRowModel.rows.forEach(handleRow);
3431
- return paginatedRowModel;
3432
- }, getMemoOptions(table.options, 'debugTable', 'getPaginationRowModel'));
3433
- }
3434
-
3435
- function getSortedRowModel() {
3436
- return table => memo(() => [table.getState().sorting, table.getPreSortedRowModel()], (sorting, rowModel) => {
3437
- if (!rowModel.rows.length || !(sorting != null && sorting.length)) {
3438
- return rowModel;
3439
- }
3440
- const sortingState = table.getState().sorting;
3441
- const sortedFlatRows = [];
3442
-
3443
- // Filter out sortings that correspond to non existing columns
3444
- const availableSorting = sortingState.filter(sort => {
3445
- var _table$getColumn;
3446
- return (_table$getColumn = table.getColumn(sort.id)) == null ? void 0 : _table$getColumn.getCanSort();
3447
- });
3448
- const columnInfoById = {};
3449
- availableSorting.forEach(sortEntry => {
3450
- const column = table.getColumn(sortEntry.id);
3451
- if (!column) return;
3452
- columnInfoById[sortEntry.id] = {
3453
- sortUndefined: column.columnDef.sortUndefined,
3454
- invertSorting: column.columnDef.invertSorting,
3455
- sortingFn: column.getSortingFn()
3456
- };
3457
- });
3458
- const sortData = rows => {
3459
- // This will also perform a stable sorting using the row index
3460
- // if needed.
3461
- const sortedData = rows.map(row => ({
3462
- ...row
3463
- }));
3464
- sortedData.sort((rowA, rowB) => {
3465
- for (let i = 0; i < availableSorting.length; i += 1) {
3466
- var _sortEntry$desc;
3467
- const sortEntry = availableSorting[i];
3468
- const columnInfo = columnInfoById[sortEntry.id];
3469
- const sortUndefined = columnInfo.sortUndefined;
3470
- const isDesc = (_sortEntry$desc = sortEntry == null ? void 0 : sortEntry.desc) != null ? _sortEntry$desc : false;
3471
- let sortInt = 0;
3472
-
3473
- // All sorting ints should always return in ascending order
3474
- if (sortUndefined) {
3475
- const aValue = rowA.getValue(sortEntry.id);
3476
- const bValue = rowB.getValue(sortEntry.id);
3477
- const aUndefined = aValue === undefined;
3478
- const bUndefined = bValue === undefined;
3479
- if (aUndefined || bUndefined) {
3480
- if (sortUndefined === 'first') return aUndefined ? -1 : 1;
3481
- if (sortUndefined === 'last') return aUndefined ? 1 : -1;
3482
- sortInt = aUndefined && bUndefined ? 0 : aUndefined ? sortUndefined : -sortUndefined;
3483
- }
3484
- }
3485
- if (sortInt === 0) {
3486
- sortInt = columnInfo.sortingFn(rowA, rowB, sortEntry.id);
3487
- }
3488
-
3489
- // If sorting is non-zero, take care of desc and inversion
3490
- if (sortInt !== 0) {
3491
- if (isDesc) {
3492
- sortInt *= -1;
3493
- }
3494
- if (columnInfo.invertSorting) {
3495
- sortInt *= -1;
3496
- }
3497
- return sortInt;
3498
- }
3499
- }
3500
- return rowA.index - rowB.index;
3501
- });
3502
-
3503
- // If there are sub-rows, sort them
3504
- sortedData.forEach(row => {
3505
- var _row$subRows;
3506
- sortedFlatRows.push(row);
3507
- if ((_row$subRows = row.subRows) != null && _row$subRows.length) {
3508
- row.subRows = sortData(row.subRows);
3509
- }
3510
- });
3511
- return sortedData;
3512
- };
3513
- return {
3514
- rows: sortData(rowModel.rows),
3515
- flatRows: sortedFlatRows,
3516
- rowsById: rowModel.rowsById
3517
- };
3518
- }, getMemoOptions(table.options, 'debugTable', 'getSortedRowModel', () => table._autoResetPageIndex()));
3519
- }
3520
-
3521
- export { ColumnFaceting, ColumnFiltering, ColumnGrouping, ColumnOrdering, ColumnPinning, ColumnSizing, ColumnVisibility, GlobalFaceting, GlobalFiltering, Headers, RowExpanding, RowPagination, RowPinning, RowSelection, RowSorting, _getVisibleLeafColumns, aggregationFns, buildHeaderGroups, createCell, createColumn, createColumnHelper, createRow, createTable, defaultColumnSizing, expandRows, filterFns, flattenBy, functionalUpdate, getCoreRowModel, getExpandedRowModel, getFacetedMinMaxValues, getFacetedRowModel, getFacetedUniqueValues, getFilteredRowModel, getGroupedRowModel, getMemoOptions, getPaginationRowModel, getSortedRowModel, isFunction, isNumberArray, isRowSelected, isSubRowSelected, makeStateUpdater, memo, noop, orderColumns, passiveEventSupported, reSplitAlphaNumeric, selectRowsFn, shouldAutoRemoveFilter, sortingFns };
3522
- //# sourceMappingURL=index.esm.js.map