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