@novastera-oss/material-react-table 4.0.0-beta.7

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 (324) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +233 -0
  3. package/dist/index.cjs +5190 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.ts +1871 -0
  6. package/dist/index.js +5084 -0
  7. package/dist/index.js.map +1 -0
  8. package/locales/ar/index.d.ts +3 -0
  9. package/locales/ar/index.esm.d.ts +3 -0
  10. package/locales/ar/index.esm.js +96 -0
  11. package/locales/ar/index.js +98 -0
  12. package/locales/ar/package.json +6 -0
  13. package/locales/az/index.d.ts +3 -0
  14. package/locales/az/index.esm.d.ts +3 -0
  15. package/locales/az/index.esm.js +96 -0
  16. package/locales/az/index.js +98 -0
  17. package/locales/az/package.json +6 -0
  18. package/locales/bg/index.d.ts +3 -0
  19. package/locales/bg/index.esm.d.ts +3 -0
  20. package/locales/bg/index.esm.js +96 -0
  21. package/locales/bg/index.js +98 -0
  22. package/locales/bg/package.json +6 -0
  23. package/locales/cs/index.d.ts +3 -0
  24. package/locales/cs/index.esm.d.ts +3 -0
  25. package/locales/cs/index.esm.js +96 -0
  26. package/locales/cs/index.js +98 -0
  27. package/locales/cs/package.json +6 -0
  28. package/locales/da/index.d.ts +3 -0
  29. package/locales/da/index.esm.d.ts +3 -0
  30. package/locales/da/index.esm.js +96 -0
  31. package/locales/da/index.js +98 -0
  32. package/locales/da/package.json +6 -0
  33. package/locales/de/index.d.ts +3 -0
  34. package/locales/de/index.esm.d.ts +3 -0
  35. package/locales/de/index.esm.js +96 -0
  36. package/locales/de/index.js +98 -0
  37. package/locales/de/package.json +6 -0
  38. package/locales/el/index.d.ts +3 -0
  39. package/locales/el/index.esm.d.ts +3 -0
  40. package/locales/el/index.esm.js +96 -0
  41. package/locales/el/index.js +98 -0
  42. package/locales/el/package.json +6 -0
  43. package/locales/en/index.d.ts +3 -0
  44. package/locales/en/index.esm.d.ts +3 -0
  45. package/locales/en/index.esm.js +96 -0
  46. package/locales/en/index.js +98 -0
  47. package/locales/en/package.json +6 -0
  48. package/locales/es/index.d.ts +3 -0
  49. package/locales/es/index.esm.d.ts +3 -0
  50. package/locales/es/index.esm.js +96 -0
  51. package/locales/es/index.js +98 -0
  52. package/locales/es/package.json +6 -0
  53. package/locales/et/index.d.ts +3 -0
  54. package/locales/et/index.esm.d.ts +3 -0
  55. package/locales/et/index.esm.js +96 -0
  56. package/locales/et/index.js +98 -0
  57. package/locales/et/package.json +6 -0
  58. package/locales/fa/index.d.ts +3 -0
  59. package/locales/fa/index.esm.d.ts +3 -0
  60. package/locales/fa/index.esm.js +96 -0
  61. package/locales/fa/index.js +98 -0
  62. package/locales/fa/package.json +6 -0
  63. package/locales/fi/index.d.ts +3 -0
  64. package/locales/fi/index.esm.d.ts +3 -0
  65. package/locales/fi/index.esm.js +96 -0
  66. package/locales/fi/index.js +98 -0
  67. package/locales/fi/package.json +6 -0
  68. package/locales/fr/index.d.ts +3 -0
  69. package/locales/fr/index.esm.d.ts +3 -0
  70. package/locales/fr/index.esm.js +96 -0
  71. package/locales/fr/index.js +98 -0
  72. package/locales/fr/package.json +6 -0
  73. package/locales/he/index.d.ts +3 -0
  74. package/locales/he/index.esm.d.ts +3 -0
  75. package/locales/he/index.esm.js +96 -0
  76. package/locales/he/index.js +98 -0
  77. package/locales/he/package.json +6 -0
  78. package/locales/hr/index.d.ts +3 -0
  79. package/locales/hr/index.esm.d.ts +3 -0
  80. package/locales/hr/index.esm.js +96 -0
  81. package/locales/hr/index.js +98 -0
  82. package/locales/hr/package.json +6 -0
  83. package/locales/hu/index.d.ts +3 -0
  84. package/locales/hu/index.esm.d.ts +3 -0
  85. package/locales/hu/index.esm.js +96 -0
  86. package/locales/hu/index.js +98 -0
  87. package/locales/hu/package.json +6 -0
  88. package/locales/hy/index.d.ts +3 -0
  89. package/locales/hy/index.esm.d.ts +3 -0
  90. package/locales/hy/index.esm.js +96 -0
  91. package/locales/hy/index.js +98 -0
  92. package/locales/hy/package.json +6 -0
  93. package/locales/id/index.d.ts +3 -0
  94. package/locales/id/index.esm.d.ts +3 -0
  95. package/locales/id/index.esm.js +96 -0
  96. package/locales/id/index.js +98 -0
  97. package/locales/id/package.json +6 -0
  98. package/locales/it/index.d.ts +3 -0
  99. package/locales/it/index.esm.d.ts +3 -0
  100. package/locales/it/index.esm.js +96 -0
  101. package/locales/it/index.js +98 -0
  102. package/locales/it/package.json +6 -0
  103. package/locales/ja/index.d.ts +3 -0
  104. package/locales/ja/index.esm.d.ts +3 -0
  105. package/locales/ja/index.esm.js +96 -0
  106. package/locales/ja/index.js +98 -0
  107. package/locales/ja/package.json +6 -0
  108. package/locales/ko/index.d.ts +3 -0
  109. package/locales/ko/index.esm.d.ts +3 -0
  110. package/locales/ko/index.esm.js +96 -0
  111. package/locales/ko/index.js +98 -0
  112. package/locales/ko/package.json +6 -0
  113. package/locales/nl/index.d.ts +3 -0
  114. package/locales/nl/index.esm.d.ts +3 -0
  115. package/locales/nl/index.esm.js +96 -0
  116. package/locales/nl/index.js +98 -0
  117. package/locales/nl/package.json +6 -0
  118. package/locales/no/index.d.ts +3 -0
  119. package/locales/no/index.esm.d.ts +3 -0
  120. package/locales/no/index.esm.js +96 -0
  121. package/locales/no/index.js +98 -0
  122. package/locales/no/package.json +6 -0
  123. package/locales/np/index.d.ts +3 -0
  124. package/locales/np/index.esm.d.ts +3 -0
  125. package/locales/np/index.esm.js +96 -0
  126. package/locales/np/index.js +98 -0
  127. package/locales/np/package.json +6 -0
  128. package/locales/pl/index.d.ts +3 -0
  129. package/locales/pl/index.esm.d.ts +3 -0
  130. package/locales/pl/index.esm.js +96 -0
  131. package/locales/pl/index.js +98 -0
  132. package/locales/pl/package.json +6 -0
  133. package/locales/pt/index.d.ts +3 -0
  134. package/locales/pt/index.esm.d.ts +3 -0
  135. package/locales/pt/index.esm.js +96 -0
  136. package/locales/pt/index.js +98 -0
  137. package/locales/pt/package.json +6 -0
  138. package/locales/pt-BR/index.d.ts +3 -0
  139. package/locales/pt-BR/index.esm.d.ts +3 -0
  140. package/locales/pt-BR/index.esm.js +96 -0
  141. package/locales/pt-BR/index.js +98 -0
  142. package/locales/pt-BR/package.json +6 -0
  143. package/locales/ro/index.d.ts +3 -0
  144. package/locales/ro/index.esm.d.ts +3 -0
  145. package/locales/ro/index.esm.js +96 -0
  146. package/locales/ro/index.js +98 -0
  147. package/locales/ro/package.json +6 -0
  148. package/locales/ru/index.d.ts +3 -0
  149. package/locales/ru/index.esm.d.ts +3 -0
  150. package/locales/ru/index.esm.js +96 -0
  151. package/locales/ru/index.js +98 -0
  152. package/locales/ru/package.json +6 -0
  153. package/locales/sk/index.d.ts +3 -0
  154. package/locales/sk/index.esm.d.ts +3 -0
  155. package/locales/sk/index.esm.js +96 -0
  156. package/locales/sk/index.js +98 -0
  157. package/locales/sk/package.json +6 -0
  158. package/locales/sr-Cyrl-RS/index.d.ts +3 -0
  159. package/locales/sr-Cyrl-RS/index.esm.d.ts +3 -0
  160. package/locales/sr-Cyrl-RS/index.esm.js +96 -0
  161. package/locales/sr-Cyrl-RS/index.js +98 -0
  162. package/locales/sr-Cyrl-RS/package.json +6 -0
  163. package/locales/sr-Latn-RS/index.d.ts +3 -0
  164. package/locales/sr-Latn-RS/index.esm.d.ts +3 -0
  165. package/locales/sr-Latn-RS/index.esm.js +96 -0
  166. package/locales/sr-Latn-RS/index.js +98 -0
  167. package/locales/sr-Latn-RS/package.json +6 -0
  168. package/locales/sv/index.d.ts +3 -0
  169. package/locales/sv/index.esm.d.ts +3 -0
  170. package/locales/sv/index.esm.js +96 -0
  171. package/locales/sv/index.js +98 -0
  172. package/locales/sv/package.json +6 -0
  173. package/locales/tr/index.d.ts +3 -0
  174. package/locales/tr/index.esm.d.ts +3 -0
  175. package/locales/tr/index.esm.js +96 -0
  176. package/locales/tr/index.js +98 -0
  177. package/locales/tr/package.json +6 -0
  178. package/locales/uk/index.d.ts +3 -0
  179. package/locales/uk/index.esm.d.ts +3 -0
  180. package/locales/uk/index.esm.js +96 -0
  181. package/locales/uk/index.js +98 -0
  182. package/locales/uk/package.json +6 -0
  183. package/locales/vi/index.d.ts +3 -0
  184. package/locales/vi/index.esm.d.ts +3 -0
  185. package/locales/vi/index.esm.js +96 -0
  186. package/locales/vi/index.js +98 -0
  187. package/locales/vi/package.json +6 -0
  188. package/locales/zh-Hans/index.d.ts +3 -0
  189. package/locales/zh-Hans/index.esm.d.ts +3 -0
  190. package/locales/zh-Hans/index.esm.js +96 -0
  191. package/locales/zh-Hans/index.js +98 -0
  192. package/locales/zh-Hans/package.json +6 -0
  193. package/locales/zh-Hant/index.d.ts +3 -0
  194. package/locales/zh-Hant/index.esm.d.ts +3 -0
  195. package/locales/zh-Hant/index.esm.js +96 -0
  196. package/locales/zh-Hant/index.js +98 -0
  197. package/locales/zh-Hant/package.json +6 -0
  198. package/package.json +103 -0
  199. package/src/components/MaterialReactTable.tsx +36 -0
  200. package/src/components/body/MRT_TableBody.tsx +233 -0
  201. package/src/components/body/MRT_TableBodyCell.tsx +356 -0
  202. package/src/components/body/MRT_TableBodyCellValue.tsx +130 -0
  203. package/src/components/body/MRT_TableBodyRow.tsx +306 -0
  204. package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +61 -0
  205. package/src/components/body/MRT_TableBodyRowPinButton.tsx +58 -0
  206. package/src/components/body/MRT_TableDetailPanel.tsx +118 -0
  207. package/src/components/buttons/MRT_ColumnPinningButtons.tsx +73 -0
  208. package/src/components/buttons/MRT_CopyButton.tsx +91 -0
  209. package/src/components/buttons/MRT_EditActionButtons.tsx +135 -0
  210. package/src/components/buttons/MRT_ExpandAllButton.tsx +82 -0
  211. package/src/components/buttons/MRT_ExpandButton.tsx +106 -0
  212. package/src/components/buttons/MRT_GrabHandleButton.tsx +66 -0
  213. package/src/components/buttons/MRT_RowPinButton.tsx +84 -0
  214. package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +50 -0
  215. package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +52 -0
  216. package/src/components/buttons/MRT_ToggleFiltersButton.tsx +40 -0
  217. package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +51 -0
  218. package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +46 -0
  219. package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +126 -0
  220. package/src/components/footer/MRT_TableFooter.tsx +92 -0
  221. package/src/components/footer/MRT_TableFooterCell.tsx +111 -0
  222. package/src/components/footer/MRT_TableFooterRow.tsx +99 -0
  223. package/src/components/head/MRT_TableHead.tsx +95 -0
  224. package/src/components/head/MRT_TableHeadCell.tsx +357 -0
  225. package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +100 -0
  226. package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +52 -0
  227. package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +180 -0
  228. package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +91 -0
  229. package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +96 -0
  230. package/src/components/head/MRT_TableHeadCellSortLabel.tsx +102 -0
  231. package/src/components/head/MRT_TableHeadRow.tsx +94 -0
  232. package/src/components/inputs/MRT_EditCellTextField.tsx +195 -0
  233. package/src/components/inputs/MRT_FilterCheckbox.tsx +94 -0
  234. package/src/components/inputs/MRT_FilterRangeFields.tsx +42 -0
  235. package/src/components/inputs/MRT_FilterRangeSlider.tsx +145 -0
  236. package/src/components/inputs/MRT_FilterTextField.tsx +610 -0
  237. package/src/components/inputs/MRT_GlobalFilterTextField.tsx +166 -0
  238. package/src/components/inputs/MRT_SelectCheckbox.tsx +133 -0
  239. package/src/components/menus/MRT_ActionMenuItem.tsx +62 -0
  240. package/src/components/menus/MRT_CellActionMenu.tsx +109 -0
  241. package/src/components/menus/MRT_ColumnActionMenu.tsx +354 -0
  242. package/src/components/menus/MRT_FilterOptionMenu.tsx +294 -0
  243. package/src/components/menus/MRT_RowActionMenu.tsx +90 -0
  244. package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +181 -0
  245. package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +204 -0
  246. package/src/components/modals/MRT_EditRowModal.tsx +114 -0
  247. package/src/components/table/MRT_Table.tsx +86 -0
  248. package/src/components/table/MRT_TableContainer.tsx +115 -0
  249. package/src/components/table/MRT_TableLoadingOverlay.tsx +58 -0
  250. package/src/components/table/MRT_TablePaper.tsx +91 -0
  251. package/src/components/toolbar/MRT_BottomToolbar.tsx +112 -0
  252. package/src/components/toolbar/MRT_LinearProgressBar.tsx +53 -0
  253. package/src/components/toolbar/MRT_TablePagination.tsx +241 -0
  254. package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +182 -0
  255. package/src/components/toolbar/MRT_ToolbarDropZone.tsx +82 -0
  256. package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +73 -0
  257. package/src/components/toolbar/MRT_TopToolbar.tsx +134 -0
  258. package/src/fns/aggregationFns.ts +3 -0
  259. package/src/fns/filterFns.ts +196 -0
  260. package/src/fns/sortingFns.ts +33 -0
  261. package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +28 -0
  262. package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +29 -0
  263. package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +91 -0
  264. package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +30 -0
  265. package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +24 -0
  266. package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +34 -0
  267. package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +33 -0
  268. package/src/hooks/useMRT_ColumnVirtualizer.ts +124 -0
  269. package/src/hooks/useMRT_Effects.ts +106 -0
  270. package/src/hooks/useMRT_RowVirtualizer.ts +88 -0
  271. package/src/hooks/useMRT_Rows.ts +44 -0
  272. package/src/hooks/useMRT_TableInstance.ts +317 -0
  273. package/src/hooks/useMRT_TableOptions.ts +270 -0
  274. package/src/hooks/useMaterialReactTable.ts +12 -0
  275. package/src/icons.ts +73 -0
  276. package/src/index.ts +91 -0
  277. package/src/locales/ar.ts +97 -0
  278. package/src/locales/az.ts +97 -0
  279. package/src/locales/bg.ts +97 -0
  280. package/src/locales/cs.ts +98 -0
  281. package/src/locales/da.ts +97 -0
  282. package/src/locales/de.ts +97 -0
  283. package/src/locales/el.ts +97 -0
  284. package/src/locales/en.ts +97 -0
  285. package/src/locales/es.ts +97 -0
  286. package/src/locales/et.ts +98 -0
  287. package/src/locales/fa.ts +97 -0
  288. package/src/locales/fi.ts +98 -0
  289. package/src/locales/fr.ts +97 -0
  290. package/src/locales/he.ts +97 -0
  291. package/src/locales/hr.ts +97 -0
  292. package/src/locales/hu.ts +97 -0
  293. package/src/locales/hy.ts +97 -0
  294. package/src/locales/id.ts +98 -0
  295. package/src/locales/it.ts +97 -0
  296. package/src/locales/ja.ts +97 -0
  297. package/src/locales/ko.ts +97 -0
  298. package/src/locales/mk.ts +96 -0
  299. package/src/locales/nl.ts +97 -0
  300. package/src/locales/no.ts +99 -0
  301. package/src/locales/np.ts +98 -0
  302. package/src/locales/pl.ts +97 -0
  303. package/src/locales/pt-BR.ts +97 -0
  304. package/src/locales/pt.ts +97 -0
  305. package/src/locales/ro.ts +97 -0
  306. package/src/locales/ru.ts +97 -0
  307. package/src/locales/sk.ts +98 -0
  308. package/src/locales/sr-Cyrl-RS.ts +97 -0
  309. package/src/locales/sr-Latn-RS.ts +97 -0
  310. package/src/locales/sv.ts +97 -0
  311. package/src/locales/tr.ts +97 -0
  312. package/src/locales/uk.ts +97 -0
  313. package/src/locales/vi.ts +97 -0
  314. package/src/locales/zh-Hans.ts +96 -0
  315. package/src/locales/zh-Hant.ts +96 -0
  316. package/src/types.ts +1298 -0
  317. package/src/utils/cell.utils.ts +234 -0
  318. package/src/utils/column.utils.ts +209 -0
  319. package/src/utils/displayColumn.utils.ts +152 -0
  320. package/src/utils/row.utils.ts +260 -0
  321. package/src/utils/style.utils.ts +221 -0
  322. package/src/utils/tanstack.helpers.ts +64 -0
  323. package/src/utils/utils.ts +56 -0
  324. package/src/utils/virtualization.utils.ts +24 -0
