@lminii/material-react-table 4.0.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 (349) hide show
  1. package/LICENSE +22 -0
  2. package/README.md +234 -0
  3. package/dist/index.d.mts +2408 -0
  4. package/dist/index.d.ts +2408 -0
  5. package/dist/index.js +4825 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/index.mjs +4631 -0
  8. package/dist/index.mjs.map +1 -0
  9. package/locales/ar/index.d.mts +3 -0
  10. package/locales/ar/index.d.ts +3 -0
  11. package/locales/ar/index.js +100 -0
  12. package/locales/ar/index.mjs +96 -0
  13. package/locales/ar/package.json +6 -0
  14. package/locales/az/index.d.mts +3 -0
  15. package/locales/az/index.d.ts +3 -0
  16. package/locales/az/index.js +100 -0
  17. package/locales/az/index.mjs +96 -0
  18. package/locales/az/package.json +6 -0
  19. package/locales/bg/index.d.mts +3 -0
  20. package/locales/bg/index.d.ts +3 -0
  21. package/locales/bg/index.js +100 -0
  22. package/locales/bg/index.mjs +96 -0
  23. package/locales/bg/package.json +6 -0
  24. package/locales/cs/index.d.mts +3 -0
  25. package/locales/cs/index.d.ts +3 -0
  26. package/locales/cs/index.js +100 -0
  27. package/locales/cs/index.mjs +96 -0
  28. package/locales/cs/package.json +6 -0
  29. package/locales/da/index.d.mts +3 -0
  30. package/locales/da/index.d.ts +3 -0
  31. package/locales/da/index.js +100 -0
  32. package/locales/da/index.mjs +96 -0
  33. package/locales/da/package.json +6 -0
  34. package/locales/de/index.d.mts +3 -0
  35. package/locales/de/index.d.ts +3 -0
  36. package/locales/de/index.js +100 -0
  37. package/locales/de/index.mjs +96 -0
  38. package/locales/de/package.json +6 -0
  39. package/locales/el/index.d.mts +3 -0
  40. package/locales/el/index.d.ts +3 -0
  41. package/locales/el/index.js +100 -0
  42. package/locales/el/index.mjs +96 -0
  43. package/locales/el/package.json +6 -0
  44. package/locales/en/index.d.mts +3 -0
  45. package/locales/en/index.d.ts +3 -0
  46. package/locales/en/index.js +100 -0
  47. package/locales/en/index.mjs +96 -0
  48. package/locales/en/package.json +6 -0
  49. package/locales/es/index.d.mts +3 -0
  50. package/locales/es/index.d.ts +3 -0
  51. package/locales/es/index.js +100 -0
  52. package/locales/es/index.mjs +96 -0
  53. package/locales/es/package.json +6 -0
  54. package/locales/et/index.d.mts +3 -0
  55. package/locales/et/index.d.ts +3 -0
  56. package/locales/et/index.js +100 -0
  57. package/locales/et/index.mjs +96 -0
  58. package/locales/et/package.json +6 -0
  59. package/locales/fa/index.d.mts +3 -0
  60. package/locales/fa/index.d.ts +3 -0
  61. package/locales/fa/index.js +100 -0
  62. package/locales/fa/index.mjs +96 -0
  63. package/locales/fa/package.json +6 -0
  64. package/locales/fi/index.d.mts +3 -0
  65. package/locales/fi/index.d.ts +3 -0
  66. package/locales/fi/index.js +100 -0
  67. package/locales/fi/index.mjs +96 -0
  68. package/locales/fi/package.json +6 -0
  69. package/locales/fr/index.d.mts +3 -0
  70. package/locales/fr/index.d.ts +3 -0
  71. package/locales/fr/index.js +100 -0
  72. package/locales/fr/index.mjs +96 -0
  73. package/locales/fr/package.json +6 -0
  74. package/locales/he/index.d.mts +3 -0
  75. package/locales/he/index.d.ts +3 -0
  76. package/locales/he/index.js +100 -0
  77. package/locales/he/index.mjs +96 -0
  78. package/locales/he/package.json +6 -0
  79. package/locales/hr/index.d.mts +3 -0
  80. package/locales/hr/index.d.ts +3 -0
  81. package/locales/hr/index.js +100 -0
  82. package/locales/hr/index.mjs +96 -0
  83. package/locales/hr/package.json +6 -0
  84. package/locales/hu/index.d.mts +3 -0
  85. package/locales/hu/index.d.ts +3 -0
  86. package/locales/hu/index.js +100 -0
  87. package/locales/hu/index.mjs +96 -0
  88. package/locales/hu/package.json +6 -0
  89. package/locales/hy/index.d.mts +3 -0
  90. package/locales/hy/index.d.ts +3 -0
  91. package/locales/hy/index.js +100 -0
  92. package/locales/hy/index.mjs +96 -0
  93. package/locales/hy/package.json +6 -0
  94. package/locales/id/index.d.mts +3 -0
  95. package/locales/id/index.d.ts +3 -0
  96. package/locales/id/index.js +100 -0
  97. package/locales/id/index.mjs +96 -0
  98. package/locales/id/package.json +6 -0
  99. package/locales/it/index.d.mts +3 -0
  100. package/locales/it/index.d.ts +3 -0
  101. package/locales/it/index.js +100 -0
  102. package/locales/it/index.mjs +96 -0
  103. package/locales/it/package.json +6 -0
  104. package/locales/ja/index.d.mts +3 -0
  105. package/locales/ja/index.d.ts +3 -0
  106. package/locales/ja/index.js +100 -0
  107. package/locales/ja/index.mjs +96 -0
  108. package/locales/ja/package.json +6 -0
  109. package/locales/ko/index.d.mts +3 -0
  110. package/locales/ko/index.d.ts +3 -0
  111. package/locales/ko/index.js +100 -0
  112. package/locales/ko/index.mjs +96 -0
  113. package/locales/ko/package.json +6 -0
  114. package/locales/nl/index.d.mts +3 -0
  115. package/locales/nl/index.d.ts +3 -0
  116. package/locales/nl/index.js +100 -0
  117. package/locales/nl/index.mjs +96 -0
  118. package/locales/nl/package.json +6 -0
  119. package/locales/no/index.d.mts +3 -0
  120. package/locales/no/index.d.ts +3 -0
  121. package/locales/no/index.js +100 -0
  122. package/locales/no/index.mjs +96 -0
  123. package/locales/no/package.json +6 -0
  124. package/locales/np/index.d.mts +3 -0
  125. package/locales/np/index.d.ts +3 -0
  126. package/locales/np/index.js +100 -0
  127. package/locales/np/index.mjs +96 -0
  128. package/locales/np/package.json +6 -0
  129. package/locales/pl/index.d.mts +3 -0
  130. package/locales/pl/index.d.ts +3 -0
  131. package/locales/pl/index.js +100 -0
  132. package/locales/pl/index.mjs +96 -0
  133. package/locales/pl/package.json +6 -0
  134. package/locales/pt/index.d.mts +3 -0
  135. package/locales/pt/index.d.ts +3 -0
  136. package/locales/pt/index.js +100 -0
  137. package/locales/pt/index.mjs +96 -0
  138. package/locales/pt/package.json +6 -0
  139. package/locales/pt-BR/index.d.mts +3 -0
  140. package/locales/pt-BR/index.d.ts +3 -0
  141. package/locales/pt-BR/index.js +100 -0
  142. package/locales/pt-BR/index.mjs +96 -0
  143. package/locales/pt-BR/package.json +6 -0
  144. package/locales/ro/index.d.mts +3 -0
  145. package/locales/ro/index.d.ts +3 -0
  146. package/locales/ro/index.js +100 -0
  147. package/locales/ro/index.mjs +96 -0
  148. package/locales/ro/package.json +6 -0
  149. package/locales/ru/index.d.mts +3 -0
  150. package/locales/ru/index.d.ts +3 -0
  151. package/locales/ru/index.js +100 -0
  152. package/locales/ru/index.mjs +96 -0
  153. package/locales/ru/package.json +6 -0
  154. package/locales/sk/index.d.mts +3 -0
  155. package/locales/sk/index.d.ts +3 -0
  156. package/locales/sk/index.js +100 -0
  157. package/locales/sk/index.mjs +96 -0
  158. package/locales/sk/package.json +6 -0
  159. package/locales/sr-Cyrl-RS/index.d.mts +3 -0
  160. package/locales/sr-Cyrl-RS/index.d.ts +3 -0
  161. package/locales/sr-Cyrl-RS/index.js +100 -0
  162. package/locales/sr-Cyrl-RS/index.mjs +96 -0
  163. package/locales/sr-Cyrl-RS/package.json +6 -0
  164. package/locales/sr-Latn-RS/index.d.mts +3 -0
  165. package/locales/sr-Latn-RS/index.d.ts +3 -0
  166. package/locales/sr-Latn-RS/index.js +100 -0
  167. package/locales/sr-Latn-RS/index.mjs +96 -0
  168. package/locales/sr-Latn-RS/package.json +6 -0
  169. package/locales/sv/index.d.mts +3 -0
  170. package/locales/sv/index.d.ts +3 -0
  171. package/locales/sv/index.js +100 -0
  172. package/locales/sv/index.mjs +96 -0
  173. package/locales/sv/package.json +6 -0
  174. package/locales/tr/index.d.mts +3 -0
  175. package/locales/tr/index.d.ts +3 -0
  176. package/locales/tr/index.js +100 -0
  177. package/locales/tr/index.mjs +96 -0
  178. package/locales/tr/package.json +6 -0
  179. package/locales/uk/index.d.mts +3 -0
  180. package/locales/uk/index.d.ts +3 -0
  181. package/locales/uk/index.js +100 -0
  182. package/locales/uk/index.mjs +96 -0
  183. package/locales/uk/package.json +6 -0
  184. package/locales/vi/index.d.mts +3 -0
  185. package/locales/vi/index.d.ts +3 -0
  186. package/locales/vi/index.js +100 -0
  187. package/locales/vi/index.mjs +96 -0
  188. package/locales/vi/package.json +6 -0
  189. package/locales/zh-Hans/index.d.mts +3 -0
  190. package/locales/zh-Hans/index.d.ts +3 -0
  191. package/locales/zh-Hans/index.js +100 -0
  192. package/locales/zh-Hans/index.mjs +96 -0
  193. package/locales/zh-Hans/package.json +6 -0
  194. package/locales/zh-Hant/index.d.mts +3 -0
  195. package/locales/zh-Hant/index.d.ts +3 -0
  196. package/locales/zh-Hant/index.js +100 -0
  197. package/locales/zh-Hant/index.mjs +96 -0
  198. package/locales/zh-Hant/package.json +6 -0
  199. package/package.json +147 -0
  200. package/skills/README.md +81 -0
  201. package/skills/composable-components/SKILL.md +189 -0
  202. package/skills/customization/SKILL.md +190 -0
  203. package/skills/drag-and-drop-ordering/SKILL.md +227 -0
  204. package/skills/editing/SKILL.md +243 -0
  205. package/skills/filtering/SKILL.md +213 -0
  206. package/skills/getting-started/SKILL.md +213 -0
  207. package/skills/localization/SKILL.md +182 -0
  208. package/skills/migrate-v3-to-v4/SKILL.md +161 -0
  209. package/skills/state-and-server-data/SKILL.md +200 -0
  210. package/skills/virtualization/SKILL.md +203 -0
  211. package/src/components/MaterialReactTable.tsx +36 -0
  212. package/src/components/body/MRT_TableBody.tsx +221 -0
  213. package/src/components/body/MRT_TableBodyCell.tsx +351 -0
  214. package/src/components/body/MRT_TableBodyCellValue.tsx +130 -0
  215. package/src/components/body/MRT_TableBodyRow.tsx +288 -0
  216. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +61 -0
  217. package/src/components/body/MRT_TableBodyRowPinButton.tsx +58 -0
  218. package/src/components/body/MRT_TableDetailPanel.tsx +110 -0
  219. package/src/components/buttons/MRT_ColumnPinningButtons.tsx +72 -0
  220. package/src/components/buttons/MRT_CopyButton.tsx +87 -0
  221. package/src/components/buttons/MRT_EditActionButtons.tsx +134 -0
  222. package/src/components/buttons/MRT_ExpandAllButton.tsx +78 -0
  223. package/src/components/buttons/MRT_ExpandButton.tsx +102 -0
  224. package/src/components/buttons/MRT_GrabHandleButton.tsx +65 -0
  225. package/src/components/buttons/MRT_RowPinButton.tsx +84 -0
  226. package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +50 -0
  227. package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +52 -0
  228. package/src/components/buttons/MRT_ToggleFiltersButton.tsx +40 -0
  229. package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +51 -0
  230. package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +46 -0
  231. package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +126 -0
  232. package/src/components/footer/MRT_TableFooter.tsx +88 -0
  233. package/src/components/footer/MRT_TableFooterCell.tsx +107 -0
  234. package/src/components/footer/MRT_TableFooterRow.tsx +95 -0
  235. package/src/components/head/MRT_TableHead.tsx +91 -0
  236. package/src/components/head/MRT_TableHeadCell.tsx +351 -0
  237. package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +96 -0
  238. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +52 -0
  239. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +178 -0
  240. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +91 -0
  241. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +96 -0
  242. package/src/components/head/MRT_TableHeadCellSortLabel.tsx +101 -0
  243. package/src/components/head/MRT_TableHeadRow.tsx +90 -0
  244. package/src/components/inputs/MRT_EditCellTextField.tsx +202 -0
  245. package/src/components/inputs/MRT_FilterCheckbox.tsx +90 -0
  246. package/src/components/inputs/MRT_FilterRangeFields.tsx +41 -0
  247. package/src/components/inputs/MRT_FilterRangeSlider.tsx +143 -0
  248. package/src/components/inputs/MRT_FilterTextField.tsx +592 -0
  249. package/src/components/inputs/MRT_GlobalFilterTextField.tsx +167 -0
  250. package/src/components/inputs/MRT_SelectCheckbox.tsx +135 -0
  251. package/src/components/menus/MRT_ActionMenuItem.tsx +62 -0
  252. package/src/components/menus/MRT_CellActionMenu.tsx +107 -0
  253. package/src/components/menus/MRT_ColumnActionMenu.tsx +352 -0
  254. package/src/components/menus/MRT_FilterOptionMenu.tsx +292 -0
  255. package/src/components/menus/MRT_RowActionMenu.tsx +88 -0
  256. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +181 -0
  257. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +203 -0
  258. package/src/components/modals/MRT_EditRowModal.tsx +114 -0
  259. package/src/components/table/MRT_Table.tsx +84 -0
  260. package/src/components/table/MRT_TableContainer.tsx +111 -0
  261. package/src/components/table/MRT_TableLoadingOverlay.tsx +58 -0
  262. package/src/components/table/MRT_TablePaper.tsx +89 -0
  263. package/src/components/toolbar/MRT_BottomToolbar.tsx +111 -0
  264. package/src/components/toolbar/MRT_LinearProgressBar.tsx +53 -0
  265. package/src/components/toolbar/MRT_TablePagination.tsx +241 -0
  266. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +184 -0
  267. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +83 -0
  268. package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +72 -0
  269. package/src/components/toolbar/MRT_TopToolbar.tsx +130 -0
  270. package/src/features/mrtCellActionsFeature.ts +67 -0
  271. package/src/features/mrtColumnDraggingFeature.ts +83 -0
  272. package/src/features/mrtDensityFeature.ts +64 -0
  273. package/src/features/mrtEditingFeature.ts +102 -0
  274. package/src/features/mrtFeatures.ts +103 -0
  275. package/src/features/mrtFilterModesFeature.ts +99 -0
  276. package/src/features/mrtFnsFeature.ts +46 -0
  277. package/src/features/mrtFullScreenFeature.ts +63 -0
  278. package/src/features/mrtLoadingFeature.ts +35 -0
  279. package/src/features/mrtRefsFeature.ts +60 -0
  280. package/src/features/mrtRowDraggingFeature.ts +81 -0
  281. package/src/features/mrtStateCompatFeature.ts +43 -0
  282. package/src/features/mrtToolbarsFeature.ts +76 -0
  283. package/src/fns/aggregationFns.ts +3 -0
  284. package/src/fns/filterFns.ts +196 -0
  285. package/src/fns/sortingFns.ts +31 -0
  286. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +28 -0
  287. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +29 -0
  288. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +97 -0
  289. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +30 -0
  290. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +24 -0
  291. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +34 -0
  292. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +33 -0
  293. package/src/hooks/useMRT_ColumnVirtualizer.ts +124 -0
  294. package/src/hooks/useMRT_Effects.ts +108 -0
  295. package/src/hooks/useMRT_RowVirtualizer.ts +88 -0
  296. package/src/hooks/useMRT_Rows.ts +44 -0
  297. package/src/hooks/useMRT_TableInstance.ts +181 -0
  298. package/src/hooks/useMRT_TableOptions.ts +241 -0
  299. package/src/hooks/useMaterialReactTable.ts +12 -0
  300. package/src/icons.ts +73 -0
  301. package/src/index.ts +91 -0
  302. package/src/locales/ar.ts +97 -0
  303. package/src/locales/az.ts +97 -0
  304. package/src/locales/bg.ts +97 -0
  305. package/src/locales/cs.ts +98 -0
  306. package/src/locales/da.ts +97 -0
  307. package/src/locales/de.ts +97 -0
  308. package/src/locales/el.ts +97 -0
  309. package/src/locales/en.ts +97 -0
  310. package/src/locales/es.ts +97 -0
  311. package/src/locales/et.ts +98 -0
  312. package/src/locales/fa.ts +97 -0
  313. package/src/locales/fi.ts +98 -0
  314. package/src/locales/fr.ts +97 -0
  315. package/src/locales/he.ts +97 -0
  316. package/src/locales/hr.ts +97 -0
  317. package/src/locales/hu.ts +97 -0
  318. package/src/locales/hy.ts +97 -0
  319. package/src/locales/id.ts +98 -0
  320. package/src/locales/it.ts +97 -0
  321. package/src/locales/ja.ts +97 -0
  322. package/src/locales/ko.ts +97 -0
  323. package/src/locales/mk.ts +96 -0
  324. package/src/locales/nl.ts +97 -0
  325. package/src/locales/no.ts +99 -0
  326. package/src/locales/np.ts +98 -0
  327. package/src/locales/pl.ts +97 -0
  328. package/src/locales/pt-BR.ts +97 -0
  329. package/src/locales/pt.ts +97 -0
  330. package/src/locales/ro.ts +97 -0
  331. package/src/locales/ru.ts +97 -0
  332. package/src/locales/sk.ts +98 -0
  333. package/src/locales/sr-Cyrl-RS.ts +97 -0
  334. package/src/locales/sr-Latn-RS.ts +97 -0
  335. package/src/locales/sv.ts +97 -0
  336. package/src/locales/tr.ts +97 -0
  337. package/src/locales/uk.ts +97 -0
  338. package/src/locales/vi.ts +97 -0
  339. package/src/locales/zh-Hans.ts +96 -0
  340. package/src/locales/zh-Hant.ts +96 -0
  341. package/src/types.ts +1314 -0
  342. package/src/utils/cell.utils.ts +234 -0
  343. package/src/utils/column.utils.ts +204 -0
  344. package/src/utils/displayColumn.utils.ts +152 -0
  345. package/src/utils/row.utils.ts +258 -0
  346. package/src/utils/style.utils.ts +211 -0
  347. package/src/utils/tanstack.helpers.ts +64 -0
  348. package/src/utils/utils.ts +34 -0
  349. package/src/utils/virtualization.utils.ts +24 -0
