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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (259) hide show
  1. package/dist/cjs/aggregationFns.cjs +98 -0
  2. package/dist/cjs/aggregationFns.cjs.map +1 -0
  3. package/dist/cjs/aggregationFns.d.cts +14 -0
  4. package/dist/cjs/columnHelper.cjs +19 -0
  5. package/dist/cjs/columnHelper.cjs.map +1 -0
  6. package/dist/cjs/columnHelper.d.cts +9 -0
  7. package/dist/cjs/core/cell.cjs +38 -0
  8. package/dist/cjs/core/cell.cjs.map +1 -0
  9. package/dist/cjs/core/cell.d.cts +50 -0
  10. package/dist/cjs/core/column.cjs +81 -0
  11. package/dist/cjs/core/column.cjs.map +1 -0
  12. package/dist/cjs/core/column.d.cts +56 -0
  13. package/dist/cjs/core/headers.cjs +310 -0
  14. package/dist/cjs/core/headers.cjs.map +1 -0
  15. package/dist/cjs/core/headers.d.cts +195 -0
  16. package/dist/cjs/core/row.cjs +93 -0
  17. package/dist/cjs/core/row.cjs.map +1 -0
  18. package/dist/cjs/core/row.d.cts +92 -0
  19. package/dist/cjs/core/table.cjs +228 -0
  20. package/dist/cjs/core/table.cjs.map +1 -0
  21. package/dist/cjs/core/table.d.cts +221 -0
  22. package/dist/cjs/features/ColumnFaceting.cjs +29 -0
  23. package/dist/cjs/features/ColumnFaceting.cjs.map +1 -0
  24. package/dist/cjs/features/ColumnFaceting.d.cts +35 -0
  25. package/dist/cjs/features/ColumnFiltering.cjs +137 -0
  26. package/dist/cjs/features/ColumnFiltering.cjs.map +1 -0
  27. package/dist/cjs/features/ColumnFiltering.d.cts +195 -0
  28. package/dist/cjs/features/ColumnGrouping.cjs +134 -0
  29. package/dist/cjs/features/ColumnGrouping.cjs.map +1 -0
  30. package/dist/cjs/features/ColumnGrouping.d.cts +202 -0
  31. package/dist/cjs/features/ColumnOrdering.cjs +76 -0
  32. package/dist/cjs/features/ColumnOrdering.cjs.map +1 -0
  33. package/dist/cjs/features/ColumnOrdering.d.cts +54 -0
  34. package/dist/cjs/features/ColumnPinning.cjs +145 -0
  35. package/dist/cjs/features/ColumnPinning.cjs.map +1 -0
  36. package/dist/cjs/features/ColumnPinning.d.cts +127 -0
  37. package/dist/cjs/features/ColumnSizing.cjs +308 -0
  38. package/dist/cjs/features/ColumnSizing.cjs.map +1 -0
  39. package/dist/cjs/features/ColumnSizing.d.cts +194 -0
  40. package/dist/cjs/features/ColumnVisibility.cjs +144 -0
  41. package/dist/cjs/features/ColumnVisibility.cjs.map +1 -0
  42. package/dist/cjs/features/ColumnVisibility.d.cts +130 -0
  43. package/dist/cjs/features/GlobalFaceting.cjs +29 -0
  44. package/dist/cjs/features/GlobalFaceting.cjs.map +1 -0
  45. package/dist/cjs/features/GlobalFaceting.d.cts +27 -0
  46. package/dist/cjs/features/GlobalFiltering.cjs +50 -0
  47. package/dist/cjs/features/GlobalFiltering.cjs.map +1 -0
  48. package/dist/cjs/features/GlobalFiltering.d.cts +80 -0
  49. package/dist/cjs/features/RowExpanding.cjs +154 -0
  50. package/dist/cjs/features/RowExpanding.cjs.map +1 -0
  51. package/dist/cjs/features/RowExpanding.d.cts +155 -0
  52. package/dist/cjs/features/RowPagination.cjs +162 -0
  53. package/dist/cjs/features/RowPagination.cjs.map +1 -0
  54. package/dist/cjs/features/RowPagination.d.cts +166 -0
  55. package/dist/cjs/features/RowPinning.cjs +133 -0
  56. package/dist/cjs/features/RowPinning.cjs.map +1 -0
  57. package/dist/cjs/features/RowPinning.d.cts +99 -0
  58. package/dist/cjs/features/RowSelection.cjs +298 -0
  59. package/dist/cjs/features/RowSelection.cjs.map +1 -0
  60. package/dist/cjs/features/RowSelection.d.cts +177 -0
  61. package/dist/cjs/features/RowSorting.cjs +201 -0
  62. package/dist/cjs/features/RowSorting.cjs.map +1 -0
  63. package/dist/cjs/features/RowSorting.d.cts +238 -0
  64. package/dist/cjs/filterFns.cjs +88 -0
  65. package/dist/cjs/filterFns.cjs.map +1 -0
  66. package/dist/cjs/filterFns.d.cts +14 -0
  67. package/{build/lib/index.js → dist/cjs/index.cjs} +36 -49
  68. package/dist/cjs/index.cjs.map +1 -0
  69. package/dist/cjs/index.d.cts +34 -0
  70. package/{build/lib/sortingFns.js → dist/cjs/sortingFns.cjs} +23 -52
  71. package/dist/cjs/sortingFns.cjs.map +1 -0
  72. package/dist/cjs/sortingFns.d.cts +12 -0
  73. package/dist/cjs/types.d.cts +120 -0
  74. package/{build/lib/utils/filterRowsUtils.js → dist/cjs/utils/filterRowsUtils.cjs} +34 -46
  75. package/dist/cjs/utils/filterRowsUtils.cjs.map +1 -0
  76. package/dist/cjs/utils/filterRowsUtils.d.cts +3 -0
  77. package/dist/cjs/utils/getCoreRowModel.cjs +54 -0
  78. package/dist/cjs/utils/getCoreRowModel.cjs.map +1 -0
  79. package/dist/cjs/utils/getCoreRowModel.d.cts +3 -0
  80. package/dist/cjs/utils/getExpandedRowModel.cjs +41 -0
  81. package/dist/cjs/utils/getExpandedRowModel.cjs.map +1 -0
  82. package/dist/cjs/utils/getExpandedRowModel.d.cts +8 -0
  83. package/dist/cjs/utils/getFacetedMinMaxValues.cjs +36 -0
  84. package/dist/cjs/utils/getFacetedMinMaxValues.cjs.map +1 -0
  85. package/dist/cjs/utils/getFacetedMinMaxValues.d.cts +3 -0
  86. package/dist/cjs/utils/getFacetedRowModel.cjs +35 -0
  87. package/dist/cjs/utils/getFacetedRowModel.cjs.map +1 -0
  88. package/dist/cjs/utils/getFacetedRowModel.d.cts +3 -0
  89. package/dist/cjs/utils/getFacetedUniqueValues.cjs +38 -0
  90. package/dist/cjs/utils/getFacetedUniqueValues.cjs.map +1 -0
  91. package/dist/cjs/utils/getFacetedUniqueValues.d.cts +3 -0
  92. package/dist/cjs/utils/getFilteredRowModel.cjs +116 -0
  93. package/dist/cjs/utils/getFilteredRowModel.cjs.map +1 -0
  94. package/dist/cjs/utils/getFilteredRowModel.d.cts +3 -0
  95. package/dist/cjs/utils/getGroupedRowModel.cjs +118 -0
  96. package/dist/cjs/utils/getGroupedRowModel.cjs.map +1 -0
  97. package/dist/cjs/utils/getGroupedRowModel.d.cts +3 -0
  98. package/dist/cjs/utils/getPaginationRowModel.cjs +49 -0
  99. package/dist/cjs/utils/getPaginationRowModel.cjs.map +1 -0
  100. package/dist/cjs/utils/getPaginationRowModel.d.cts +5 -0
  101. package/dist/cjs/utils/getSortedRowModel.cjs +91 -0
  102. package/dist/cjs/utils/getSortedRowModel.cjs.map +1 -0
  103. package/dist/cjs/utils/getSortedRowModel.d.cts +3 -0
  104. package/{build/lib/utils.js → dist/cjs/utils.cjs} +30 -41
  105. package/dist/cjs/utils.cjs.map +1 -0
  106. package/dist/cjs/utils.d.cts +39 -0
  107. package/{build/lib → dist/esm}/aggregationFns.d.ts +2 -1
  108. package/dist/esm/aggregationFns.js +98 -0
  109. package/dist/esm/aggregationFns.js.map +1 -0
  110. package/{build/lib → dist/esm}/columnHelper.d.ts +3 -2
  111. package/dist/esm/columnHelper.js +19 -0
  112. package/{build/lib → dist/esm}/columnHelper.js.map +1 -1
  113. package/{build/lib → dist/esm}/core/cell.d.ts +1 -0
  114. package/dist/esm/core/cell.js +38 -0
  115. package/{build/lib → dist/esm}/core/cell.js.map +1 -1
  116. package/{build/lib → dist/esm}/core/column.d.ts +1 -0
  117. package/dist/esm/core/column.js +81 -0
  118. package/{build/lib → dist/esm}/core/column.js.map +1 -1
  119. package/{build/lib → dist/esm}/core/headers.d.ts +1 -0
  120. package/dist/esm/core/headers.js +310 -0
  121. package/{build/lib → dist/esm}/core/headers.js.map +1 -1
  122. package/{build/lib → dist/esm}/core/row.d.ts +1 -0
  123. package/dist/esm/core/row.js +93 -0
  124. package/{build/lib → dist/esm}/core/row.js.map +1 -1
  125. package/{build/lib → dist/esm}/core/table.d.ts +1 -0
  126. package/dist/esm/core/table.js +228 -0
  127. package/{build/lib → dist/esm}/core/table.js.map +1 -1
  128. package/{build/lib → dist/esm}/features/ColumnFaceting.d.ts +1 -0
  129. package/{build/lib → dist/esm}/features/ColumnFaceting.js +5 -18
  130. package/{build/lib → dist/esm}/features/ColumnFaceting.js.map +1 -1
  131. package/{build/lib → dist/esm}/features/ColumnFiltering.d.ts +1 -0
  132. package/dist/esm/features/ColumnFiltering.js +137 -0
  133. package/{build/lib → dist/esm}/features/ColumnFiltering.js.map +1 -1
  134. package/{build/lib → dist/esm}/features/ColumnGrouping.d.ts +1 -0
  135. package/dist/esm/features/ColumnGrouping.js +134 -0
  136. package/{build/lib → dist/esm}/features/ColumnGrouping.js.map +1 -1
  137. package/{build/lib → dist/esm}/features/ColumnOrdering.d.ts +1 -0
  138. package/dist/esm/features/ColumnOrdering.js +76 -0
  139. package/{build/lib → dist/esm}/features/ColumnOrdering.js.map +1 -1
  140. package/{build/lib → dist/esm}/features/ColumnPinning.d.ts +1 -0
  141. package/dist/esm/features/ColumnPinning.js +145 -0
  142. package/{build/lib → dist/esm}/features/ColumnPinning.js.map +1 -1
  143. package/{build/lib → dist/esm}/features/ColumnSizing.d.ts +2 -1
  144. package/dist/esm/features/ColumnSizing.js +308 -0
  145. package/{build/lib → dist/esm}/features/ColumnSizing.js.map +1 -1
  146. package/{build/lib → dist/esm}/features/ColumnVisibility.d.ts +1 -0
  147. package/dist/esm/features/ColumnVisibility.js +144 -0
  148. package/{build/lib → dist/esm}/features/ColumnVisibility.js.map +1 -1
  149. package/{build/lib → dist/esm}/features/GlobalFaceting.d.ts +1 -0
  150. package/{build/lib → dist/esm}/features/GlobalFaceting.js +8 -21
  151. package/{build/lib → dist/esm}/features/GlobalFaceting.js.map +1 -1
  152. package/{build/lib → dist/esm}/features/GlobalFiltering.d.ts +1 -0
  153. package/dist/esm/features/GlobalFiltering.js +50 -0
  154. package/{build/lib → dist/esm}/features/GlobalFiltering.js.map +1 -1
  155. package/{build/lib → dist/esm}/features/RowExpanding.d.ts +1 -0
  156. package/{build/lib → dist/esm}/features/RowExpanding.js +40 -59
  157. package/{build/lib → dist/esm}/features/RowExpanding.js.map +1 -1
  158. package/{build/lib → dist/esm}/features/RowPagination.d.ts +1 -0
  159. package/dist/esm/features/RowPagination.js +162 -0
  160. package/{build/lib → dist/esm}/features/RowPagination.js.map +1 -1
  161. package/{build/lib → dist/esm}/features/RowPinning.d.ts +1 -0
  162. package/dist/esm/features/RowPinning.js +133 -0
  163. package/{build/lib → dist/esm}/features/RowPinning.js.map +1 -1
  164. package/{build/lib → dist/esm}/features/RowSelection.d.ts +1 -0
  165. package/dist/esm/features/RowSelection.js +298 -0
  166. package/{build/lib → dist/esm}/features/RowSelection.js.map +1 -1
  167. package/{build/lib → dist/esm}/features/RowSorting.d.ts +1 -0
  168. package/dist/esm/features/RowSorting.js +201 -0
  169. package/{build/lib → dist/esm}/features/RowSorting.js.map +1 -1
  170. package/{build/lib → dist/esm}/filterFns.d.ts +2 -1
  171. package/dist/esm/filterFns.js +88 -0
  172. package/dist/esm/filterFns.js.map +1 -0
  173. package/dist/esm/index.d.ts +34 -0
  174. package/dist/esm/index.js +87 -0
  175. package/dist/esm/index.js.map +1 -0
  176. package/{build/lib → dist/esm}/sortingFns.d.ts +2 -1
  177. package/dist/esm/sortingFns.js +91 -0
  178. package/dist/esm/sortingFns.js.map +1 -0
  179. package/{build/lib → dist/esm}/types.d.ts +21 -20
  180. package/{build/lib → dist/esm}/utils/filterRowsUtils.d.ts +1 -0
  181. package/dist/esm/utils/filterRowsUtils.js +99 -0
  182. package/dist/esm/utils/filterRowsUtils.js.map +1 -0
  183. package/{build/lib → dist/esm}/utils/getCoreRowModel.d.ts +1 -0
  184. package/dist/esm/utils/getCoreRowModel.js +54 -0
  185. package/{build/lib → dist/esm}/utils/getCoreRowModel.js.map +1 -1
  186. package/{build/lib → dist/esm}/utils/getExpandedRowModel.d.ts +1 -0
  187. package/dist/esm/utils/getExpandedRowModel.js +41 -0
  188. package/dist/esm/utils/getExpandedRowModel.js.map +1 -0
  189. package/{build/lib → dist/esm}/utils/getFacetedMinMaxValues.d.ts +1 -0
  190. package/dist/esm/utils/getFacetedMinMaxValues.js +36 -0
  191. package/dist/esm/utils/getFacetedMinMaxValues.js.map +1 -0
  192. package/{build/lib → dist/esm}/utils/getFacetedRowModel.d.ts +1 -0
  193. package/dist/esm/utils/getFacetedRowModel.js +35 -0
  194. package/{build/lib → dist/esm}/utils/getFacetedRowModel.js.map +1 -1
  195. package/{build/lib → dist/esm}/utils/getFacetedUniqueValues.d.ts +1 -0
  196. package/dist/esm/utils/getFacetedUniqueValues.js +38 -0
  197. package/dist/esm/utils/getFacetedUniqueValues.js.map +1 -0
  198. package/{build/lib → dist/esm}/utils/getFilteredRowModel.d.ts +1 -0
  199. package/dist/esm/utils/getFilteredRowModel.js +116 -0
  200. package/{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/{build/lib → dist/esm}/utils/getGroupedRowModel.js.map +1 -1
  204. package/{build/lib → dist/esm}/utils/getPaginationRowModel.d.ts +1 -0
  205. package/dist/esm/utils/getPaginationRowModel.js +49 -0
  206. package/dist/esm/utils/getPaginationRowModel.js.map +1 -0
  207. package/{build/lib → dist/esm}/utils/getSortedRowModel.d.ts +1 -0
  208. package/dist/esm/utils/getSortedRowModel.js +91 -0
  209. package/{build/lib → dist/esm}/utils/getSortedRowModel.js.map +1 -1
  210. package/{build/lib → dist/esm}/utils.d.ts +2 -1
  211. package/dist/esm/utils.js +100 -0
  212. package/{build/lib → dist/esm}/utils.js.map +1 -1
  213. package/package.json +15 -19
  214. package/build/lib/aggregationFns.js +0 -108
  215. package/build/lib/aggregationFns.js.map +0 -1
  216. package/build/lib/columnHelper.js +0 -71
  217. package/build/lib/core/cell.js +0 -42
  218. package/build/lib/core/column.js +0 -80
  219. package/build/lib/core/headers.js +0 -270
  220. package/build/lib/core/row.js +0 -89
  221. package/build/lib/core/table.js +0 -212
  222. package/build/lib/features/ColumnFiltering.js +0 -151
  223. package/build/lib/features/ColumnGrouping.js +0 -142
  224. package/build/lib/features/ColumnOrdering.js +0 -84
  225. package/build/lib/features/ColumnPinning.js +0 -130
  226. package/build/lib/features/ColumnSizing.js +0 -270
  227. package/build/lib/features/ColumnVisibility.js +0 -99
  228. package/build/lib/features/GlobalFiltering.js +0 -63
  229. package/build/lib/features/RowPagination.js +0 -169
  230. package/build/lib/features/RowPinning.js +0 -145
  231. package/build/lib/features/RowSelection.js +0 -391
  232. package/build/lib/features/RowSorting.js +0 -226
  233. package/build/lib/filterFns.js +0 -96
  234. package/build/lib/filterFns.js.map +0 -1
  235. package/build/lib/index.d.ts +0 -34
  236. package/build/lib/index.esm.js +0 -3522
  237. package/build/lib/index.esm.js.map +0 -1
  238. package/build/lib/index.js.map +0 -1
  239. package/build/lib/index.mjs +0 -3522
  240. package/build/lib/index.mjs.map +0 -1
  241. package/build/lib/sortingFns.js.map +0 -1
  242. package/build/lib/utils/filterRowsUtils.js.map +0 -1
  243. package/build/lib/utils/getCoreRowModel.js +0 -65
  244. package/build/lib/utils/getExpandedRowModel.js +0 -46
  245. package/build/lib/utils/getExpandedRowModel.js.map +0 -1
  246. package/build/lib/utils/getFacetedMinMaxValues.js +0 -43
  247. package/build/lib/utils/getFacetedMinMaxValues.js.map +0 -1
  248. package/build/lib/utils/getFacetedRowModel.js +0 -36
  249. package/build/lib/utils/getFacetedUniqueValues.js +0 -39
  250. package/build/lib/utils/getFacetedUniqueValues.js.map +0 -1
  251. package/build/lib/utils/getFilteredRowModel.js +0 -111
  252. package/build/lib/utils/getGroupedRowModel.js +0 -150
  253. package/build/lib/utils/getPaginationRowModel.js +0 -60
  254. package/build/lib/utils/getPaginationRowModel.js.map +0 -1
  255. package/build/lib/utils/getSortedRowModel.js +0 -102
  256. package/build/umd/index.development.js +0 -3578
  257. package/build/umd/index.development.js.map +0 -1
  258. package/build/umd/index.production.js +0 -12
  259. package/build/umd/index.production.js.map +0 -1
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const sortingFns = require("../sortingFns.cjs");
4
+ const utils = require("../utils.cjs");
5
+ const RowSorting = {
6
+ getInitialState: (state) => {
7
+ return {
8
+ sorting: [],
9
+ ...state
10
+ };
11
+ },
12
+ getDefaultColumnDef: () => {
13
+ return {
14
+ sortingFn: "auto",
15
+ sortUndefined: 1
16
+ };
17
+ },
18
+ getDefaultOptions: (table) => {
19
+ return {
20
+ onSortingChange: utils.makeStateUpdater("sorting", table),
21
+ isMultiSortEvent: (e) => {
22
+ return e.shiftKey;
23
+ }
24
+ };
25
+ },
26
+ createColumn: (column, table) => {
27
+ column.getAutoSortingFn = () => {
28
+ const firstRows = table.getFilteredRowModel().flatRows.slice(10);
29
+ let isString = false;
30
+ for (const row of firstRows) {
31
+ const value = row == null ? void 0 : row.getValue(column.id);
32
+ if (Object.prototype.toString.call(value) === "[object Date]") {
33
+ return sortingFns.sortingFns.datetime;
34
+ }
35
+ if (typeof value === "string") {
36
+ isString = true;
37
+ if (value.split(sortingFns.reSplitAlphaNumeric).length > 1) {
38
+ return sortingFns.sortingFns.alphanumeric;
39
+ }
40
+ }
41
+ }
42
+ if (isString) {
43
+ return sortingFns.sortingFns.text;
44
+ }
45
+ return sortingFns.sortingFns.basic;
46
+ };
47
+ column.getAutoSortDir = () => {
48
+ const firstRow = table.getFilteredRowModel().flatRows[0];
49
+ const value = firstRow == null ? void 0 : firstRow.getValue(column.id);
50
+ if (typeof value === "string") {
51
+ return "asc";
52
+ }
53
+ return "desc";
54
+ };
55
+ column.getSortingFn = () => {
56
+ var _a;
57
+ if (!column) {
58
+ throw new Error();
59
+ }
60
+ return utils.isFunction(column.columnDef.sortingFn) ? column.columnDef.sortingFn : column.columnDef.sortingFn === "auto" ? column.getAutoSortingFn() : ((_a = table.options.sortingFns) == null ? void 0 : _a[column.columnDef.sortingFn]) ?? sortingFns.sortingFns[column.columnDef.sortingFn];
61
+ };
62
+ column.toggleSorting = (desc, multi) => {
63
+ const nextSortingOrder = column.getNextSortingOrder();
64
+ const hasManualValue = typeof desc !== "undefined" && desc !== null;
65
+ table.setSorting((old) => {
66
+ const existingSorting = old == null ? void 0 : old.find((d) => d.id === column.id);
67
+ const existingIndex = old == null ? void 0 : old.findIndex((d) => d.id === column.id);
68
+ let newSorting = [];
69
+ let sortAction;
70
+ let nextDesc = hasManualValue ? desc : nextSortingOrder === "desc";
71
+ if ((old == null ? void 0 : old.length) && column.getCanMultiSort() && multi) {
72
+ if (existingSorting) {
73
+ sortAction = "toggle";
74
+ } else {
75
+ sortAction = "add";
76
+ }
77
+ } else {
78
+ if ((old == null ? void 0 : old.length) && existingIndex !== old.length - 1) {
79
+ sortAction = "replace";
80
+ } else if (existingSorting) {
81
+ sortAction = "toggle";
82
+ } else {
83
+ sortAction = "replace";
84
+ }
85
+ }
86
+ if (sortAction === "toggle") {
87
+ if (!hasManualValue) {
88
+ if (!nextSortingOrder) {
89
+ sortAction = "remove";
90
+ }
91
+ }
92
+ }
93
+ if (sortAction === "add") {
94
+ newSorting = [
95
+ ...old,
96
+ {
97
+ id: column.id,
98
+ desc: nextDesc
99
+ }
100
+ ];
101
+ newSorting.splice(
102
+ 0,
103
+ newSorting.length - (table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER)
104
+ );
105
+ } else if (sortAction === "toggle") {
106
+ newSorting = old.map((d) => {
107
+ if (d.id === column.id) {
108
+ return {
109
+ ...d,
110
+ desc: nextDesc
111
+ };
112
+ }
113
+ return d;
114
+ });
115
+ } else if (sortAction === "remove") {
116
+ newSorting = old.filter((d) => d.id !== column.id);
117
+ } else {
118
+ newSorting = [
119
+ {
120
+ id: column.id,
121
+ desc: nextDesc
122
+ }
123
+ ];
124
+ }
125
+ return newSorting;
126
+ });
127
+ };
128
+ column.getFirstSortDir = () => {
129
+ const sortDescFirst = column.columnDef.sortDescFirst ?? table.options.sortDescFirst ?? column.getAutoSortDir() === "desc";
130
+ return sortDescFirst ? "desc" : "asc";
131
+ };
132
+ column.getNextSortingOrder = (multi) => {
133
+ const firstSortDirection = column.getFirstSortDir();
134
+ const isSorted = column.getIsSorted();
135
+ if (!isSorted) {
136
+ return firstSortDirection;
137
+ }
138
+ if (isSorted !== firstSortDirection && (table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general
139
+ (multi ? table.options.enableMultiRemove ?? true : true)) {
140
+ return false;
141
+ }
142
+ return isSorted === "desc" ? "asc" : "desc";
143
+ };
144
+ column.getCanSort = () => {
145
+ return (column.columnDef.enableSorting ?? true) && (table.options.enableSorting ?? true) && !!column.accessorFn;
146
+ };
147
+ column.getCanMultiSort = () => {
148
+ return column.columnDef.enableMultiSort ?? table.options.enableMultiSort ?? !!column.accessorFn;
149
+ };
150
+ column.getIsSorted = () => {
151
+ var _a;
152
+ const columnSort = (_a = table.getState().sorting) == null ? void 0 : _a.find((d) => d.id === column.id);
153
+ return !columnSort ? false : columnSort.desc ? "desc" : "asc";
154
+ };
155
+ column.getSortIndex = () => {
156
+ var _a;
157
+ return ((_a = table.getState().sorting) == null ? void 0 : _a.findIndex((d) => d.id === column.id)) ?? -1;
158
+ };
159
+ column.clearSorting = () => {
160
+ table.setSorting(
161
+ (old) => (old == null ? void 0 : old.length) ? old.filter((d) => d.id !== column.id) : []
162
+ );
163
+ };
164
+ column.getToggleSortingHandler = () => {
165
+ const canSort = column.getCanSort();
166
+ return (e) => {
167
+ var _a, _b, _c, _d;
168
+ if (!canSort)
169
+ return;
170
+ (_a = e.persist) == null ? void 0 : _a.call(e);
171
+ (_d = column.toggleSorting) == null ? void 0 : _d.call(
172
+ column,
173
+ void 0,
174
+ column.getCanMultiSort() ? (_c = (_b = table.options).isMultiSortEvent) == null ? void 0 : _c.call(_b, e) : false
175
+ );
176
+ };
177
+ };
178
+ },
179
+ createTable: (table) => {
180
+ table.setSorting = (updater) => {
181
+ var _a, _b;
182
+ return (_b = (_a = table.options).onSortingChange) == null ? void 0 : _b.call(_a, updater);
183
+ };
184
+ table.resetSorting = (defaultState) => {
185
+ var _a;
186
+ table.setSorting(defaultState ? [] : ((_a = table.initialState) == null ? void 0 : _a.sorting) ?? []);
187
+ };
188
+ table.getPreSortedRowModel = () => table.getGroupedRowModel();
189
+ table.getSortedRowModel = () => {
190
+ if (!table._getSortedRowModel && table.options.getSortedRowModel) {
191
+ table._getSortedRowModel = table.options.getSortedRowModel(table);
192
+ }
193
+ if (table.options.manualSorting || !table._getSortedRowModel) {
194
+ return table.getPreSortedRowModel();
195
+ }
196
+ return table._getSortedRowModel();
197
+ };
198
+ }
199
+ };
200
+ exports.RowSorting = RowSorting;
201
+ //# sourceMappingURL=RowSorting.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RowSorting.cjs","sources":["../../../src/features/RowSorting.ts"],"sourcesContent":["import { RowModel } from '..'\nimport {\n BuiltInSortingFn,\n reSplitAlphaNumeric,\n sortingFns,\n} from '../sortingFns'\n\nimport {\n Column,\n OnChangeFn,\n Table,\n Row,\n Updater,\n RowData,\n SortingFns,\n TableFeature,\n} from '../types'\n\nimport { isFunction, makeStateUpdater } from '../utils'\n\nexport type SortDirection = 'asc' | 'desc'\n\nexport interface ColumnSort {\n desc: boolean\n id: string\n}\n\nexport type SortingState = ColumnSort[]\n\nexport interface SortingTableState {\n sorting: SortingState\n}\n\nexport interface SortingFn<TData extends RowData> {\n (rowA: Row<TData>, rowB: Row<TData>, columnId: string): number\n}\n\nexport type CustomSortingFns<TData extends RowData> = Record<\n string,\n SortingFn<TData>\n>\n\nexport type SortingFnOption<TData extends RowData> =\n | 'auto'\n | keyof SortingFns\n | BuiltInSortingFn\n | SortingFn<TData>\n\nexport interface SortingColumnDef<TData extends RowData> {\n /**\n * Enables/Disables multi-sorting for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiSort?: boolean\n /**\n * Enables/Disables sorting for this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSorting?: boolean\n /**\n * Inverts the order of the sorting for this column. This is useful for values that have an inverted best/worst scale where lower numbers are better, eg. a ranking (1st, 2nd, 3rd) or golf-like scoring\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#invertsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n invertSorting?: boolean\n /**\n * Set to `true` for sorting toggles on this column to start in the descending direction.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortDescFirst?: boolean\n /**\n * The sorting function to use with this column.\n * - A `string` referencing a built-in sorting function\n * - A custom sorting function\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortingFn?: SortingFnOption<TData>\n /**\n * The priority of undefined values when sorting this column.\n * - `false`\n * - Undefined values will be considered tied and need to be sorted by the next column filter or original index (whichever applies)\n * - `-1`\n * - Undefined values will be sorted with higher priority (ascending) (if ascending, undefined will appear on the beginning of the list)\n * - `1`\n * - Undefined values will be sorted with lower priority (descending) (if ascending, undefined will appear on the end of the list)\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortundefined)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortUndefined?: false | -1 | 1 | 'first' | 'last'\n}\n\nexport interface SortingColumn<TData extends RowData> {\n /**\n * Removes this column from the table's sorting state\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#clearsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n clearSorting: () => void\n /**\n * Returns a sort direction automatically inferred based on the columns values.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortdir)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getAutoSortDir: () => SortDirection\n /**\n * Returns a sorting function automatically inferred based on the columns values.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getAutoSortingFn: () => SortingFn<TData>\n /**\n * Returns whether this column can be multi-sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcanmultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getCanMultiSort: () => boolean\n /**\n * Returns whether this column can be sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcansort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getCanSort: () => boolean\n /**\n * Returns the first direction that should be used when sorting this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getfirstsortdir)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getFirstSortDir: () => SortDirection\n /**\n * Returns the current sort direction of this column.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getissorted)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getIsSorted: () => false | SortDirection\n /**\n * Returns the next sorting order.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getnextsortingorder)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getNextSortingOrder: () => SortDirection | false\n /**\n * Returns the index position of this column's sorting within the sorting state\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortindex)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortIndex: () => number\n /**\n * Returns the resolved sorting function to be used for this column\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortingfn)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortingFn: () => SortingFn<TData>\n /**\n * Returns a function that can be used to toggle this column's sorting state. This is useful for attaching a click handler to the column header.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#gettogglesortinghandler)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getToggleSortingHandler: () => undefined | ((event: unknown) => void)\n /**\n * Toggles this columns sorting state. If `desc` is provided, it will force the sort direction to that value. If `isMulti` is provided, it will additivity multi-sort the column (or toggle it if it is already sorted).\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#togglesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n toggleSorting: (desc?: boolean, isMulti?: boolean) => void\n}\n\ninterface SortingOptionsBase {\n /**\n * Enables/disables the ability to remove multi-sorts\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultiremove)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiRemove?: boolean\n /**\n * Enables/Disables multi-sorting for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableMultiSort?: boolean\n /**\n * Enables/Disables sorting for the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSorting?: boolean\n /**\n * Enables/Disables the ability to remove sorting for the table.\n * - If `true` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'none' -> ...\n * - If `false` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'desc' -> 'asc' -> ...\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesortingremoval)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n enableSortingRemoval?: boolean\n /**\n * This function is used to retrieve the sorted row model. If using server-side sorting, this function is not required. To use client-side sorting, pass the exported `getSortedRowModel()` from your adapter to your table or implement your own.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortedRowModel?: (table: Table<any>) => () => RowModel<any>\n /**\n * Pass a custom function that will be used to determine if a multi-sort event should be triggered. It is passed the event from the sort toggle handler and should return `true` if the event should trigger a multi-sort.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#ismultisortevent)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n isMultiSortEvent?: (e: unknown) => boolean\n /**\n * Enables manual sorting for the table. If this is `true`, you will be expected to sort your data before it is passed to the table. This is useful if you are doing server-side sorting.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#manualsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n manualSorting?: boolean\n /**\n * Set a maximum number of columns that can be multi-sorted.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#maxmultisortcolcount)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n maxMultiSortColCount?: number\n /**\n * If provided, this function will be called with an `updaterFn` when `state.sorting` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#onsortingchange)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n onSortingChange?: OnChangeFn<SortingState>\n /**\n * If `true`, all sorts will default to descending as their first toggle state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n sortDescFirst?: boolean\n}\n\ntype ResolvedSortingFns = keyof SortingFns extends never\n ? {\n sortingFns?: Record<string, SortingFn<any>>\n }\n : {\n sortingFns: Record<keyof SortingFns, SortingFn<any>>\n }\n\nexport interface SortingOptions<TData extends RowData>\n extends SortingOptionsBase,\n ResolvedSortingFns {}\n\nexport interface SortingInstance<TData extends RowData> {\n _getSortedRowModel?: () => RowModel<TData>\n /**\n * Returns the row model for the table before any sorting has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getpresortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getPreSortedRowModel: () => RowModel<TData>\n /**\n * Returns the row model for the table after sorting has been applied.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n getSortedRowModel: () => RowModel<TData>\n /**\n * Resets the **sorting** state to `initialState.sorting`, or `true` can be passed to force a default blank state reset to `[]`.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n resetSorting: (defaultState?: boolean) => void\n /**\n * Sets or updates the `state.sorting` state.\n * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#setsorting)\n * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)\n */\n setSorting: (updater: Updater<SortingState>) => void\n}\n\n//\n\nexport const RowSorting: TableFeature = {\n getInitialState: (state): SortingTableState => {\n return {\n sorting: [],\n ...state,\n }\n },\n\n getDefaultColumnDef: <TData extends RowData>(): SortingColumnDef<TData> => {\n return {\n sortingFn: 'auto',\n sortUndefined: 1,\n }\n },\n\n getDefaultOptions: <TData extends RowData>(\n table: Table<TData>\n ): SortingOptions<TData> => {\n return {\n onSortingChange: makeStateUpdater('sorting', table),\n isMultiSortEvent: (e: unknown) => {\n return (e as MouseEvent).shiftKey\n },\n }\n },\n\n createColumn: <TData extends RowData, TValue>(\n column: Column<TData, TValue>,\n table: Table<TData>\n ): void => {\n column.getAutoSortingFn = () => {\n const firstRows = table.getFilteredRowModel().flatRows.slice(10)\n\n let isString = false\n\n for (const row of firstRows) {\n const value = row?.getValue(column.id)\n\n if (Object.prototype.toString.call(value) === '[object Date]') {\n return sortingFns.datetime\n }\n\n if (typeof value === 'string') {\n isString = true\n\n if (value.split(reSplitAlphaNumeric).length > 1) {\n return sortingFns.alphanumeric\n }\n }\n }\n\n if (isString) {\n return sortingFns.text\n }\n\n return sortingFns.basic\n }\n column.getAutoSortDir = () => {\n const firstRow = table.getFilteredRowModel().flatRows[0]\n\n const value = firstRow?.getValue(column.id)\n\n if (typeof value === 'string') {\n return 'asc'\n }\n\n return 'desc'\n }\n column.getSortingFn = () => {\n if (!column) {\n throw new Error()\n }\n\n return isFunction(column.columnDef.sortingFn)\n ? column.columnDef.sortingFn\n : column.columnDef.sortingFn === 'auto'\n ? column.getAutoSortingFn()\n : table.options.sortingFns?.[column.columnDef.sortingFn as string] ??\n sortingFns[column.columnDef.sortingFn as BuiltInSortingFn]\n }\n column.toggleSorting = (desc, multi) => {\n // if (column.columns.length) {\n // column.columns.forEach((c, i) => {\n // if (c.id) {\n // table.toggleColumnSorting(c.id, undefined, multi || !!i)\n // }\n // })\n // return\n // }\n\n // this needs to be outside of table.setSorting to be in sync with rerender\n const nextSortingOrder = column.getNextSortingOrder()\n const hasManualValue = typeof desc !== 'undefined' && desc !== null\n\n table.setSorting(old => {\n // Find any existing sorting for this column\n const existingSorting = old?.find(d => d.id === column.id)\n const existingIndex = old?.findIndex(d => d.id === column.id)\n\n let newSorting: SortingState = []\n\n // What should we do with this sort action?\n let sortAction: 'add' | 'remove' | 'toggle' | 'replace'\n let nextDesc = hasManualValue ? desc : nextSortingOrder === 'desc'\n\n // Multi-mode\n if (old?.length && column.getCanMultiSort() && multi) {\n if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'add'\n }\n } else {\n // Normal mode\n if (old?.length && existingIndex !== old.length - 1) {\n sortAction = 'replace'\n } else if (existingSorting) {\n sortAction = 'toggle'\n } else {\n sortAction = 'replace'\n }\n }\n\n // Handle toggle states that will remove the sorting\n if (sortAction === 'toggle') {\n // If we are \"actually\" toggling (not a manual set value), should we remove the sorting?\n if (!hasManualValue) {\n // Is our intention to remove?\n if (!nextSortingOrder) {\n sortAction = 'remove'\n }\n }\n }\n\n if (sortAction === 'add') {\n newSorting = [\n ...old,\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n // Take latest n columns\n newSorting.splice(\n 0,\n newSorting.length -\n (table.options.maxMultiSortColCount ?? Number.MAX_SAFE_INTEGER)\n )\n } else if (sortAction === 'toggle') {\n // This flips (or sets) the\n newSorting = old.map(d => {\n if (d.id === column.id) {\n return {\n ...d,\n desc: nextDesc,\n }\n }\n return d\n })\n } else if (sortAction === 'remove') {\n newSorting = old.filter(d => d.id !== column.id)\n } else {\n newSorting = [\n {\n id: column.id,\n desc: nextDesc,\n },\n ]\n }\n\n return newSorting\n })\n }\n\n column.getFirstSortDir = () => {\n const sortDescFirst =\n column.columnDef.sortDescFirst ??\n table.options.sortDescFirst ??\n column.getAutoSortDir() === 'desc'\n return sortDescFirst ? 'desc' : 'asc'\n }\n\n column.getNextSortingOrder = (multi?: boolean) => {\n const firstSortDirection = column.getFirstSortDir()\n const isSorted = column.getIsSorted()\n\n if (!isSorted) {\n return firstSortDirection\n }\n\n if (\n isSorted !== firstSortDirection &&\n (table.options.enableSortingRemoval ?? true) && // If enableSortRemove, enable in general\n (multi ? table.options.enableMultiRemove ?? true : true) // If multi, don't allow if enableMultiRemove))\n ) {\n return false\n }\n return isSorted === 'desc' ? 'asc' : 'desc'\n }\n\n column.getCanSort = () => {\n return (\n (column.columnDef.enableSorting ?? true) &&\n (table.options.enableSorting ?? true) &&\n !!column.accessorFn\n )\n }\n\n column.getCanMultiSort = () => {\n return (\n column.columnDef.enableMultiSort ??\n table.options.enableMultiSort ??\n !!column.accessorFn\n )\n }\n\n column.getIsSorted = () => {\n const columnSort = table.getState().sorting?.find(d => d.id === column.id)\n\n return !columnSort ? false : columnSort.desc ? 'desc' : 'asc'\n }\n\n column.getSortIndex = () =>\n table.getState().sorting?.findIndex(d => d.id === column.id) ?? -1\n\n column.clearSorting = () => {\n //clear sorting for just 1 column\n table.setSorting(old =>\n old?.length ? old.filter(d => d.id !== column.id) : []\n )\n }\n\n column.getToggleSortingHandler = () => {\n const canSort = column.getCanSort()\n\n return (e: unknown) => {\n if (!canSort) return\n ;(e as any).persist?.()\n column.toggleSorting?.(\n undefined,\n column.getCanMultiSort() ? table.options.isMultiSortEvent?.(e) : false\n )\n }\n }\n },\n\n createTable: <TData extends RowData>(table: Table<TData>): void => {\n table.setSorting = updater => table.options.onSortingChange?.(updater)\n table.resetSorting = defaultState => {\n table.setSorting(defaultState ? [] : table.initialState?.sorting ?? [])\n }\n table.getPreSortedRowModel = () => table.getGroupedRowModel()\n table.getSortedRowModel = () => {\n if (!table._getSortedRowModel && table.options.getSortedRowModel) {\n table._getSortedRowModel = table.options.getSortedRowModel(table)\n }\n\n if (table.options.manualSorting || !table._getSortedRowModel) {\n return table.getPreSortedRowModel()\n }\n\n return table._getSortedRowModel()\n }\n },\n}\n"],"names":["makeStateUpdater","sortingFns","reSplitAlphaNumeric","isFunction"],"mappings":";;;;AAqRO,MAAM,aAA2B;AAAA,EACtC,iBAAiB,CAAC,UAA6B;AACtC,WAAA;AAAA,MACL,SAAS,CAAC;AAAA,MACV,GAAG;AAAA,IAAA;AAAA,EAEP;AAAA,EAEA,qBAAqB,MAAsD;AAClE,WAAA;AAAA,MACL,WAAW;AAAA,MACX,eAAe;AAAA,IAAA;AAAA,EAEnB;AAAA,EAEA,mBAAmB,CACjB,UAC0B;AACnB,WAAA;AAAA,MACL,iBAAiBA,MAAAA,iBAAiB,WAAW,KAAK;AAAA,MAClD,kBAAkB,CAAC,MAAe;AAChC,eAAQ,EAAiB;AAAA,MAC3B;AAAA,IAAA;AAAA,EAEJ;AAAA,EAEA,cAAc,CACZ,QACA,UACS;AACT,WAAO,mBAAmB,MAAM;AAC9B,YAAM,YAAY,MAAM,oBAAA,EAAsB,SAAS,MAAM,EAAE;AAE/D,UAAI,WAAW;AAEf,iBAAW,OAAO,WAAW;AAC3B,cAAM,QAAQ,2BAAK,SAAS,OAAO;A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AAa,CAAA,YAAA;;AAAW,+BAAM,SAAQ,oBAAd,4BAAgC;AAAA;AAC9D,UAAM,eAAe,CAAgB,iBAAA;;AAC7B,YAAA,WAAW,eAAe,CAAC,MAAI,WAAM,iBAAN,mBAAoB,YAAW,CAAA,CAAE;AAAA,IAAA;AAElE,UAAA,uBAAuB,MAAM,MAAM,mBAAmB;AAC5D,UAAM,oBAAoB,MAAM;AAC9B,UAAI,CAAC,MAAM,sBAAsB,MAAM,QAAQ,mBAAmB;AAChE,cAAM,qBAAqB,MAAM,QAAQ,kBAAkB,KAAK;AAAA,MAClE;AAEA,UAAI,MAAM,QAAQ,iBAAiB,CAAC,MAAM,oBAAoB;AAC5D,eAAO,MAAM;MACf;AAEA,aAAO,MAAM;IAAmB;AAAA,EAEpC;AACF;;"}
@@ -0,0 +1,238 @@
1
+ import { RowModel } from '..';
2
+ import { BuiltInSortingFn } from '../sortingFns';
3
+ import { OnChangeFn, Table, Row, Updater, RowData, SortingFns, TableFeature } from '../types';
4
+
5
+ export type SortDirection = 'asc' | 'desc';
6
+ export interface ColumnSort {
7
+ desc: boolean;
8
+ id: string;
9
+ }
10
+ export type SortingState = ColumnSort[];
11
+ export interface SortingTableState {
12
+ sorting: SortingState;
13
+ }
14
+ export interface SortingFn<TData extends RowData> {
15
+ (rowA: Row<TData>, rowB: Row<TData>, columnId: string): number;
16
+ }
17
+ export type CustomSortingFns<TData extends RowData> = Record<string, SortingFn<TData>>;
18
+ export type SortingFnOption<TData extends RowData> = 'auto' | keyof SortingFns | BuiltInSortingFn | SortingFn<TData>;
19
+ export interface SortingColumnDef<TData extends RowData> {
20
+ /**
21
+ * Enables/Disables multi-sorting for this column.
22
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)
23
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
24
+ */
25
+ enableMultiSort?: boolean;
26
+ /**
27
+ * Enables/Disables sorting for this column.
28
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)
29
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
30
+ */
31
+ enableSorting?: boolean;
32
+ /**
33
+ * Inverts the order of the sorting for this column. This is useful for values that have an inverted best/worst scale where lower numbers are better, eg. a ranking (1st, 2nd, 3rd) or golf-like scoring
34
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#invertsorting)
35
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
36
+ */
37
+ invertSorting?: boolean;
38
+ /**
39
+ * Set to `true` for sorting toggles on this column to start in the descending direction.
40
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)
41
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
42
+ */
43
+ sortDescFirst?: boolean;
44
+ /**
45
+ * The sorting function to use with this column.
46
+ * - A `string` referencing a built-in sorting function
47
+ * - A custom sorting function
48
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortingfn)
49
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
50
+ */
51
+ sortingFn?: SortingFnOption<TData>;
52
+ /**
53
+ * The priority of undefined values when sorting this column.
54
+ * - `false`
55
+ * - Undefined values will be considered tied and need to be sorted by the next column filter or original index (whichever applies)
56
+ * - `-1`
57
+ * - Undefined values will be sorted with higher priority (ascending) (if ascending, undefined will appear on the beginning of the list)
58
+ * - `1`
59
+ * - Undefined values will be sorted with lower priority (descending) (if ascending, undefined will appear on the end of the list)
60
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortundefined)
61
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
62
+ */
63
+ sortUndefined?: false | -1 | 1 | 'first' | 'last';
64
+ }
65
+ export interface SortingColumn<TData extends RowData> {
66
+ /**
67
+ * Removes this column from the table's sorting state
68
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#clearsorting)
69
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
70
+ */
71
+ clearSorting: () => void;
72
+ /**
73
+ * Returns a sort direction automatically inferred based on the columns values.
74
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortdir)
75
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
76
+ */
77
+ getAutoSortDir: () => SortDirection;
78
+ /**
79
+ * Returns a sorting function automatically inferred based on the columns values.
80
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getautosortingfn)
81
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
82
+ */
83
+ getAutoSortingFn: () => SortingFn<TData>;
84
+ /**
85
+ * Returns whether this column can be multi-sorted.
86
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcanmultisort)
87
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
88
+ */
89
+ getCanMultiSort: () => boolean;
90
+ /**
91
+ * Returns whether this column can be sorted.
92
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getcansort)
93
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
94
+ */
95
+ getCanSort: () => boolean;
96
+ /**
97
+ * Returns the first direction that should be used when sorting this column.
98
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getfirstsortdir)
99
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
100
+ */
101
+ getFirstSortDir: () => SortDirection;
102
+ /**
103
+ * Returns the current sort direction of this column.
104
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getissorted)
105
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
106
+ */
107
+ getIsSorted: () => false | SortDirection;
108
+ /**
109
+ * Returns the next sorting order.
110
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getnextsortingorder)
111
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
112
+ */
113
+ getNextSortingOrder: () => SortDirection | false;
114
+ /**
115
+ * Returns the index position of this column's sorting within the sorting state
116
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortindex)
117
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
118
+ */
119
+ getSortIndex: () => number;
120
+ /**
121
+ * Returns the resolved sorting function to be used for this column
122
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortingfn)
123
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
124
+ */
125
+ getSortingFn: () => SortingFn<TData>;
126
+ /**
127
+ * Returns a function that can be used to toggle this column's sorting state. This is useful for attaching a click handler to the column header.
128
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#gettogglesortinghandler)
129
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
130
+ */
131
+ getToggleSortingHandler: () => undefined | ((event: unknown) => void);
132
+ /**
133
+ * Toggles this columns sorting state. If `desc` is provided, it will force the sort direction to that value. If `isMulti` is provided, it will additivity multi-sort the column (or toggle it if it is already sorted).
134
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#togglesorting)
135
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
136
+ */
137
+ toggleSorting: (desc?: boolean, isMulti?: boolean) => void;
138
+ }
139
+ interface SortingOptionsBase {
140
+ /**
141
+ * Enables/disables the ability to remove multi-sorts
142
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultiremove)
143
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
144
+ */
145
+ enableMultiRemove?: boolean;
146
+ /**
147
+ * Enables/Disables multi-sorting for the table.
148
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablemultisort)
149
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
150
+ */
151
+ enableMultiSort?: boolean;
152
+ /**
153
+ * Enables/Disables sorting for the table.
154
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesorting)
155
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
156
+ */
157
+ enableSorting?: boolean;
158
+ /**
159
+ * Enables/Disables the ability to remove sorting for the table.
160
+ * - If `true` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'none' -> ...
161
+ * - If `false` then changing sort order will circle like: 'none' -> 'desc' -> 'asc' -> 'desc' -> 'asc' -> ...
162
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#enablesortingremoval)
163
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
164
+ */
165
+ enableSortingRemoval?: boolean;
166
+ /**
167
+ * This function is used to retrieve the sorted row model. If using server-side sorting, this function is not required. To use client-side sorting, pass the exported `getSortedRowModel()` from your adapter to your table or implement your own.
168
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)
169
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
170
+ */
171
+ getSortedRowModel?: (table: Table<any>) => () => RowModel<any>;
172
+ /**
173
+ * Pass a custom function that will be used to determine if a multi-sort event should be triggered. It is passed the event from the sort toggle handler and should return `true` if the event should trigger a multi-sort.
174
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#ismultisortevent)
175
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
176
+ */
177
+ isMultiSortEvent?: (e: unknown) => boolean;
178
+ /**
179
+ * Enables manual sorting for the table. If this is `true`, you will be expected to sort your data before it is passed to the table. This is useful if you are doing server-side sorting.
180
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#manualsorting)
181
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
182
+ */
183
+ manualSorting?: boolean;
184
+ /**
185
+ * Set a maximum number of columns that can be multi-sorted.
186
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#maxmultisortcolcount)
187
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
188
+ */
189
+ maxMultiSortColCount?: number;
190
+ /**
191
+ * If provided, this function will be called with an `updaterFn` when `state.sorting` changes. This overrides the default internal state management, so you will need to persist the state change either fully or partially outside of the table.
192
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#onsortingchange)
193
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
194
+ */
195
+ onSortingChange?: OnChangeFn<SortingState>;
196
+ /**
197
+ * If `true`, all sorts will default to descending as their first toggle state.
198
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#sortdescfirst)
199
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
200
+ */
201
+ sortDescFirst?: boolean;
202
+ }
203
+ type ResolvedSortingFns = keyof SortingFns extends never ? {
204
+ sortingFns?: Record<string, SortingFn<any>>;
205
+ } : {
206
+ sortingFns: Record<keyof SortingFns, SortingFn<any>>;
207
+ };
208
+ export interface SortingOptions<TData extends RowData> extends SortingOptionsBase, ResolvedSortingFns {
209
+ }
210
+ export interface SortingInstance<TData extends RowData> {
211
+ _getSortedRowModel?: () => RowModel<TData>;
212
+ /**
213
+ * Returns the row model for the table before any sorting has been applied.
214
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getpresortedrowmodel)
215
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
216
+ */
217
+ getPreSortedRowModel: () => RowModel<TData>;
218
+ /**
219
+ * Returns the row model for the table after sorting has been applied.
220
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#getsortedrowmodel)
221
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
222
+ */
223
+ getSortedRowModel: () => RowModel<TData>;
224
+ /**
225
+ * Resets the **sorting** state to `initialState.sorting`, or `true` can be passed to force a default blank state reset to `[]`.
226
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#resetsorting)
227
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
228
+ */
229
+ resetSorting: (defaultState?: boolean) => void;
230
+ /**
231
+ * Sets or updates the `state.sorting` state.
232
+ * @link [API Docs](https://tanstack.com/table/v8/docs/api/features/sorting#setsorting)
233
+ * @link [Guide](https://tanstack.com/table/v8/docs/guide/sorting)
234
+ */
235
+ setSorting: (updater: Updater<SortingState>) => void;
236
+ }
237
+ export declare const RowSorting: TableFeature;
238
+ export {};
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const includesString = (row, columnId, filterValue) => {
4
+ var _a, _b, _c;
5
+ const search = filterValue.toLowerCase();
6
+ return Boolean(
7
+ (_c = (_b = (_a = row.getValue(columnId)) == null ? void 0 : _a.toString()) == null ? void 0 : _b.toLowerCase()) == null ? void 0 : _c.includes(search)
8
+ );
9
+ };
10
+ includesString.autoRemove = (val) => testFalsey(val);
11
+ const includesStringSensitive = (row, columnId, filterValue) => {
12
+ var _a, _b;
13
+ return Boolean(
14
+ (_b = (_a = row.getValue(columnId)) == null ? void 0 : _a.toString()) == null ? void 0 : _b.includes(filterValue)
15
+ );
16
+ };
17
+ includesStringSensitive.autoRemove = (val) => testFalsey(val);
18
+ const equalsString = (row, columnId, filterValue) => {
19
+ var _a, _b;
20
+ return ((_b = (_a = row.getValue(columnId)) == null ? void 0 : _a.toString()) == null ? void 0 : _b.toLowerCase()) === (filterValue == null ? void 0 : filterValue.toLowerCase());
21
+ };
22
+ equalsString.autoRemove = (val) => testFalsey(val);
23
+ const arrIncludes = (row, columnId, filterValue) => {
24
+ var _a;
25
+ return (_a = row.getValue(columnId)) == null ? void 0 : _a.includes(filterValue);
26
+ };
27
+ arrIncludes.autoRemove = (val) => testFalsey(val) || !(val == null ? void 0 : val.length);
28
+ const arrIncludesAll = (row, columnId, filterValue) => {
29
+ return !filterValue.some(
30
+ (val) => {
31
+ var _a;
32
+ return !((_a = row.getValue(columnId)) == null ? void 0 : _a.includes(val));
33
+ }
34
+ );
35
+ };
36
+ arrIncludesAll.autoRemove = (val) => testFalsey(val) || !(val == null ? void 0 : val.length);
37
+ const arrIncludesSome = (row, columnId, filterValue) => {
38
+ return filterValue.some(
39
+ (val) => {
40
+ var _a;
41
+ return (_a = row.getValue(columnId)) == null ? void 0 : _a.includes(val);
42
+ }
43
+ );
44
+ };
45
+ arrIncludesSome.autoRemove = (val) => testFalsey(val) || !(val == null ? void 0 : val.length);
46
+ const equals = (row, columnId, filterValue) => {
47
+ return row.getValue(columnId) === filterValue;
48
+ };
49
+ equals.autoRemove = (val) => testFalsey(val);
50
+ const weakEquals = (row, columnId, filterValue) => {
51
+ return row.getValue(columnId) == filterValue;
52
+ };
53
+ weakEquals.autoRemove = (val) => testFalsey(val);
54
+ const inNumberRange = (row, columnId, filterValue) => {
55
+ let [min, max] = filterValue;
56
+ const rowValue = row.getValue(columnId);
57
+ return rowValue >= min && rowValue <= max;
58
+ };
59
+ inNumberRange.resolveFilterValue = (val) => {
60
+ let [unsafeMin, unsafeMax] = val;
61
+ let parsedMin = typeof unsafeMin !== "number" ? parseFloat(unsafeMin) : unsafeMin;
62
+ let parsedMax = typeof unsafeMax !== "number" ? parseFloat(unsafeMax) : unsafeMax;
63
+ let min = unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin;
64
+ let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax;
65
+ if (min > max) {
66
+ const temp = min;
67
+ min = max;
68
+ max = temp;
69
+ }
70
+ return [min, max];
71
+ };
72
+ inNumberRange.autoRemove = (val) => testFalsey(val) || testFalsey(val[0]) && testFalsey(val[1]);
73
+ const filterFns = {
74
+ includesString,
75
+ includesStringSensitive,
76
+ equalsString,
77
+ arrIncludes,
78
+ arrIncludesAll,
79
+ arrIncludesSome,
80
+ equals,
81
+ weakEquals,
82
+ inNumberRange
83
+ };
84
+ function testFalsey(val) {
85
+ return val === void 0 || val === null || val === "";
86
+ }
87
+ exports.filterFns = filterFns;
88
+ //# sourceMappingURL=filterFns.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterFns.cjs","sources":["../../src/filterFns.ts"],"sourcesContent":["import { FilterFn } from './features/ColumnFiltering'\n\nconst includesString: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: string\n) => {\n const search = filterValue.toLowerCase()\n return Boolean(\n row\n .getValue<string | null>(columnId)\n ?.toString()\n ?.toLowerCase()\n ?.includes(search)\n )\n}\n\nincludesString.autoRemove = (val: any) => testFalsey(val)\n\nconst includesStringSensitive: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: string\n) => {\n return Boolean(\n row.getValue<string | null>(columnId)?.toString()?.includes(filterValue)\n )\n}\n\nincludesStringSensitive.autoRemove = (val: any) => testFalsey(val)\n\nconst equalsString: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: string\n) => {\n return (\n row.getValue<string | null>(columnId)?.toString()?.toLowerCase() ===\n filterValue?.toLowerCase()\n )\n}\n\nequalsString.autoRemove = (val: any) => testFalsey(val)\n\nconst arrIncludes: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: unknown\n) => {\n return row.getValue<unknown[]>(columnId)?.includes(filterValue)\n}\n\narrIncludes.autoRemove = (val: any) => testFalsey(val) || !val?.length\n\nconst arrIncludesAll: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: unknown[]\n) => {\n return !filterValue.some(\n val => !row.getValue<unknown[]>(columnId)?.includes(val)\n )\n}\n\narrIncludesAll.autoRemove = (val: any) => testFalsey(val) || !val?.length\n\nconst arrIncludesSome: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: unknown[]\n) => {\n return filterValue.some(\n val => row.getValue<unknown[]>(columnId)?.includes(val)\n )\n}\n\narrIncludesSome.autoRemove = (val: any) => testFalsey(val) || !val?.length\n\nconst equals: FilterFn<any> = (row, columnId: string, filterValue: unknown) => {\n return row.getValue(columnId) === filterValue\n}\n\nequals.autoRemove = (val: any) => testFalsey(val)\n\nconst weakEquals: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: unknown\n) => {\n return row.getValue(columnId) == filterValue\n}\n\nweakEquals.autoRemove = (val: any) => testFalsey(val)\n\nconst inNumberRange: FilterFn<any> = (\n row,\n columnId: string,\n filterValue: [number, number]\n) => {\n let [min, max] = filterValue\n\n const rowValue = row.getValue<number>(columnId)\n return rowValue >= min && rowValue <= max\n}\n\ninNumberRange.resolveFilterValue = (val: [any, any]) => {\n let [unsafeMin, unsafeMax] = val\n\n let parsedMin =\n typeof unsafeMin !== 'number' ? parseFloat(unsafeMin as string) : unsafeMin\n let parsedMax =\n typeof unsafeMax !== 'number' ? parseFloat(unsafeMax as string) : unsafeMax\n\n let min =\n unsafeMin === null || Number.isNaN(parsedMin) ? -Infinity : parsedMin\n let max = unsafeMax === null || Number.isNaN(parsedMax) ? Infinity : parsedMax\n\n if (min > max) {\n const temp = min\n min = max\n max = temp\n }\n\n return [min, max] as const\n}\n\ninNumberRange.autoRemove = (val: any) =>\n testFalsey(val) || (testFalsey(val[0]) && testFalsey(val[1]))\n\n// Export\n\nexport const filterFns = {\n includesString,\n includesStringSensitive,\n equalsString,\n arrIncludes,\n arrIncludesAll,\n arrIncludesSome,\n equals,\n weakEquals,\n inNumberRange,\n}\n\nexport type BuiltInFilterFn = keyof typeof filterFns\n\n// Utils\n\nfunction testFalsey(val: any) {\n return val === undefined || val === null || val === ''\n}\n"],"names":[],"mappings":";;AAEA,MAAM,iBAAgC,CACpC,KACA,UACA,gBACG;;AACG,QAAA,SAAS,YAAY;AACpB,SAAA;AAAA,KACL,qBACG,SAAwB,QAAQ,MADnC,mBAEI,eAFJ,mBAGI,kBAHJ,mBAII,SAAS;AAAA,EAAM;AAEvB;AAEA,eAAe,aAAa,CAAC,QAAa,WAAW,GAAG;AAExD,MAAM,0BAAyC,CAC7C,KACA,UACA,gBACG;;AACI,SAAA;AAAA,KACL,eAAI,SAAwB,QAAQ,MAApC,mBAAuC,eAAvC,mBAAmD,SAAS;AAAA,EAAW;AAE3E;AAEA,wBAAwB,aAAa,CAAC,QAAa,WAAW,GAAG;AAEjE,MAAM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AW,SAAS,IAAI;AAE7B,MAAI,YACF,OAAO,cAAc,WAAW,WAAW,SAAmB,IAAI;AACpE,MAAI,YACF,OAAO,cAAc,WAAW,WAAW,SAAmB,IAAI;AAEpE,MAAI,MACF,cAAc,QAAQ,OAAO,MAAM,SAAS,IAAI,YAAY;AAC9D,MAAI,MAAM,cAAc,QAAQ,OAAO,MAAM,SAAS,IAAI,WAAW;AAErE,MAAI,MAAM,KAAK;AACb,UAAM,OAAO;AACP,UAAA;AACA,UAAA;AAAA,EACR;AAEO,SAAA,CAAC,KAAK,GAAG;AAClB;AAEA,cAAc,aAAa,CAAC,QAC1B,WAAW,GAAG,KAAM,WAAW,IAAI,CAAC,CAAC,KAAK,WAAW,IAAI,CAAC,CAAC;AAItD,MAAM,YAAY;AAAA,EACvB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAMA,SAAS,WAAW,KAAU;AAC5B,SAAO,QAAQ,UAAa,QAAQ,QAAQ,QAAQ;AACtD;;"}
@@ -0,0 +1,14 @@
1
+ import { FilterFn } from './features/ColumnFiltering.cjs';
2
+
3
+ export declare const filterFns: {
4
+ includesString: FilterFn<any>;
5
+ includesStringSensitive: FilterFn<any>;
6
+ equalsString: FilterFn<any>;
7
+ arrIncludes: FilterFn<any>;
8
+ arrIncludesAll: FilterFn<any>;
9
+ arrIncludesSome: FilterFn<any>;
10
+ equals: FilterFn<any>;
11
+ weakEquals: FilterFn<any>;
12
+ inNumberRange: FilterFn<any>;
13
+ };
14
+ export type BuiltInFilterFn = keyof typeof filterFns;