@@ -0,0 +1,28 @@
1
+ import { MRT_ToggleRowActionMenuButton } from '../../components/buttons/MRT_ToggleRowActionMenuButton';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
+
9
+ export const getMRT_RowActionsColumnDef = <TData extends MRT_RowData>(
10
+ tableOptions: MRT_StatefulTableOptions<TData>,
11
+ ): MRT_ColumnDef<TData> => {
12
+ return {
13
+ Cell: ({ cell, row, staticRowIndex, table }) => (
14
+ <MRT_ToggleRowActionMenuButton
15
+ cell={cell}
16
+ row={row}
17
+ staticRowIndex={staticRowIndex}
18
+ table={table}
19
+ />
20
+ ),
21
+ ...defaultDisplayColumnProps({
22
+ header: 'actions',
23
+ id: 'mrt-row-actions',
24
+ size: 70,
25
+ tableOptions,
26
+ }),
27
+ };
28
+ };
@@ -0,0 +1,29 @@
1
+ import { type RefObject } from 'react';
2
+ import { MRT_TableBodyRowGrabHandle } from '../../components/body/MRT_TableBodyRowGrabHandle';
3
+ import {
4
+ type MRT_ColumnDef,
5
+ type MRT_RowData,
6
+ type MRT_StatefulTableOptions,
7
+ } from '../../types';
8
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
9
+
10
+ export const getMRT_RowDragColumnDef = <TData extends MRT_RowData>(
11
+ tableOptions: MRT_StatefulTableOptions<TData>,
12
+ ): MRT_ColumnDef<TData> => {
13
+ return {
14
+ Cell: ({ row, rowRef, table }) => (
15
+ <MRT_TableBodyRowGrabHandle
16
+ row={row}
17
+ rowRef={rowRef as RefObject<HTMLTableRowElement | null>}
18
+ table={table}
19
+ />
20
+ ),
21
+ grow: false,
22
+ ...defaultDisplayColumnProps({
23
+ header: 'move',
24
+ id: 'mrt-row-drag',
25
+ size: 60,
26
+ tableOptions,
27
+ }),
28
+ };
29
+ };
@@ -0,0 +1,91 @@
1
+ import { type ReactNode } from 'react';
2
+ import Stack from '@mui/material/Stack';
3
+ import Tooltip from '@mui/material/Tooltip';
4
+ import { MRT_ExpandAllButton } from '../../components/buttons/MRT_ExpandAllButton';
5
+ import { MRT_ExpandButton } from '../../components/buttons/MRT_ExpandButton';
6
+ import {
7
+ type MRT_ColumnDef,
8
+ type MRT_RowData,
9
+ type MRT_StatefulTableOptions,
10
+ } from '../../types';
11
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
12
+ import { getCommonTooltipProps } from '../../utils/style.utils';
13
+
14
+ export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
15
+ tableOptions: MRT_StatefulTableOptions<TData>,
16
+ ): MRT_ColumnDef<TData> => {
17
+ const {
18
+ defaultColumn,
19
+ enableExpandAll,
20
+ groupedColumnMode,
21
+ positionExpandColumn,
22
+ renderDetailPanel,
23
+ state: { grouping },
24
+ } = tableOptions;
25
+
26
+ const alignProps =
27
+ positionExpandColumn === 'last'
28
+ ? ({
29
+ align: 'right',
30
+ } as const)
31
+ : undefined;
32
+
33
+ return {
34
+ Cell: ({ cell, column, row, staticRowIndex, table }) => {
35
+ const expandButtonProps = { row, staticRowIndex, table };
36
+ const subRowsLength = row.subRows?.length;
37
+ if (groupedColumnMode === 'remove' && row.groupingColumnId) {
38
+ return (
39
+ <Stack sx={{ alignItems: 'center', gap: '0.25rem' }} direction="row">
40
+ <MRT_ExpandButton {...expandButtonProps} />
41
+ <Tooltip
42
+ {...getCommonTooltipProps('right')}
43
+ title={table.getColumn(row.groupingColumnId).columnDef.header}
44
+ >
45
+ <span>{row.groupingValue as ReactNode}</span>
46
+ </Tooltip>
47
+ {!!subRowsLength && <span>({subRowsLength})</span>}
48
+ </Stack>
49
+ );
50
+ } else {
51
+ return (
52
+ <>
53
+ <MRT_ExpandButton {...expandButtonProps} />
54
+ {column.columnDef.GroupedCell?.({ cell, column, row, table })}
55
+ </>
56
+ );
57
+ }
58
+ },
59
+ Header: enableExpandAll
60
+ ? ({ table }) => {
61
+ return (
62
+ <>
63
+ <MRT_ExpandAllButton table={table} />
64
+ {groupedColumnMode === 'remove' &&
65
+ grouping
66
+ ?.map(
67
+ (groupedColumnId) =>
68
+ table.getColumn(groupedColumnId).columnDef.header,
69
+ )
70
+ ?.join(', ')}
71
+ </>
72
+ );
73
+ }
74
+ : undefined,
75
+ muiTableBodyCellProps: alignProps,
76
+ muiTableHeadCellProps: alignProps,
77
+ ...defaultDisplayColumnProps({
78
+ header: 'expand',
79
+ id: 'mrt-row-expand',
80
+ size:
81
+ groupedColumnMode === 'remove'
82
+ ? (defaultColumn?.size ?? 180)
83
+ : renderDetailPanel
84
+ ? enableExpandAll
85
+ ? 60
86
+ : 70
87
+ : 100,
88
+ tableOptions,
89
+ }),
90
+ };
91
+ };
@@ -0,0 +1,30 @@
1
+ import {
2
+ type MRT_ColumnDef,
3
+ type MRT_RowData,
4
+ type MRT_StatefulTableOptions,
5
+ } from '../../types';
6
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
7
+
8
+ export const getMRT_RowNumbersColumnDef = <TData extends MRT_RowData>(
9
+ tableOptions: MRT_StatefulTableOptions<TData>,
10
+ ): MRT_ColumnDef<TData> => {
11
+ const { localization, rowNumberDisplayMode } = tableOptions;
12
+ const {
13
+ pagination: { pageIndex, pageSize },
14
+ } = tableOptions.state;
15
+
16
+ return {
17
+ Cell: ({ row, staticRowIndex }) =>
18
+ ((rowNumberDisplayMode === 'static'
19
+ ? (staticRowIndex || 0) + (pageSize || 0) * (pageIndex || 0)
20
+ : row.index) ?? 0) + 1,
21
+ Header: () => localization.rowNumber,
22
+ grow: false,
23
+ ...defaultDisplayColumnProps({
24
+ header: 'rowNumbers',
25
+ id: 'mrt-row-numbers',
26
+ size: 50,
27
+ tableOptions,
28
+ }),
29
+ };
30
+ };
@@ -0,0 +1,24 @@
1
+ import { MRT_TableBodyRowPinButton } from '../../components/body/MRT_TableBodyRowPinButton';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
+
9
+ export const getMRT_RowPinningColumnDef = <TData extends MRT_RowData>(
10
+ tableOptions: MRT_StatefulTableOptions<TData>,
11
+ ): MRT_ColumnDef<TData> => {
12
+ return {
13
+ Cell: ({ row, table }) => (
14
+ <MRT_TableBodyRowPinButton row={row} table={table} />
15
+ ),
16
+ grow: false,
17
+ ...defaultDisplayColumnProps({
18
+ header: 'pin',
19
+ id: 'mrt-row-pin',
20
+ size: 60,
21
+ tableOptions,
22
+ }),
23
+ };
24
+ };
@@ -0,0 +1,34 @@
1
+ import { MRT_SelectCheckbox } from '../../components/inputs/MRT_SelectCheckbox';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
+
9
+ export const getMRT_RowSelectColumnDef = <TData extends MRT_RowData>(
10
+ tableOptions: MRT_StatefulTableOptions<TData>,
11
+ ): MRT_ColumnDef<TData> => {
12
+ const { enableMultiRowSelection, enableSelectAll } = tableOptions;
13
+
14
+ return {
15
+ Cell: ({ row, staticRowIndex, table }) => (
16
+ <MRT_SelectCheckbox
17
+ row={row}
18
+ staticRowIndex={staticRowIndex}
19
+ table={table}
20
+ />
21
+ ),
22
+ Header:
23
+ enableSelectAll && enableMultiRowSelection
24
+ ? ({ table }) => <MRT_SelectCheckbox table={table} />
25
+ : undefined,
26
+ grow: false,
27
+ ...defaultDisplayColumnProps({
28
+ header: 'select',
29
+ id: 'mrt-row-select',
30
+ size: enableSelectAll ? 60 : 70,
31
+ tableOptions,
32
+ }),
33
+ };
34
+ };
@@ -0,0 +1,33 @@
1
+ import { MRT_DefaultDisplayColumn } from '../useMRT_TableOptions';
2
+ import {
3
+ type MRT_ColumnDef,
4
+ type MRT_RowData,
5
+ type MRT_StatefulTableOptions,
6
+ } from '../../types';
7
+ import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
8
+
9
+ const blankColProps = {
10
+ children: null,
11
+ sx: {
12
+ minWidth: 0,
13
+ p: 0,
14
+ width: 0,
15
+ },
16
+ };
17
+
18
+ export const getMRT_RowSpacerColumnDef = <TData extends MRT_RowData>(
19
+ tableOptions: MRT_StatefulTableOptions<TData>,
20
+ ): MRT_ColumnDef<TData> => {
21
+ return {
22
+ ...defaultDisplayColumnProps({
23
+ id: 'mrt-row-spacer',
24
+ size: 0,
25
+ tableOptions,
26
+ }),
27
+ grow: true,
28
+ ...MRT_DefaultDisplayColumn,
29
+ muiTableBodyCellProps: blankColProps,
30
+ muiTableFooterCellProps: blankColProps,
31
+ muiTableHeadCellProps: blankColProps,
32
+ };
33
+ };
@@ -0,0 +1,124 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { type Range, useVirtualizer } from '@tanstack/react-virtual';
3
+ import {
4
+ type MRT_ColumnVirtualizer,
5
+ type MRT_RowData,
6
+ type MRT_TableInstance,
7
+ } from '../types';
8
+ import { parseFromValuesOrFunc } from '../utils/utils';
9
+ import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
10
+
11
+ export const useMRT_ColumnVirtualizer = <
12
+ TData extends MRT_RowData,
13
+ TScrollElement extends Element | Window = HTMLDivElement,
14
+ TItemElement extends Element = HTMLTableCellElement,
15
+ >(
16
+ table: MRT_TableInstance<TData>,
17
+ ): MRT_ColumnVirtualizer | undefined => {
18
+ const {
19
+ getState,
20
+ options: {
21
+ columnVirtualizerInstanceRef,
22
+ columnVirtualizerOptions,
23
+ enableColumnPinning,
24
+ enableColumnVirtualization,
25
+ },
26
+ refs: { tableContainerRef },
27
+ } = table;
28
+ const { columnPinning, columnVisibility, draggingColumn } = getState();
29
+
30
+ if (!enableColumnVirtualization) return undefined;
31
+
32
+ const columnVirtualizerProps = parseFromValuesOrFunc(
33
+ columnVirtualizerOptions,
34
+ {
35
+ table,
36
+ },
37
+ );
38
+
39
+ const visibleColumns = table.getVisibleLeafColumns();
40
+
41
+ const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(
42
+ () =>
43
+ enableColumnPinning
44
+ ? [
45
+ table.getLeftVisibleLeafColumns().map((c) => c.getPinnedIndex()),
46
+ table
47
+ .getRightVisibleLeafColumns()
48
+ .map(
49
+ (column) => visibleColumns.length - column.getPinnedIndex() - 1,
50
+ )
51
+ .sort((a, b) => a - b),
52
+ ]
53
+ : [[], []],
54
+ [columnPinning, columnVisibility, enableColumnPinning],
55
+ );
56
+
57
+ const numPinnedLeft = leftPinnedIndexes.length;
58
+ const numPinnedRight = rightPinnedIndexes.length;
59
+
60
+ const draggingColumnIndex = useMemo(
61
+ () =>
62
+ draggingColumn?.id
63
+ ? visibleColumns.findIndex((c) => c.id === draggingColumn?.id)
64
+ : undefined,
65
+ [draggingColumn?.id],
66
+ );
67
+
68
+ const columnVirtualizer = useVirtualizer({
69
+ count: visibleColumns.length,
70
+ estimateSize: (index) => visibleColumns[index].getSize(),
71
+ getScrollElement: () => tableContainerRef.current,
72
+ horizontal: true,
73
+ overscan: 3,
74
+ rangeExtractor: useCallback(
75
+ (range: Range) => {
76
+ const newIndexes = extraIndexRangeExtractor(range, draggingColumnIndex);
77
+ if (!numPinnedLeft && !numPinnedRight) {
78
+ return newIndexes;
79
+ }
80
+ return [
81
+ ...new Set([
82
+ ...leftPinnedIndexes,
83
+ ...newIndexes,
84
+ ...rightPinnedIndexes,
85
+ ]),
86
+ ];
87
+ },
88
+ [leftPinnedIndexes, rightPinnedIndexes, draggingColumnIndex],
89
+ ),
90
+ ...columnVirtualizerProps,
91
+ }) as unknown as MRT_ColumnVirtualizer<TScrollElement, TItemElement>;
92
+
93
+ const virtualColumns = columnVirtualizer.getVirtualItems();
94
+ columnVirtualizer.virtualColumns = virtualColumns as any;
95
+ const numColumns = virtualColumns.length;
96
+
97
+ if (numColumns) {
98
+ const totalSize = columnVirtualizer.getTotalSize();
99
+
100
+ const leftNonPinnedStart = virtualColumns[numPinnedLeft]?.start || 0;
101
+ const leftNonPinnedEnd =
102
+ virtualColumns[leftPinnedIndexes.length - 1]?.end || 0;
103
+
104
+ const rightNonPinnedStart =
105
+ virtualColumns[numColumns - numPinnedRight]?.start || 0;
106
+ const rightNonPinnedEnd =
107
+ virtualColumns[numColumns - numPinnedRight - 1]?.end || 0;
108
+
109
+ columnVirtualizer.virtualPaddingLeft =
110
+ leftNonPinnedStart - leftNonPinnedEnd;
111
+
112
+ columnVirtualizer.virtualPaddingRight =
113
+ totalSize -
114
+ rightNonPinnedEnd -
115
+ (numPinnedRight ? totalSize - rightNonPinnedStart : 0);
116
+ }
117
+
118
+ if (columnVirtualizerInstanceRef) {
119
+ //@ts-expect-error
120
+ columnVirtualizerInstanceRef.current = columnVirtualizer;
121
+ }
122
+
123
+ return columnVirtualizer as any;
124
+ };
@@ -0,0 +1,106 @@
1
+ import { useEffect, useReducer, useRef } from 'react';
2
+ import {
3
+ type MRT_RowData,
4
+ type MRT_SortingState,
5
+ type MRT_TableInstance,
6
+ } from '../types';
7
+ import { getDefaultColumnOrderIds } from '../utils/displayColumn.utils';
8
+ import { getCanRankRows } from '../utils/row.utils';
9
+
10
+ export const useMRT_Effects = <TData extends MRT_RowData>(
11
+ table: MRT_TableInstance<TData>,
12
+ ) => {
13
+ const {
14
+ getIsSomeRowsPinned,
15
+ getPrePaginationRowModel,
16
+ getState,
17
+ options: { enablePagination, enableRowPinning, rowCount },
18
+ } = table;
19
+ const {
20
+ columnOrder,
21
+ density,
22
+ globalFilter,
23
+ isFullScreen,
24
+ isLoading,
25
+ pagination,
26
+ showSkeletons,
27
+ sorting,
28
+ } = getState();
29
+
30
+ const totalColumnCount = table.options.columns.length;
31
+ const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
32
+
33
+ const rerender = useReducer(() => ({}), {})[1];
34
+ const initialBodyHeight = useRef<string>(null);
35
+ const previousTop = useRef<number>(null);
36
+
37
+ useEffect(() => {
38
+ if (typeof window !== 'undefined') {
39
+ initialBodyHeight.current = document.body.style.height;
40
+ }
41
+ }, []);
42
+
43
+ //hide scrollbars when table is in full screen mode, preserve body scroll position after full screen exit
44
+ useEffect(() => {
45
+ if (typeof window !== 'undefined') {
46
+ if (isFullScreen) {
47
+ previousTop.current = document.body.getBoundingClientRect().top; //save scroll position
48
+ document.body.style.height = '100dvh'; //hide page scrollbars when table is in full screen mode
49
+ } else {
50
+ document.body.style.height = initialBodyHeight.current as string;
51
+ if (!previousTop.current) return;
52
+ //restore scroll position
53
+ window.scrollTo({
54
+ behavior: 'instant',
55
+ top: -1 * (previousTop.current as number),
56
+ });
57
+ }
58
+ }
59
+ }, [isFullScreen]);
60
+
61
+ //recalculate column order when columns change or features are toggled on/off
62
+ useEffect(() => {
63
+ if (totalColumnCount !== columnOrder.length) {
64
+ table.setColumnOrder(getDefaultColumnOrderIds(table.options));
65
+ }
66
+ }, [totalColumnCount]);
67
+
68
+ //if page index is out of bounds, set it to the last page
69
+ useEffect(() => {
70
+ if (!enablePagination || isLoading || showSkeletons) return;
71
+ const { pageIndex, pageSize } = pagination;
72
+ const totalPages: number =
73
+ totalRowCount > 0 ? Math.ceil(totalRowCount / pageSize) : 1;
74
+ const isOutOfBounds: boolean = pageIndex < 0 || pageIndex >= totalPages;
75
+
76
+ if (isOutOfBounds) {
77
+ table.setPageIndex(totalPages - 1);
78
+ }
79
+ }, [totalRowCount, enablePagination, isLoading, showSkeletons]);
80
+
81
+ //turn off sort when global filter is looking for ranked results
82
+ const appliedSort = useRef<MRT_SortingState>(sorting);
83
+ useEffect(() => {
84
+ if (sorting.length) {
85
+ appliedSort.current = sorting;
86
+ }
87
+ }, [sorting]);
88
+
89
+ useEffect(() => {
90
+ if (!getCanRankRows(table)) return;
91
+ if (globalFilter) {
92
+ table.setSorting([]);
93
+ } else {
94
+ table.setSorting(() => appliedSort.current || []);
95
+ }
96
+ }, [globalFilter]);
97
+
98
+ //fix pinned row top style when density changes
99
+ useEffect(() => {
100
+ if (enableRowPinning && getIsSomeRowsPinned()) {
101
+ setTimeout(() => {
102
+ rerender();
103
+ }, 150);
104
+ }
105
+ }, [density]);
106
+ };
@@ -0,0 +1,88 @@
1
+ import { useCallback, useMemo } from 'react';
2
+ import { type Range, useVirtualizer } from '@tanstack/react-virtual';
3
+ import {
4
+ type MRT_Row,
5
+ type MRT_RowData,
6
+ type MRT_RowVirtualizer,
7
+ type MRT_TableInstance,
8
+ } from '../types';
9
+ import { parseFromValuesOrFunc } from '../utils/utils';
10
+ import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
11
+
12
+ export const useMRT_RowVirtualizer = <
13
+ TData extends MRT_RowData,
14
+ TScrollElement extends Element | Window = HTMLDivElement,
15
+ TItemElement extends Element = HTMLTableRowElement,
16
+ >(
17
+ table: MRT_TableInstance<TData>,
18
+ rows?: MRT_Row<TData>[],
19
+ ): MRT_RowVirtualizer<TScrollElement, TItemElement> | undefined => {
20
+ const {
21
+ getRowModel,
22
+ getState,
23
+ options: {
24
+ enableRowVirtualization,
25
+ renderDetailPanel,
26
+ rowVirtualizerInstanceRef,
27
+ rowVirtualizerOptions,
28
+ },
29
+ refs: { tableContainerRef },
30
+ } = table;
31
+ const { density, draggingRow, expanded } = getState();
32
+
33
+ if (!enableRowVirtualization) return undefined;
34
+
35
+ const rowVirtualizerProps = parseFromValuesOrFunc(rowVirtualizerOptions, {
36
+ table,
37
+ });
38
+
39
+ const realRows = rows ?? getRowModel().rows;
40
+ /**
41
+ * when filtering, should find the correct index in filtered rows
42
+ */
43
+ const draggingRowIndex = useMemo(
44
+ () =>
45
+ draggingRow?.id
46
+ ? realRows.findIndex((r) => r.id === draggingRow?.id)
47
+ : undefined,
48
+ [realRows, draggingRow?.id],
49
+ );
50
+
51
+ const rowCount = realRows.length;
52
+
53
+ const normalRowHeight =
54
+ density === 'compact' ? 37 : density === 'comfortable' ? 58 : 73;
55
+
56
+ const rowVirtualizer = useVirtualizer({
57
+ count: renderDetailPanel ? rowCount * 2 : rowCount,
58
+ estimateSize: (index) =>
59
+ renderDetailPanel && index % 2 === 1
60
+ ? expanded === true
61
+ ? 100
62
+ : 0
63
+ : normalRowHeight,
64
+ getScrollElement: () => tableContainerRef.current,
65
+ measureElement:
66
+ typeof window !== 'undefined' &&
67
+ navigator.userAgent.indexOf('Firefox') === -1
68
+ ? (element) => element?.getBoundingClientRect().height
69
+ : undefined,
70
+ overscan: 4,
71
+ rangeExtractor: useCallback(
72
+ (range: Range) => {
73
+ return extraIndexRangeExtractor(range, draggingRowIndex);
74
+ },
75
+ [draggingRowIndex],
76
+ ),
77
+ ...rowVirtualizerProps,
78
+ }) as unknown as MRT_RowVirtualizer<TScrollElement, TItemElement>;
79
+
80
+ rowVirtualizer.virtualRows = rowVirtualizer.getVirtualItems() as any;
81
+
82
+ if (rowVirtualizerInstanceRef) {
83
+ //@ts-expect-error
84
+ rowVirtualizerInstanceRef.current = rowVirtualizer;
85
+ }
86
+
87
+ return rowVirtualizer;
88
+ };
@@ -0,0 +1,44 @@
1
+ import { useMemo } from 'react';
2
+ import {
3
+ type MRT_Row,
4
+ type MRT_RowData,
5
+ type MRT_TableInstance,
6
+ } from '../types';
7
+ import { getMRT_Rows } from '../utils/row.utils';
8
+
9
+ export const useMRT_Rows = <TData extends MRT_RowData>(
10
+ table: MRT_TableInstance<TData>,
11
+ ): MRT_Row<TData>[] => {
12
+ const {
13
+ getRowModel,
14
+ getState,
15
+ options: { data, enableGlobalFilterRankedResults, positionCreatingRow },
16
+ } = table;
17
+ const {
18
+ creatingRow,
19
+ expanded,
20
+ globalFilter,
21
+ pagination,
22
+ rowPinning,
23
+ sorting,
24
+ } = getState();
25
+
26
+ const rows = useMemo(
27
+ () => getMRT_Rows(table),
28
+ [
29
+ creatingRow,
30
+ data,
31
+ enableGlobalFilterRankedResults,
32
+ expanded,
33
+ getRowModel().rows,
34
+ globalFilter,
35
+ pagination.pageIndex,
36
+ pagination.pageSize,
37
+ positionCreatingRow,
38
+ rowPinning,
39
+ sorting,
40
+ ],
41
+ );
42
+
43
+ return rows;
44
+ };