@@ -0,0 +1,258 @@
1
+ import { type ChangeEvent, type MouseEvent } from 'react';
2
+ import { parseFromValuesOrFunc } from './utils';
3
+ import { rankGlobalFuzzy } from '../fns/sortingFns';
4
+ import {
5
+ type MRT_Row,
6
+ type MRT_RowData,
7
+ type MRT_TableInstance,
8
+ } from '../types';
9
+
10
+ export const getMRT_Rows = <TData extends MRT_RowData>(
11
+ table: MRT_TableInstance<TData>,
12
+ all?: boolean,
13
+ ): MRT_Row<TData>[] => {
14
+ const {
15
+ getCenterRows,
16
+ getPrePaginatedRowModel,
17
+ getRowModel,
18
+ getTopRows,
19
+ options: {
20
+ createDisplayMode,
21
+ enablePagination,
22
+ enableRowPinning,
23
+ manualPagination,
24
+ positionCreatingRow,
25
+ rowPinningDisplayMode,
26
+ },
27
+ state,
28
+ } = table;
29
+ const { creatingRow, pagination } = state;
30
+
31
+ const isRankingRows = getIsRankingRows(table);
32
+
33
+ let rows: MRT_Row<TData>[] = [];
34
+ if (!isRankingRows) {
35
+ rows =
36
+ !enableRowPinning || rowPinningDisplayMode?.includes('sticky')
37
+ ? all
38
+ ? getPrePaginatedRowModel().rows
39
+ : getRowModel().rows
40
+ : getCenterRows();
41
+ } else {
42
+ // fuzzy ranking adjustments
43
+ rows = getPrePaginatedRowModel().rows.sort((a, b) => rankGlobalFuzzy(a, b));
44
+ if (enablePagination && !manualPagination && !all) {
45
+ const start = pagination.pageIndex * pagination.pageSize;
46
+ rows = rows.slice(start, start + pagination.pageSize);
47
+ }
48
+ if (enableRowPinning && !rowPinningDisplayMode?.includes('sticky')) {
49
+ // "re-center-ize" the rows (no top or bottom pinned rows unless sticky)
50
+ rows = rows.filter((row) => !row.getIsPinned());
51
+ }
52
+ }
53
+ // row pinning adjustments
54
+ if (enableRowPinning && rowPinningDisplayMode?.includes('sticky')) {
55
+ const centerPinnedRowIds = rows
56
+ .filter((row) => row.getIsPinned())
57
+ .map((r) => r.id);
58
+
59
+ rows = [
60
+ ...getTopRows().filter((row) => !centerPinnedRowIds.includes(row.id)),
61
+ ...rows,
62
+ ];
63
+ }
64
+ // blank inserted creating row adjustments
65
+ if (
66
+ positionCreatingRow !== undefined &&
67
+ creatingRow &&
68
+ createDisplayMode === 'row'
69
+ ) {
70
+ const creatingRowIndex = !isNaN(+positionCreatingRow)
71
+ ? +positionCreatingRow
72
+ : positionCreatingRow === 'top'
73
+ ? 0
74
+ : rows.length;
75
+ rows = [
76
+ ...rows.slice(0, creatingRowIndex),
77
+ creatingRow,
78
+ ...rows.slice(creatingRowIndex),
79
+ ];
80
+ }
81
+
82
+ return rows;
83
+ };
84
+
85
+ export const getCanRankRows = <TData extends MRT_RowData>(
86
+ table: MRT_TableInstance<TData>,
87
+ ) => {
88
+ const {
89
+ options: {
90
+ enableGlobalFilterRankedResults,
91
+ manualExpanding,
92
+ manualFiltering,
93
+ manualGrouping,
94
+ manualSorting,
95
+ },
96
+ state,
97
+ } = table;
98
+ const { expanded, globalFilterFn } = state;
99
+
100
+ return (
101
+ !manualExpanding &&
102
+ !manualFiltering &&
103
+ !manualGrouping &&
104
+ !manualSorting &&
105
+ enableGlobalFilterRankedResults &&
106
+ globalFilterFn === 'fuzzy' &&
107
+ expanded !== true &&
108
+ !Object.values(expanded).some(Boolean)
109
+ );
110
+ };
111
+
112
+ export const getIsRankingRows = <TData extends MRT_RowData>(
113
+ table: MRT_TableInstance<TData>,
114
+ ) => {
115
+ const { globalFilter, sorting } = table.getState();
116
+
117
+ return (
118
+ getCanRankRows(table) &&
119
+ globalFilter &&
120
+ !Object.values(sorting).some(Boolean)
121
+ );
122
+ };
123
+
124
+ export const getIsRowSelected = <TData extends MRT_RowData>({
125
+ row,
126
+ table,
127
+ }: {
128
+ row: MRT_Row<TData>;
129
+ table: MRT_TableInstance<TData>;
130
+ }) => {
131
+ const {
132
+ options: { enableRowSelection },
133
+ } = table;
134
+
135
+ return (
136
+ row.getIsSelected() ||
137
+ (parseFromValuesOrFunc(enableRowSelection, row) &&
138
+ row.getCanSelectSubRows() &&
139
+ row.getIsAllSubRowsSelected())
140
+ );
141
+ };
142
+
143
+ export const getMRT_RowSelectionHandler =
144
+ <TData extends MRT_RowData>({
145
+ row,
146
+ staticRowIndex = 0,
147
+ table,
148
+ }: {
149
+ row: MRT_Row<TData>;
150
+ staticRowIndex?: number;
151
+ table: MRT_TableInstance<TData>;
152
+ }) =>
153
+ (
154
+ event: ChangeEvent<HTMLInputElement> | MouseEvent<HTMLTableRowElement>,
155
+ value?: boolean,
156
+ ) => {
157
+ const {
158
+ options: {
159
+ enableBatchRowSelection,
160
+ enableMultiRowSelection,
161
+ enableRowPinning,
162
+ manualPagination,
163
+ rowPinningDisplayMode,
164
+ },
165
+ refs: { lastSelectedRowId: lastSelectedRowId },
166
+ state,
167
+ } = table;
168
+ const {
169
+ pagination: { pageIndex, pageSize },
170
+ } = state;
171
+
172
+ const paginationOffset = manualPagination ? 0 : pageSize * pageIndex;
173
+
174
+ const wasCurrentRowChecked = getIsRowSelected({ row, table });
175
+
176
+ // toggle selection of this row
177
+ row.toggleSelected(value ?? !wasCurrentRowChecked);
178
+
179
+ const changedRowIds = new Set<string>([row.id]);
180
+
181
+ // if shift key is pressed, select all rows between last selected and this one
182
+ if (
183
+ enableBatchRowSelection &&
184
+ enableMultiRowSelection &&
185
+ (event as any).nativeEvent.shiftKey &&
186
+ lastSelectedRowId.current !== null
187
+ ) {
188
+ const rows = getMRT_Rows(table, true);
189
+
190
+ const lastIndex = rows.findIndex(
191
+ (r) => r.id === lastSelectedRowId.current,
192
+ );
193
+
194
+ if (lastIndex !== -1) {
195
+ const isLastIndexChecked = getIsRowSelected({
196
+ row: rows?.[lastIndex],
197
+ table,
198
+ });
199
+
200
+ const currentIndex = staticRowIndex + paginationOffset;
201
+ const [start, end] =
202
+ lastIndex < currentIndex
203
+ ? [lastIndex, currentIndex]
204
+ : [currentIndex, lastIndex];
205
+
206
+ // toggle selection of all rows between last selected and this one
207
+ // but only if the last selected row is not the same as the current one
208
+ if (wasCurrentRowChecked !== isLastIndexChecked) {
209
+ for (let i = start; i <= end; i++) {
210
+ rows[i].toggleSelected(!wasCurrentRowChecked);
211
+ changedRowIds.add(rows[i].id);
212
+ }
213
+ }
214
+ }
215
+ }
216
+
217
+ // record the last selected row id
218
+ lastSelectedRowId.current = row.id;
219
+
220
+ // if all sub rows were selected, unselect them
221
+ if (row.getCanSelectSubRows() && row.getIsAllSubRowsSelected()) {
222
+ row.subRows?.forEach((r) => r.toggleSelected(false));
223
+ }
224
+
225
+ if (enableRowPinning && rowPinningDisplayMode?.includes('select')) {
226
+ changedRowIds.forEach((rowId) => {
227
+ const rowToTogglePin = table.getRow(rowId);
228
+ rowToTogglePin.pin(
229
+ !wasCurrentRowChecked //was not previously pinned or selected
230
+ ? rowPinningDisplayMode?.includes('bottom')
231
+ ? 'bottom'
232
+ : 'top'
233
+ : false,
234
+ );
235
+ });
236
+ }
237
+ };
238
+
239
+ export const getMRT_SelectAllHandler =
240
+ <TData extends MRT_RowData>({ table }: { table: MRT_TableInstance<TData> }) =>
241
+ (
242
+ event: ChangeEvent<HTMLInputElement> | MouseEvent<HTMLButtonElement>,
243
+ value?: boolean,
244
+ forceAll?: boolean,
245
+ ) => {
246
+ const {
247
+ options: { enableRowPinning, rowPinningDisplayMode, selectAllMode },
248
+ refs: { lastSelectedRowId },
249
+ } = table;
250
+
251
+ selectAllMode === 'all' || forceAll
252
+ ? table.toggleAllRowsSelected(value ?? (event as any).target.checked)
253
+ : table.toggleAllPageRowsSelected(value ?? (event as any).target.checked);
254
+ if (enableRowPinning && rowPinningDisplayMode?.includes('select')) {
255
+ table.setRowPinning({ bottom: [], top: [] });
256
+ }
257
+ lastSelectedRowId.current = null;
258
+ };
@@ -0,0 +1,211 @@
1
+ import { type CSSProperties } from 'react';
2
+ import { alpha, darken, lighten } from '@mui/material/styles';
3
+ import { type Theme } from '@mui/material/styles';
4
+ import { type TableCellProps } from '@mui/material/TableCell';
5
+ import { type TooltipProps } from '@mui/material/Tooltip';
6
+ import { parseFromValuesOrFunc } from './utils';
7
+ import {
8
+ type MRT_Column,
9
+ type MRT_Header,
10
+ type MRT_RowData,
11
+ type MRT_TableInstance,
12
+ type MRT_TableOptions,
13
+ type MRT_Theme,
14
+ } from '../types';
15
+
16
+ export const parseCSSVarId = (id: string) => id.replace(/[^a-zA-Z0-9]/g, '_');
17
+
18
+ export const getMRTTheme = <TData extends MRT_RowData>(
19
+ mrtTheme: MRT_TableOptions<TData>['mrtTheme'],
20
+ muiTheme: Theme,
21
+ ): MRT_Theme => {
22
+ const mrtThemeOverrides = parseFromValuesOrFunc(mrtTheme, muiTheme);
23
+ const baseBackgroundColor =
24
+ mrtThemeOverrides?.baseBackgroundColor ??
25
+ (muiTheme.palette.mode === 'dark'
26
+ ? lighten(muiTheme.palette.background.default, 0.05)
27
+ : muiTheme.palette.background.default);
28
+ return {
29
+ baseBackgroundColor,
30
+ cellNavigationOutlineColor: muiTheme.palette.primary.main,
31
+ draggingBorderColor: muiTheme.palette.primary.main,
32
+ matchHighlightColor:
33
+ muiTheme.palette.mode === 'dark'
34
+ ? darken(muiTheme.palette.warning.dark, 0.25)
35
+ : lighten(muiTheme.palette.warning.light, 0.5),
36
+ menuBackgroundColor: lighten(baseBackgroundColor, 0.07),
37
+ pinnedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.1),
38
+ selectedRowBackgroundColor: alpha(muiTheme.palette.primary.main, 0.2),
39
+ ...mrtThemeOverrides,
40
+ };
41
+ };
42
+
43
+ export const commonCellBeforeAfterStyles = {
44
+ content: '""',
45
+ height: '100%',
46
+ left: 0,
47
+ position: 'absolute',
48
+ top: 0,
49
+ width: '100%',
50
+ zIndex: -1,
51
+ };
52
+
53
+ export const getCommonPinnedCellStyles = <TData extends MRT_RowData>({
54
+ column,
55
+ table,
56
+ theme,
57
+ }: {
58
+ column?: MRT_Column<TData>;
59
+ table: MRT_TableInstance<TData>;
60
+ theme: Theme;
61
+ }) => {
62
+ const { baseBackgroundColor } = table.options.mrtTheme;
63
+ const isPinned = column?.getIsPinned();
64
+
65
+ return {
66
+ '&[data-pinned="true"]': {
67
+ '&:before': {
68
+ backgroundColor: alpha(
69
+ darken(
70
+ baseBackgroundColor,
71
+ theme.palette.mode === 'dark' ? 0.05 : 0.01,
72
+ ),
73
+ 0.97,
74
+ ),
75
+ boxShadow: column
76
+ ? isPinned === 'start' && column.getIsLastColumn(isPinned)
77
+ ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
78
+ : isPinned === 'end' && column.getIsFirstColumn(isPinned)
79
+ ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset`
80
+ : undefined
81
+ : undefined,
82
+ ...commonCellBeforeAfterStyles,
83
+ },
84
+ },
85
+ };
86
+ };
87
+
88
+ export const getCommonMRTCellStyles = <TData extends MRT_RowData>({
89
+ column,
90
+ header,
91
+ table,
92
+ tableCellProps,
93
+ theme,
94
+ }: {
95
+ column: MRT_Column<TData>;
96
+ header?: MRT_Header<TData>;
97
+ table: MRT_TableInstance<TData>;
98
+ tableCellProps: TableCellProps;
99
+ theme: Theme;
100
+ }) => {
101
+ const {
102
+ options: { enableColumnVirtualization, layoutMode },
103
+ state,
104
+ } = table;
105
+ const { draggingColumn } = state;
106
+ const { columnDef } = column;
107
+ const { columnDefType } = columnDef;
108
+
109
+ const isColumnPinned =
110
+ columnDef.columnDefType !== 'group' && column.getIsPinned();
111
+
112
+ const widthStyles: CSSProperties = {
113
+ minWidth: `max(calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
114
+ header?.id ?? column.id,
115
+ )}-size) * 1px), ${columnDef.minSize ?? 30}px)`,
116
+ width: `calc(var(--${header ? 'header' : 'col'}-${parseCSSVarId(
117
+ header?.id ?? column.id,
118
+ )}-size) * 1px)`,
119
+ };
120
+
121
+ if (layoutMode === 'grid') {
122
+ widthStyles.flex = `${
123
+ [0, false].includes(columnDef.grow!)
124
+ ? 0
125
+ : `var(--${header ? 'header' : 'col'}-${parseCSSVarId(
126
+ header?.id ?? column.id,
127
+ )}-size)`
128
+ } 0 auto`;
129
+ } else if (layoutMode === 'grid-no-grow') {
130
+ widthStyles.flex = `${+(columnDef.grow || 0)} 0 auto`;
131
+ }
132
+
133
+ const pinnedStyles = isColumnPinned
134
+ ? {
135
+ ...getCommonPinnedCellStyles({ column, table, theme }),
136
+ insetInlineEnd:
137
+ isColumnPinned === 'end' ? `${column.getAfter('end')}px` : undefined,
138
+ insetInlineStart:
139
+ isColumnPinned === 'start'
140
+ ? `${column.getStart('start')}px`
141
+ : undefined,
142
+ opacity: 0.97,
143
+ position: 'sticky',
144
+ }
145
+ : {};
146
+
147
+ return {
148
+ '&:focus-visible': {
149
+ outline: `2px solid ${table.options.mrtTheme.cellNavigationOutlineColor}`,
150
+ outlineOffset: '-2px',
151
+ },
152
+ backgroundColor: 'inherit',
153
+ backgroundImage: 'inherit',
154
+ display: layoutMode?.startsWith('grid') ? 'flex' : undefined,
155
+ justifyContent:
156
+ columnDefType === 'group'
157
+ ? 'center'
158
+ : layoutMode?.startsWith('grid')
159
+ ? tableCellProps.align
160
+ : undefined,
161
+ opacity:
162
+ table.state.draggingColumn?.id === column.id ||
163
+ table.state.hoveredColumn?.id === column.id
164
+ ? 0.5
165
+ : 1,
166
+ position: 'relative',
167
+ transition: enableColumnVirtualization
168
+ ? 'none'
169
+ : `padding 150ms ease-in-out`,
170
+ zIndex:
171
+ column.getIsResizing() || draggingColumn?.id === column.id
172
+ ? 2
173
+ : columnDefType !== 'group' && isColumnPinned
174
+ ? 1
175
+ : 0,
176
+ ...pinnedStyles,
177
+ ...widthStyles,
178
+ ...(parseFromValuesOrFunc(tableCellProps?.sx, theme) as any),
179
+ };
180
+ };
181
+
182
+ export const getCommonToolbarStyles = <TData extends MRT_RowData>({
183
+ table,
184
+ }: {
185
+ table: MRT_TableInstance<TData>;
186
+ theme: Theme;
187
+ }) => ({
188
+ alignItems: 'flex-start',
189
+ backgroundColor: table.options.mrtTheme.baseBackgroundColor,
190
+ display: 'grid',
191
+ flexWrap: 'wrap-reverse',
192
+ minHeight: '3.5rem',
193
+ overflow: 'hidden',
194
+ position: 'relative',
195
+ transition: 'all 150ms ease-in-out',
196
+ zIndex: 1,
197
+ });
198
+
199
+ export const flipIconStyles = (theme: Theme) =>
200
+ theme.direction === 'rtl'
201
+ ? { style: { transform: 'scaleX(-1)' } }
202
+ : undefined;
203
+
204
+ export const getCommonTooltipProps = (
205
+ placement?: TooltipProps['placement'],
206
+ ): Partial<TooltipProps> => ({
207
+ disableInteractive: true,
208
+ enterDelay: 1000,
209
+ enterNextDelay: 1000,
210
+ placement,
211
+ });
@@ -0,0 +1,64 @@
1
+ import { type JSX, type ReactNode } from 'react';
2
+ import {
3
+ constructRow as _createRow,
4
+ flexRender as _flexRender,
5
+ type Renderable,
6
+ } from '@tanstack/react-table';
7
+ import { getAllLeafColumnDefs, getColumnId } from './column.utils';
8
+ import {
9
+ type MRT_ColumnHelper,
10
+ type MRT_DisplayColumnDef,
11
+ type MRT_GroupColumnDef,
12
+ type MRT_Row,
13
+ type MRT_RowData,
14
+ type MRT_TableInstance,
15
+ } from '../types';
16
+
17
+ export const flexRender = _flexRender as (
18
+ Comp: Renderable<any>,
19
+ props: any,
20
+ ) => JSX.Element | ReactNode;
21
+
22
+ export function createMRTColumnHelper<
23
+ TData extends MRT_RowData,
24
+ >(): MRT_ColumnHelper<TData> {
25
+ return {
26
+ accessor: (accessor, column) => {
27
+ return typeof accessor === 'function'
28
+ ? ({
29
+ ...column,
30
+ accessorFn: accessor,
31
+ } as any)
32
+ : {
33
+ ...column,
34
+ accessorKey: accessor,
35
+ };
36
+ },
37
+ display: (column) => column as MRT_DisplayColumnDef<TData>,
38
+ group: (column) => column as MRT_GroupColumnDef<TData>,
39
+ };
40
+ }
41
+
42
+ export const createRow = <TData extends MRT_RowData>(
43
+ table: MRT_TableInstance<TData>,
44
+ originalRow?: TData,
45
+ rowIndex = -1,
46
+ depth = 0,
47
+ subRows?: MRT_Row<TData>[],
48
+ parentId?: string,
49
+ ): MRT_Row<TData> =>
50
+ _createRow(
51
+ table as any,
52
+ 'mrt-row-create',
53
+ originalRow ??
54
+ Object.assign(
55
+ {},
56
+ ...getAllLeafColumnDefs(table.options.columns).map((col) => ({
57
+ [getColumnId(col)]: '',
58
+ })),
59
+ ),
60
+ rowIndex,
61
+ depth,
62
+ subRows as any,
63
+ parentId,
64
+ ) as MRT_Row<TData>;
@@ -0,0 +1,34 @@
1
+ import { type DropdownOption } from '../types';
2
+
3
+ export const parseFromValuesOrFunc = <T, U>(
4
+ fn: ((arg: U) => T) | T | undefined,
5
+ arg: U,
6
+ ): T | undefined => (fn instanceof Function ? fn(arg) : fn);
7
+
8
+ type SlotPropsObject<S> = Exclude<NonNullable<S>, (...args: any[]) => unknown>;
9
+
10
+ // MRT has no ownerState to call a function-form slot entry with, so only the
11
+ // object form of a MUI slotProps entry is supported.
12
+ export const parseSlotProps = <S>(
13
+ slotProps: S,
14
+ ): SlotPropsObject<S> | undefined =>
15
+ slotProps instanceof Function
16
+ ? undefined
17
+ : (slotProps as SlotPropsObject<S> | undefined);
18
+
19
+ export const getValueAndLabel = (
20
+ option?: DropdownOption | null,
21
+ ): { label: string; value: string } => {
22
+ let label: string = '';
23
+ let value: string = '';
24
+ if (option) {
25
+ if (typeof option !== 'object') {
26
+ label = option;
27
+ value = option;
28
+ } else {
29
+ label = option.label ?? option.value;
30
+ value = option.value ?? label;
31
+ }
32
+ }
33
+ return { label, value };
34
+ };
@@ -0,0 +1,24 @@
1
+ import { defaultRangeExtractor, type Range } from '@tanstack/react-virtual';
2
+
3
+ /**
4
+ * When scroll, the `draggingRow` or `draggingColumn` can be removed from document because of virtualization,
5
+ * then, the `dragEnd` event on `MRT_TableBodyRowGrabHandle` or `MRT_TableHeadCellGrabHandle` will not fire.
6
+ * We should keep the `draggingRow` or `draggingColumn` in `getVirtualItems()` to avoid this thing.
7
+ */
8
+ export const extraIndexRangeExtractor = (
9
+ range: Range,
10
+ draggingIndex?: number,
11
+ ) => {
12
+ const newIndexes = defaultRangeExtractor(range);
13
+ if (draggingIndex === undefined) return newIndexes;
14
+ if (
15
+ draggingIndex >= 0 &&
16
+ draggingIndex < Math.max(range.startIndex - range.overscan, 0)
17
+ ) {
18
+ newIndexes.unshift(draggingIndex);
19
+ }
20
+ if (draggingIndex >= 0 && draggingIndex > range.endIndex + range.overscan) {
21
+ newIndexes.push(draggingIndex);
22
+ }
23
+ return newIndexes;
24
+ };