@careharmony/mantine-react-table-ng 0.0.0-stage → 4.0.0-beta.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.
- package/LICENSE +21 -0
- package/README.md +217 -3
- package/dist/index.cjs +4023 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1488 -0
- package/dist/index.esm.d.mts +1488 -0
- package/dist/index.esm.mjs +3909 -0
- package/dist/index.esm.mjs.map +1 -0
- package/locales/ar/index.cjs +97 -0
- package/locales/ar/index.d.cts +3 -0
- package/locales/ar/index.esm.d.mts +3 -0
- package/locales/ar/index.esm.mjs +95 -0
- package/locales/ar/package.json +19 -0
- package/locales/az/index.cjs +97 -0
- package/locales/az/index.d.cts +3 -0
- package/locales/az/index.esm.d.mts +3 -0
- package/locales/az/index.esm.mjs +95 -0
- package/locales/az/package.json +19 -0
- package/locales/bg/index.cjs +97 -0
- package/locales/bg/index.d.cts +3 -0
- package/locales/bg/index.esm.d.mts +3 -0
- package/locales/bg/index.esm.mjs +95 -0
- package/locales/bg/package.json +19 -0
- package/locales/cs/index.cjs +97 -0
- package/locales/cs/index.d.cts +3 -0
- package/locales/cs/index.esm.d.mts +3 -0
- package/locales/cs/index.esm.mjs +95 -0
- package/locales/cs/package.json +19 -0
- package/locales/da/index.cjs +97 -0
- package/locales/da/index.d.cts +3 -0
- package/locales/da/index.esm.d.mts +3 -0
- package/locales/da/index.esm.mjs +95 -0
- package/locales/da/package.json +19 -0
- package/locales/de/index.cjs +97 -0
- package/locales/de/index.d.cts +3 -0
- package/locales/de/index.esm.d.mts +3 -0
- package/locales/de/index.esm.mjs +95 -0
- package/locales/de/package.json +19 -0
- package/locales/el/index.cjs +97 -0
- package/locales/el/index.d.cts +3 -0
- package/locales/el/index.esm.d.mts +3 -0
- package/locales/el/index.esm.mjs +95 -0
- package/locales/el/package.json +19 -0
- package/locales/en/index.cjs +97 -0
- package/locales/en/index.d.cts +3 -0
- package/locales/en/index.esm.d.mts +3 -0
- package/locales/en/index.esm.mjs +95 -0
- package/locales/en/package.json +19 -0
- package/locales/es/index.cjs +97 -0
- package/locales/es/index.d.cts +3 -0
- package/locales/es/index.esm.d.mts +3 -0
- package/locales/es/index.esm.mjs +95 -0
- package/locales/es/package.json +19 -0
- package/locales/et/index.cjs +97 -0
- package/locales/et/index.d.cts +3 -0
- package/locales/et/index.esm.d.mts +3 -0
- package/locales/et/index.esm.mjs +95 -0
- package/locales/et/package.json +19 -0
- package/locales/fa/index.cjs +97 -0
- package/locales/fa/index.d.cts +3 -0
- package/locales/fa/index.esm.d.mts +3 -0
- package/locales/fa/index.esm.mjs +95 -0
- package/locales/fa/package.json +19 -0
- package/locales/fi/index.cjs +97 -0
- package/locales/fi/index.d.cts +3 -0
- package/locales/fi/index.esm.d.mts +3 -0
- package/locales/fi/index.esm.mjs +95 -0
- package/locales/fi/package.json +19 -0
- package/locales/fr/index.cjs +97 -0
- package/locales/fr/index.d.cts +3 -0
- package/locales/fr/index.esm.d.mts +3 -0
- package/locales/fr/index.esm.mjs +95 -0
- package/locales/fr/package.json +19 -0
- package/locales/he/index.cjs +97 -0
- package/locales/he/index.d.cts +3 -0
- package/locales/he/index.esm.d.mts +3 -0
- package/locales/he/index.esm.mjs +95 -0
- package/locales/he/package.json +19 -0
- package/locales/hr/index.cjs +97 -0
- package/locales/hr/index.d.cts +3 -0
- package/locales/hr/index.esm.d.mts +3 -0
- package/locales/hr/index.esm.mjs +95 -0
- package/locales/hr/package.json +19 -0
- package/locales/hu/index.cjs +97 -0
- package/locales/hu/index.d.cts +3 -0
- package/locales/hu/index.esm.d.mts +3 -0
- package/locales/hu/index.esm.mjs +95 -0
- package/locales/hu/package.json +19 -0
- package/locales/hy/index.cjs +97 -0
- package/locales/hy/index.d.cts +3 -0
- package/locales/hy/index.esm.d.mts +3 -0
- package/locales/hy/index.esm.mjs +95 -0
- package/locales/hy/package.json +19 -0
- package/locales/id/index.cjs +97 -0
- package/locales/id/index.d.cts +3 -0
- package/locales/id/index.esm.d.mts +3 -0
- package/locales/id/index.esm.mjs +95 -0
- package/locales/id/package.json +19 -0
- package/locales/it/index.cjs +97 -0
- package/locales/it/index.d.cts +3 -0
- package/locales/it/index.esm.d.mts +3 -0
- package/locales/it/index.esm.mjs +95 -0
- package/locales/it/package.json +19 -0
- package/locales/ja/index.cjs +97 -0
- package/locales/ja/index.d.cts +3 -0
- package/locales/ja/index.esm.d.mts +3 -0
- package/locales/ja/index.esm.mjs +95 -0
- package/locales/ja/package.json +19 -0
- package/locales/ko/index.cjs +97 -0
- package/locales/ko/index.d.cts +3 -0
- package/locales/ko/index.esm.d.mts +3 -0
- package/locales/ko/index.esm.mjs +95 -0
- package/locales/ko/package.json +19 -0
- package/locales/nl/index.cjs +97 -0
- package/locales/nl/index.d.cts +3 -0
- package/locales/nl/index.esm.d.mts +3 -0
- package/locales/nl/index.esm.mjs +95 -0
- package/locales/nl/package.json +19 -0
- package/locales/no/index.cjs +97 -0
- package/locales/no/index.d.cts +3 -0
- package/locales/no/index.esm.d.mts +3 -0
- package/locales/no/index.esm.mjs +95 -0
- package/locales/no/package.json +19 -0
- package/locales/np/index.cjs +97 -0
- package/locales/np/index.d.cts +3 -0
- package/locales/np/index.esm.d.mts +3 -0
- package/locales/np/index.esm.mjs +95 -0
- package/locales/np/package.json +19 -0
- package/locales/pl/index.cjs +97 -0
- package/locales/pl/index.d.cts +3 -0
- package/locales/pl/index.esm.d.mts +3 -0
- package/locales/pl/index.esm.mjs +95 -0
- package/locales/pl/package.json +19 -0
- package/locales/pt/index.cjs +97 -0
- package/locales/pt/index.d.cts +3 -0
- package/locales/pt/index.esm.d.mts +3 -0
- package/locales/pt/index.esm.mjs +95 -0
- package/locales/pt/package.json +19 -0
- package/locales/pt-BR/index.cjs +97 -0
- package/locales/pt-BR/index.d.cts +3 -0
- package/locales/pt-BR/index.esm.d.mts +3 -0
- package/locales/pt-BR/index.esm.mjs +95 -0
- package/locales/pt-BR/package.json +19 -0
- package/locales/ro/index.cjs +97 -0
- package/locales/ro/index.d.cts +3 -0
- package/locales/ro/index.esm.d.mts +3 -0
- package/locales/ro/index.esm.mjs +95 -0
- package/locales/ro/package.json +19 -0
- package/locales/ru/index.cjs +97 -0
- package/locales/ru/index.d.cts +3 -0
- package/locales/ru/index.esm.d.mts +3 -0
- package/locales/ru/index.esm.mjs +95 -0
- package/locales/ru/package.json +19 -0
- package/locales/sk/index.cjs +97 -0
- package/locales/sk/index.d.cts +3 -0
- package/locales/sk/index.esm.d.mts +3 -0
- package/locales/sk/index.esm.mjs +95 -0
- package/locales/sk/package.json +19 -0
- package/locales/sr-Cyrl-RS/index.cjs +97 -0
- package/locales/sr-Cyrl-RS/index.d.cts +3 -0
- package/locales/sr-Cyrl-RS/index.esm.d.mts +3 -0
- package/locales/sr-Cyrl-RS/index.esm.mjs +95 -0
- package/locales/sr-Cyrl-RS/package.json +19 -0
- package/locales/sr-Latn-RS/index.cjs +97 -0
- package/locales/sr-Latn-RS/index.d.cts +3 -0
- package/locales/sr-Latn-RS/index.esm.d.mts +3 -0
- package/locales/sr-Latn-RS/index.esm.mjs +95 -0
- package/locales/sr-Latn-RS/package.json +19 -0
- package/locales/sv/index.cjs +97 -0
- package/locales/sv/index.d.cts +3 -0
- package/locales/sv/index.esm.d.mts +3 -0
- package/locales/sv/index.esm.mjs +95 -0
- package/locales/sv/package.json +19 -0
- package/locales/th/index.cjs +97 -0
- package/locales/th/index.d.cts +3 -0
- package/locales/th/index.esm.d.mts +3 -0
- package/locales/th/index.esm.mjs +95 -0
- package/locales/th/package.json +19 -0
- package/locales/tr/index.cjs +97 -0
- package/locales/tr/index.d.cts +3 -0
- package/locales/tr/index.esm.d.mts +3 -0
- package/locales/tr/index.esm.mjs +95 -0
- package/locales/tr/package.json +19 -0
- package/locales/uk/index.cjs +97 -0
- package/locales/uk/index.d.cts +3 -0
- package/locales/uk/index.esm.d.mts +3 -0
- package/locales/uk/index.esm.mjs +95 -0
- package/locales/uk/package.json +19 -0
- package/locales/vi/index.cjs +97 -0
- package/locales/vi/index.d.cts +3 -0
- package/locales/vi/index.esm.d.mts +3 -0
- package/locales/vi/index.esm.mjs +95 -0
- package/locales/vi/package.json +19 -0
- package/locales/zh-Hans/index.cjs +97 -0
- package/locales/zh-Hans/index.d.cts +3 -0
- package/locales/zh-Hans/index.esm.d.mts +3 -0
- package/locales/zh-Hans/index.esm.mjs +95 -0
- package/locales/zh-Hans/package.json +19 -0
- package/locales/zh-Hant/index.cjs +97 -0
- package/locales/zh-Hant/index.d.cts +3 -0
- package/locales/zh-Hant/index.esm.d.mts +3 -0
- package/locales/zh-Hant/index.esm.mjs +95 -0
- package/locales/zh-Hant/package.json +19 -0
- package/package.json +184 -4
- package/src/components/MantineReactTable.tsx +38 -0
- package/src/components/body/MRT_TableBody.module.css +42 -0
- package/src/components/body/MRT_TableBody.tsx +214 -0
- package/src/components/body/MRT_TableBodyCell.module.css +107 -0
- package/src/components/body/MRT_TableBodyCell.tsx +355 -0
- package/src/components/body/MRT_TableBodyCellValue.tsx +114 -0
- package/src/components/body/MRT_TableBodyEmptyRow.tsx +89 -0
- package/src/components/body/MRT_TableBodyRow.module.css +261 -0
- package/src/components/body/MRT_TableBodyRow.tsx +278 -0
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +59 -0
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +59 -0
- package/src/components/body/MRT_TableDetailPanel.module.css +35 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +132 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.module.css +11 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +69 -0
- package/src/components/buttons/MRT_CopyButton.module.css +27 -0
- package/src/components/buttons/MRT_CopyButton.tsx +84 -0
- package/src/components/buttons/MRT_EditActionButtons.module.css +4 -0
- package/src/components/buttons/MRT_EditActionButtons.tsx +139 -0
- package/src/components/buttons/MRT_ExpandAllButton.module.css +26 -0
- package/src/components/buttons/MRT_ExpandAllButton.tsx +84 -0
- package/src/components/buttons/MRT_ExpandButton.module.css +37 -0
- package/src/components/buttons/MRT_ExpandButton.tsx +121 -0
- package/src/components/buttons/MRT_GrabHandleButton.module.css +6 -0
- package/src/components/buttons/MRT_GrabHandleButton.tsx +65 -0
- package/src/components/buttons/MRT_RowPinButton.tsx +84 -0
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +46 -0
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +66 -0
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +45 -0
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +59 -0
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +52 -0
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +87 -0
- package/src/components/footer/MRT_TableFooter.module.css +17 -0
- package/src/components/footer/MRT_TableFooter.tsx +70 -0
- package/src/components/footer/MRT_TableFooterCell.module.css +59 -0
- package/src/components/footer/MRT_TableFooterCell.tsx +126 -0
- package/src/components/footer/MRT_TableFooterRow.module.css +10 -0
- package/src/components/footer/MRT_TableFooterRow.tsx +111 -0
- package/src/components/head/MRT_TableHead.module.css +32 -0
- package/src/components/head/MRT_TableHead.tsx +106 -0
- package/src/components/head/MRT_TableHeadCell.module.css +172 -0
- package/src/components/head/MRT_TableHeadCell.tsx +317 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.module.css +5 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +123 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.module.css +14 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +176 -0
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +82 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.module.css +44 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +68 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.module.css +22 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +90 -0
- package/src/components/head/MRT_TableHeadRow.module.css +12 -0
- package/src/components/head/MRT_TableHeadRow.tsx +105 -0
- package/src/components/inputs/MRT_EditCellTextInput.tsx +214 -0
- package/src/components/inputs/MRT_FilterCheckBox.module.css +4 -0
- package/src/components/inputs/MRT_FilterCheckbox.tsx +80 -0
- package/src/components/inputs/MRT_FilterRangeFields.module.css +5 -0
- package/src/components/inputs/MRT_FilterRangeFields.tsx +36 -0
- package/src/components/inputs/MRT_FilterRangeSlider.module.css +6 -0
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +107 -0
- package/src/components/inputs/MRT_FilterTextInput.module.css +27 -0
- package/src/components/inputs/MRT_FilterTextInput.tsx +418 -0
- package/src/components/inputs/MRT_GlobalFilterTextInput.module.css +11 -0
- package/src/components/inputs/MRT_GlobalFilterTextInput.tsx +142 -0
- package/src/components/inputs/MRT_SelectCheckbox.tsx +138 -0
- package/src/components/menus/MRT_ColumnActionMenu.module.css +7 -0
- package/src/components/menus/MRT_ColumnActionMenu.tsx +288 -0
- package/src/components/menus/MRT_FilterOptionMenu.module.css +6 -0
- package/src/components/menus/MRT_FilterOptionMenu.tsx +279 -0
- package/src/components/menus/MRT_RowActionMenu.tsx +75 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.module.css +10 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +136 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.module.css +35 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +171 -0
- package/src/components/modals/MRT_EditRowModal.tsx +98 -0
- package/src/components/table/MRT_Table.module.css +7 -0
- package/src/components/table/MRT_Table.tsx +155 -0
- package/src/components/table/MRT_TableContainer.module.css +32 -0
- package/src/components/table/MRT_TableContainer.tsx +124 -0
- package/src/components/table/MRT_TablePaper.module.css +88 -0
- package/src/components/table/MRT_TablePaper.tsx +91 -0
- package/src/components/toolbar/MRT_BottomToolbar.module.css +40 -0
- package/src/components/toolbar/MRT_BottomToolbar.tsx +99 -0
- package/src/components/toolbar/MRT_ProgressBar.module.css +10 -0
- package/src/components/toolbar/MRT_ProgressBar.tsx +54 -0
- package/src/components/toolbar/MRT_TablePagination.module.css +20 -0
- package/src/components/toolbar/MRT_TablePagination.tsx +175 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.module.css +37 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +169 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.module.css +23 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +68 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.module.css +6 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +74 -0
- package/src/components/toolbar/MRT_TopToolbar.module.css +24 -0
- package/src/components/toolbar/MRT_TopToolbar.tsx +127 -0
- package/src/components/toolbar/common.styles.module.css +10 -0
- package/src/fns/aggregationFns.ts +3 -0
- package/src/fns/filterFns.ts +243 -0
- package/src/fns/sortingFns.ts +34 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +25 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +32 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +94 -0
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +32 -0
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +26 -0
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +36 -0
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +36 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +135 -0
- package/src/hooks/useMRT_Effects.ts +109 -0
- package/src/hooks/useMRT_RowVirtualizer.ts +101 -0
- package/src/hooks/useMRT_Rows.ts +47 -0
- package/src/hooks/useMRT_TableInstance.ts +320 -0
- package/src/hooks/useMRT_TableOptions.ts +300 -0
- package/src/hooks/useMRT_TableSnapshot.ts +134 -0
- package/src/hooks/useMRT_VirtualizerScrollElement.ts +31 -0
- package/src/hooks/useMantineReactTable.ts +23 -0
- package/src/icons.ts +108 -0
- package/src/index.ts +91 -0
- package/src/locales/ar.ts +96 -0
- package/src/locales/az.ts +96 -0
- package/src/locales/bg.ts +96 -0
- package/src/locales/cs.ts +97 -0
- package/src/locales/da.ts +96 -0
- package/src/locales/de.ts +96 -0
- package/src/locales/el.ts +96 -0
- package/src/locales/en.ts +96 -0
- package/src/locales/es.ts +96 -0
- package/src/locales/et.ts +97 -0
- package/src/locales/fa.ts +96 -0
- package/src/locales/fi.ts +97 -0
- package/src/locales/fr.ts +96 -0
- package/src/locales/he.ts +96 -0
- package/src/locales/hr.ts +96 -0
- package/src/locales/hu.ts +96 -0
- package/src/locales/hy.ts +96 -0
- package/src/locales/id.ts +97 -0
- package/src/locales/it.ts +96 -0
- package/src/locales/ja.ts +96 -0
- package/src/locales/ko.ts +96 -0
- package/src/locales/nl.ts +96 -0
- package/src/locales/no.ts +97 -0
- package/src/locales/np.ts +97 -0
- package/src/locales/pl.ts +96 -0
- package/src/locales/pt-BR.ts +96 -0
- package/src/locales/pt.ts +96 -0
- package/src/locales/ro.ts +96 -0
- package/src/locales/ru.ts +96 -0
- package/src/locales/sk.ts +97 -0
- package/src/locales/sr-Cyrl-RS.ts +96 -0
- package/src/locales/sr-Latn-RS.ts +96 -0
- package/src/locales/sv.ts +96 -0
- package/src/locales/th.ts +97 -0
- package/src/locales/tr.ts +96 -0
- package/src/locales/uk.ts +96 -0
- package/src/locales/vi.ts +96 -0
- package/src/locales/zh-Hans.ts +95 -0
- package/src/locales/zh-Hant.ts +95 -0
- package/src/types.ts +1299 -0
- package/src/typings.d.ts +1 -0
- package/src/utils/column.utils.ts +157 -0
- package/src/utils/displayColumn.utils.ts +153 -0
- package/src/utils/row.utils.ts +263 -0
- package/src/utils/snapshot.utils.ts +97 -0
- package/src/utils/style.utils.ts +32 -0
- package/src/utils/tanstack.helpers.ts +66 -0
- package/src/utils/utils.ts +15 -0
- package/src/utils/virtualization.utils.ts +85 -0
- package/styles.css +1381 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type RankingInfo,
|
|
3
|
+
rankings,
|
|
4
|
+
rankItem,
|
|
5
|
+
} from '@tanstack/match-sorter-utils';
|
|
6
|
+
import { filterFns, type Row } from '@tanstack/react-table';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type MRT_FilterOption,
|
|
10
|
+
type MRT_Localization,
|
|
11
|
+
type MRT_RowData,
|
|
12
|
+
} from '../types';
|
|
13
|
+
|
|
14
|
+
//the multi-select filter input clears itself to an empty array, which must remove the filter like '' does
|
|
15
|
+
const isBlankFilterValue = (val: any) =>
|
|
16
|
+
!val || (Array.isArray(val) && !val.length);
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Mantine 8+ date inputs emit 'YYYY-MM-DD' strings. When the cell value is a
|
|
20
|
+
* Date, the filter value is read as a Date at local midnight, so the two
|
|
21
|
+
* compare as dates and not as text.
|
|
22
|
+
*/
|
|
23
|
+
const getDateFilterValue = (cellValue: unknown, filterValue: unknown) => {
|
|
24
|
+
if (!(cellValue instanceof Date)) return undefined;
|
|
25
|
+
if (filterValue instanceof Date) return filterValue;
|
|
26
|
+
if (typeof filterValue !== 'string' || !filterValue) return undefined;
|
|
27
|
+
const date = new Date(
|
|
28
|
+
filterValue.includes('T') ? filterValue : `${filterValue}T00:00:00`,
|
|
29
|
+
);
|
|
30
|
+
return isNaN(+date) ? undefined : date;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
//a date filter picks a day, so dates compare by their local day and not by time
|
|
34
|
+
const getDay = (date: Date) => new Date(date).setHours(0, 0, 0, 0);
|
|
35
|
+
|
|
36
|
+
const fuzzy = <TData extends MRT_RowData>(
|
|
37
|
+
row: Row<TData>,
|
|
38
|
+
columnId: string,
|
|
39
|
+
filterValue: number | string,
|
|
40
|
+
addMeta: (item: RankingInfo) => void,
|
|
41
|
+
) => {
|
|
42
|
+
const itemRank = rankItem(row.getValue(columnId), filterValue as string, {
|
|
43
|
+
threshold: rankings.MATCHES,
|
|
44
|
+
});
|
|
45
|
+
addMeta(itemRank);
|
|
46
|
+
return itemRank.passed;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
fuzzy.autoRemove = isBlankFilterValue;
|
|
50
|
+
|
|
51
|
+
const contains = <TData extends MRT_RowData>(
|
|
52
|
+
row: Row<TData>,
|
|
53
|
+
id: string,
|
|
54
|
+
filterValue: number | string,
|
|
55
|
+
) =>
|
|
56
|
+
row
|
|
57
|
+
.getValue<number | string>(id)
|
|
58
|
+
?.toString()
|
|
59
|
+
.toLowerCase()
|
|
60
|
+
.trim()
|
|
61
|
+
.includes(filterValue.toString().toLowerCase().trim());
|
|
62
|
+
|
|
63
|
+
contains.autoRemove = isBlankFilterValue;
|
|
64
|
+
|
|
65
|
+
const startsWith = <TData extends MRT_RowData>(
|
|
66
|
+
row: Row<TData>,
|
|
67
|
+
id: string,
|
|
68
|
+
filterValue: number | string,
|
|
69
|
+
) =>
|
|
70
|
+
row
|
|
71
|
+
.getValue<number | string>(id)
|
|
72
|
+
?.toString()
|
|
73
|
+
.toLowerCase()
|
|
74
|
+
.trim()
|
|
75
|
+
.startsWith(filterValue.toString().toLowerCase().trim());
|
|
76
|
+
|
|
77
|
+
startsWith.autoRemove = isBlankFilterValue;
|
|
78
|
+
|
|
79
|
+
const endsWith = <TData extends MRT_RowData>(
|
|
80
|
+
row: Row<TData>,
|
|
81
|
+
id: string,
|
|
82
|
+
filterValue: number | string,
|
|
83
|
+
) =>
|
|
84
|
+
row
|
|
85
|
+
.getValue<number | string>(id)
|
|
86
|
+
?.toString()
|
|
87
|
+
.toLowerCase()
|
|
88
|
+
.trim()
|
|
89
|
+
.endsWith(filterValue.toString().toLowerCase().trim());
|
|
90
|
+
|
|
91
|
+
endsWith.autoRemove = isBlankFilterValue;
|
|
92
|
+
|
|
93
|
+
const equals = <TData extends MRT_RowData>(
|
|
94
|
+
row: Row<TData>,
|
|
95
|
+
id: string,
|
|
96
|
+
filterValue: number | string,
|
|
97
|
+
) => {
|
|
98
|
+
const dateFilterValue = getDateFilterValue(row.getValue(id), filterValue);
|
|
99
|
+
if (dateFilterValue) {
|
|
100
|
+
return getDay(row.getValue<Date>(id)) === getDay(dateFilterValue);
|
|
101
|
+
}
|
|
102
|
+
return (
|
|
103
|
+
row.getValue<number | string>(id)?.toString().toLowerCase().trim() ===
|
|
104
|
+
filterValue?.toString().toLowerCase().trim()
|
|
105
|
+
);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
equals.autoRemove = isBlankFilterValue;
|
|
109
|
+
|
|
110
|
+
const notEquals = <TData extends MRT_RowData>(
|
|
111
|
+
row: Row<TData>,
|
|
112
|
+
id: string,
|
|
113
|
+
filterValue: number | string,
|
|
114
|
+
) => !equals(row, id, filterValue);
|
|
115
|
+
|
|
116
|
+
notEquals.autoRemove = isBlankFilterValue;
|
|
117
|
+
|
|
118
|
+
const greaterThan = <TData extends MRT_RowData>(
|
|
119
|
+
row: Row<TData>,
|
|
120
|
+
id: string,
|
|
121
|
+
rawFilterValue: number | string,
|
|
122
|
+
) => {
|
|
123
|
+
const dateFilterValue = getDateFilterValue(row.getValue(id), rawFilterValue);
|
|
124
|
+
if (dateFilterValue) {
|
|
125
|
+
return getDay(row.getValue<Date>(id)) > getDay(dateFilterValue);
|
|
126
|
+
}
|
|
127
|
+
const filterValue = rawFilterValue;
|
|
128
|
+
return !isNaN(+filterValue) && !isNaN(+row.getValue<number | string>(id))
|
|
129
|
+
? +row.getValue<number | string>(id) > +filterValue
|
|
130
|
+
: row.getValue<number | string>(id)?.toString().toLowerCase().trim() >
|
|
131
|
+
filterValue?.toString().toLowerCase().trim();
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
greaterThan.autoRemove = isBlankFilterValue;
|
|
135
|
+
|
|
136
|
+
const greaterThanOrEqualTo = <TData extends MRT_RowData>(
|
|
137
|
+
row: Row<TData>,
|
|
138
|
+
id: string,
|
|
139
|
+
filterValue: number | string,
|
|
140
|
+
) => equals(row, id, filterValue) || greaterThan(row, id, filterValue);
|
|
141
|
+
|
|
142
|
+
greaterThanOrEqualTo.autoRemove = isBlankFilterValue;
|
|
143
|
+
|
|
144
|
+
const lessThan = <TData extends MRT_RowData>(
|
|
145
|
+
row: Row<TData>,
|
|
146
|
+
id: string,
|
|
147
|
+
rawFilterValue: number | string,
|
|
148
|
+
) => {
|
|
149
|
+
const dateFilterValue = getDateFilterValue(row.getValue(id), rawFilterValue);
|
|
150
|
+
if (dateFilterValue) {
|
|
151
|
+
return getDay(row.getValue<Date>(id)) < getDay(dateFilterValue);
|
|
152
|
+
}
|
|
153
|
+
const filterValue = rawFilterValue;
|
|
154
|
+
return !isNaN(+filterValue) && !isNaN(+row.getValue<number | string>(id))
|
|
155
|
+
? +row.getValue<number | string>(id) < +filterValue
|
|
156
|
+
: row.getValue<number | string>(id)?.toString().toLowerCase().trim() <
|
|
157
|
+
filterValue?.toString().toLowerCase().trim();
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
lessThan.autoRemove = isBlankFilterValue;
|
|
161
|
+
|
|
162
|
+
const lessThanOrEqualTo = <TData extends MRT_RowData>(
|
|
163
|
+
row: Row<TData>,
|
|
164
|
+
id: string,
|
|
165
|
+
filterValue: number | string,
|
|
166
|
+
) => equals(row, id, filterValue) || lessThan(row, id, filterValue);
|
|
167
|
+
|
|
168
|
+
lessThanOrEqualTo.autoRemove = isBlankFilterValue;
|
|
169
|
+
|
|
170
|
+
const between = <TData extends MRT_RowData>(
|
|
171
|
+
row: Row<TData>,
|
|
172
|
+
id: string,
|
|
173
|
+
filterValues: [number | string, number | string],
|
|
174
|
+
) =>
|
|
175
|
+
((['', undefined] as any[]).includes(filterValues[0]) ||
|
|
176
|
+
greaterThan(row, id, filterValues[0])) &&
|
|
177
|
+
((!isNaN(+filterValues[0]) &&
|
|
178
|
+
!isNaN(+filterValues[1]) &&
|
|
179
|
+
+filterValues[0] > +filterValues[1]) ||
|
|
180
|
+
(['', undefined] as any[]).includes(filterValues[1]) ||
|
|
181
|
+
lessThan(row, id, filterValues[1]));
|
|
182
|
+
|
|
183
|
+
between.autoRemove = isBlankFilterValue;
|
|
184
|
+
|
|
185
|
+
const betweenInclusive = <TData extends MRT_RowData>(
|
|
186
|
+
row: Row<TData>,
|
|
187
|
+
id: string,
|
|
188
|
+
filterValues: [number | string, number | string],
|
|
189
|
+
) =>
|
|
190
|
+
((['', undefined] as any[]).includes(filterValues[0]) ||
|
|
191
|
+
greaterThanOrEqualTo(row, id, filterValues[0])) &&
|
|
192
|
+
((!isNaN(+filterValues[0]) &&
|
|
193
|
+
!isNaN(+filterValues[1]) &&
|
|
194
|
+
+filterValues[0] > +filterValues[1]) ||
|
|
195
|
+
(['', undefined] as any[]).includes(filterValues[1]) ||
|
|
196
|
+
lessThanOrEqualTo(row, id, filterValues[1]));
|
|
197
|
+
|
|
198
|
+
betweenInclusive.autoRemove = isBlankFilterValue;
|
|
199
|
+
|
|
200
|
+
const empty = <TData extends MRT_RowData>(
|
|
201
|
+
row: Row<TData>,
|
|
202
|
+
id: string,
|
|
203
|
+
_filterValue: number | string,
|
|
204
|
+
) => !row.getValue<number | string>(id)?.toString().trim();
|
|
205
|
+
|
|
206
|
+
empty.autoRemove = isBlankFilterValue;
|
|
207
|
+
|
|
208
|
+
const notEmpty = <TData extends MRT_RowData>(
|
|
209
|
+
row: Row<TData>,
|
|
210
|
+
id: string,
|
|
211
|
+
_filterValue: number | string,
|
|
212
|
+
) => !!row.getValue<number | string>(id)?.toString().trim();
|
|
213
|
+
|
|
214
|
+
notEmpty.autoRemove = isBlankFilterValue;
|
|
215
|
+
|
|
216
|
+
export const MRT_FilterFns = {
|
|
217
|
+
...filterFns,
|
|
218
|
+
between,
|
|
219
|
+
betweenInclusive,
|
|
220
|
+
contains,
|
|
221
|
+
empty,
|
|
222
|
+
endsWith,
|
|
223
|
+
equals,
|
|
224
|
+
fuzzy,
|
|
225
|
+
greaterThan,
|
|
226
|
+
greaterThanOrEqualTo,
|
|
227
|
+
lessThan,
|
|
228
|
+
lessThanOrEqualTo,
|
|
229
|
+
notEmpty,
|
|
230
|
+
notEquals,
|
|
231
|
+
startsWith,
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
export function localizedFilterOption(
|
|
235
|
+
localization: MRT_Localization,
|
|
236
|
+
option: MRT_FilterOption,
|
|
237
|
+
) {
|
|
238
|
+
if (!option) {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
const key = `filter${option[0].toUpperCase()}${option.slice(1)}`;
|
|
242
|
+
return localization[key as keyof MRT_Localization] ?? '';
|
|
243
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { compareItems, type RankingInfo } from '@tanstack/match-sorter-utils';
|
|
2
|
+
import { type Row, sortingFns } from '@tanstack/react-table';
|
|
3
|
+
|
|
4
|
+
import { type MRT_Row, type MRT_RowData } from '../types';
|
|
5
|
+
|
|
6
|
+
const fuzzy = <TData extends MRT_RowData>(
|
|
7
|
+
rowA: Row<TData>,
|
|
8
|
+
rowB: Row<TData>,
|
|
9
|
+
columnId: string,
|
|
10
|
+
) => {
|
|
11
|
+
let dir = 0;
|
|
12
|
+
if (rowA.columnFiltersMeta[columnId]) {
|
|
13
|
+
dir = compareItems(
|
|
14
|
+
rowA.columnFiltersMeta[columnId] as RankingInfo,
|
|
15
|
+
rowB.columnFiltersMeta[columnId] as RankingInfo,
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
// Provide a fallback for when the item ranks are equal
|
|
19
|
+
return dir === 0
|
|
20
|
+
? sortingFns.alphanumeric(rowA as Row<any>, rowB as Row<any>, columnId)
|
|
21
|
+
: dir;
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const MRT_SortingFns = {
|
|
25
|
+
...sortingFns,
|
|
26
|
+
fuzzy,
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const rankGlobalFuzzy = <TData extends MRT_RowData>(
|
|
30
|
+
rowA: MRT_Row<TData>,
|
|
31
|
+
rowB: MRT_Row<TData>,
|
|
32
|
+
) =>
|
|
33
|
+
Math.max(...Object.values(rowB.columnFiltersMeta).map((v: any) => v.rank)) -
|
|
34
|
+
Math.max(...Object.values(rowA.columnFiltersMeta).map((v: any) => v.rank));
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import { MRT_ToggleRowActionMenuButton } from '../../components/buttons/MRT_ToggleRowActionMenuButton';
|
|
4
|
+
import {
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
type MRT_RowData,
|
|
7
|
+
type MRT_StatefulTableOptions,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
10
|
+
|
|
11
|
+
export const getMRT_RowActionsColumnDef = <TData extends MRT_RowData>(
|
|
12
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
13
|
+
): MRT_ColumnDef<TData> | null => {
|
|
14
|
+
return {
|
|
15
|
+
Cell: ({ cell, row, table }) => (
|
|
16
|
+
<MRT_ToggleRowActionMenuButton cell={cell} row={row} table={table} />
|
|
17
|
+
),
|
|
18
|
+
...defaultDisplayColumnProps({
|
|
19
|
+
header: 'actions',
|
|
20
|
+
id: 'mrt-row-actions',
|
|
21
|
+
size: 70,
|
|
22
|
+
tableOptions,
|
|
23
|
+
}),
|
|
24
|
+
};
|
|
25
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import { type RefObject } from 'react';
|
|
4
|
+
|
|
5
|
+
import { MRT_TableBodyRowGrabHandle } from '../../components/body/MRT_TableBodyRowGrabHandle';
|
|
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
|
+
|
|
13
|
+
export const getMRT_RowDragColumnDef = <TData extends MRT_RowData>(
|
|
14
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
15
|
+
): MRT_ColumnDef<TData> | null => {
|
|
16
|
+
return {
|
|
17
|
+
Cell: ({ row, rowRef, table }) => (
|
|
18
|
+
<MRT_TableBodyRowGrabHandle
|
|
19
|
+
row={row}
|
|
20
|
+
rowRef={rowRef as RefObject<HTMLTableRowElement | null>}
|
|
21
|
+
table={table}
|
|
22
|
+
/>
|
|
23
|
+
),
|
|
24
|
+
grow: false,
|
|
25
|
+
...defaultDisplayColumnProps({
|
|
26
|
+
header: 'move',
|
|
27
|
+
id: 'mrt-row-drag',
|
|
28
|
+
size: 60,
|
|
29
|
+
tableOptions,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import { type ReactNode } from 'react';
|
|
4
|
+
|
|
5
|
+
import { Flex, Tooltip } from '@mantine/core';
|
|
6
|
+
|
|
7
|
+
import { MRT_ExpandAllButton } from '../../components/buttons/MRT_ExpandAllButton';
|
|
8
|
+
import { MRT_ExpandButton } from '../../components/buttons/MRT_ExpandButton';
|
|
9
|
+
import {
|
|
10
|
+
type MRT_ColumnDef,
|
|
11
|
+
type MRT_RowData,
|
|
12
|
+
type MRT_StatefulTableOptions,
|
|
13
|
+
} from '../../types';
|
|
14
|
+
import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
15
|
+
|
|
16
|
+
export const getMRT_RowExpandColumnDef = <TData extends MRT_RowData>(
|
|
17
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
18
|
+
): MRT_ColumnDef<TData> | null => {
|
|
19
|
+
const {
|
|
20
|
+
defaultColumn,
|
|
21
|
+
enableExpandAll,
|
|
22
|
+
groupedColumnMode,
|
|
23
|
+
positionExpandColumn,
|
|
24
|
+
renderDetailPanel,
|
|
25
|
+
state: { grouping },
|
|
26
|
+
} = tableOptions;
|
|
27
|
+
|
|
28
|
+
const alignProps =
|
|
29
|
+
positionExpandColumn === 'last'
|
|
30
|
+
? ({
|
|
31
|
+
align: 'right',
|
|
32
|
+
} as const)
|
|
33
|
+
: undefined;
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
Cell: ({ cell, column, row, table }) => {
|
|
37
|
+
const expandButtonProps = { row, table };
|
|
38
|
+
const subRowsLength = row.subRows?.length;
|
|
39
|
+
if (tableOptions.groupedColumnMode === 'remove' && row.groupingColumnId) {
|
|
40
|
+
return (
|
|
41
|
+
<Flex align="center" gap="0.25rem">
|
|
42
|
+
<MRT_ExpandButton {...expandButtonProps} />
|
|
43
|
+
<Tooltip
|
|
44
|
+
label={table.getColumn(row.groupingColumnId).columnDef.header}
|
|
45
|
+
openDelay={1000}
|
|
46
|
+
position="right"
|
|
47
|
+
>
|
|
48
|
+
<span>{row.groupingValue as ReactNode}</span>
|
|
49
|
+
</Tooltip>
|
|
50
|
+
{!!subRowsLength && <span>({subRowsLength})</span>}
|
|
51
|
+
</Flex>
|
|
52
|
+
);
|
|
53
|
+
} else {
|
|
54
|
+
return (
|
|
55
|
+
<>
|
|
56
|
+
<MRT_ExpandButton {...expandButtonProps} />
|
|
57
|
+
{column.columnDef.GroupedCell?.({ cell, column, row, table })}
|
|
58
|
+
</>
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
Header: enableExpandAll
|
|
63
|
+
? ({ table }) => {
|
|
64
|
+
return (
|
|
65
|
+
<Flex align="center">
|
|
66
|
+
<MRT_ExpandAllButton table={table} />
|
|
67
|
+
{groupedColumnMode === 'remove' &&
|
|
68
|
+
grouping
|
|
69
|
+
?.map(
|
|
70
|
+
(groupedColumnId) =>
|
|
71
|
+
table.getColumn(groupedColumnId).columnDef.header,
|
|
72
|
+
)
|
|
73
|
+
?.join(', ')}
|
|
74
|
+
</Flex>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
: undefined,
|
|
78
|
+
mantineTableBodyCellProps: alignProps,
|
|
79
|
+
mantineTableHeadCellProps: alignProps,
|
|
80
|
+
...defaultDisplayColumnProps({
|
|
81
|
+
header: 'expand',
|
|
82
|
+
id: 'mrt-row-expand',
|
|
83
|
+
size:
|
|
84
|
+
groupedColumnMode === 'remove'
|
|
85
|
+
? (defaultColumn?.size ?? 180)
|
|
86
|
+
: renderDetailPanel
|
|
87
|
+
? enableExpandAll
|
|
88
|
+
? 60
|
|
89
|
+
: 70
|
|
90
|
+
: 100,
|
|
91
|
+
tableOptions,
|
|
92
|
+
}),
|
|
93
|
+
};
|
|
94
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
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_RowNumbersColumnDef = <TData extends MRT_RowData>(
|
|
11
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
12
|
+
): MRT_ColumnDef<TData> | null => {
|
|
13
|
+
const { localization, rowNumberDisplayMode } = tableOptions;
|
|
14
|
+
const {
|
|
15
|
+
pagination: { pageIndex, pageSize },
|
|
16
|
+
} = tableOptions.state;
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
Cell: ({ renderedRowIndex = 0, row }) =>
|
|
20
|
+
((rowNumberDisplayMode === 'static'
|
|
21
|
+
? renderedRowIndex + pageSize * pageIndex
|
|
22
|
+
: row.index) ?? 0) + 1,
|
|
23
|
+
grow: false,
|
|
24
|
+
Header: () => localization.rowNumber,
|
|
25
|
+
...defaultDisplayColumnProps({
|
|
26
|
+
header: 'rowNumbers',
|
|
27
|
+
id: 'mrt-row-numbers',
|
|
28
|
+
size: 50,
|
|
29
|
+
tableOptions,
|
|
30
|
+
}),
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import { MRT_TableBodyRowPinButton } from '../../components/body/MRT_TableBodyRowPinButton';
|
|
4
|
+
import {
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
type MRT_RowData,
|
|
7
|
+
type MRT_StatefulTableOptions,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
10
|
+
|
|
11
|
+
export const getMRT_RowPinningColumnDef = <TData extends MRT_RowData>(
|
|
12
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
13
|
+
): MRT_ColumnDef<TData> | null => {
|
|
14
|
+
return {
|
|
15
|
+
Cell: ({ row, table }) => (
|
|
16
|
+
<MRT_TableBodyRowPinButton row={row} table={table} />
|
|
17
|
+
),
|
|
18
|
+
grow: false,
|
|
19
|
+
...defaultDisplayColumnProps({
|
|
20
|
+
header: 'pin',
|
|
21
|
+
id: 'mrt-row-pin',
|
|
22
|
+
size: 60,
|
|
23
|
+
tableOptions,
|
|
24
|
+
}),
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import { MRT_SelectCheckbox } from '../../components/inputs/MRT_SelectCheckbox';
|
|
4
|
+
import {
|
|
5
|
+
type MRT_ColumnDef,
|
|
6
|
+
type MRT_RowData,
|
|
7
|
+
type MRT_StatefulTableOptions,
|
|
8
|
+
} from '../../types';
|
|
9
|
+
import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
10
|
+
|
|
11
|
+
export const getMRT_RowSelectColumnDef = <TData extends MRT_RowData>(
|
|
12
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
13
|
+
): MRT_ColumnDef<TData> | null => {
|
|
14
|
+
const { enableMultiRowSelection, enableSelectAll } = tableOptions;
|
|
15
|
+
|
|
16
|
+
return {
|
|
17
|
+
Cell: ({ renderedRowIndex, row, table }) => (
|
|
18
|
+
<MRT_SelectCheckbox
|
|
19
|
+
renderedRowIndex={renderedRowIndex}
|
|
20
|
+
row={row}
|
|
21
|
+
table={table}
|
|
22
|
+
/>
|
|
23
|
+
),
|
|
24
|
+
grow: false,
|
|
25
|
+
Header:
|
|
26
|
+
enableSelectAll && enableMultiRowSelection
|
|
27
|
+
? ({ table }) => <MRT_SelectCheckbox table={table} />
|
|
28
|
+
: undefined,
|
|
29
|
+
...defaultDisplayColumnProps({
|
|
30
|
+
header: 'select',
|
|
31
|
+
id: 'mrt-row-select',
|
|
32
|
+
size: enableSelectAll ? 60 : 70,
|
|
33
|
+
tableOptions,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
|
|
3
|
+
import { MRT_DefaultDisplayColumn } from '../useMRT_TableOptions';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type MRT_ColumnDef,
|
|
7
|
+
type MRT_RowData,
|
|
8
|
+
type MRT_StatefulTableOptions,
|
|
9
|
+
} from '../../types';
|
|
10
|
+
import { defaultDisplayColumnProps } from '../../utils/displayColumn.utils';
|
|
11
|
+
|
|
12
|
+
const blankColProps = {
|
|
13
|
+
children: null,
|
|
14
|
+
style: {
|
|
15
|
+
minWidth: 0,
|
|
16
|
+
padding: 0,
|
|
17
|
+
width: 0,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const getMRT_RowSpacerColumnDef = <TData extends MRT_RowData>(
|
|
22
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
23
|
+
): MRT_ColumnDef<TData> | null => {
|
|
24
|
+
return {
|
|
25
|
+
...defaultDisplayColumnProps({
|
|
26
|
+
id: 'mrt-row-spacer',
|
|
27
|
+
size: 0,
|
|
28
|
+
tableOptions,
|
|
29
|
+
}),
|
|
30
|
+
grow: true,
|
|
31
|
+
...MRT_DefaultDisplayColumn,
|
|
32
|
+
mantineTableBodyCellProps: blankColProps,
|
|
33
|
+
mantineTableFooterCellProps: blankColProps,
|
|
34
|
+
mantineTableHeadCellProps: blankColProps,
|
|
35
|
+
};
|
|
36
|
+
};
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use no memo';
|
|
2
|
+
/* eslint-disable react-hooks/rules-of-hooks -- useMRT_TableOptions fixes the virtualization flags at initialization, so the early return never changes the hook order */
|
|
3
|
+
|
|
4
|
+
import { useCallback, useMemo } from 'react';
|
|
5
|
+
|
|
6
|
+
import { type Range, useVirtualizer } from '@tanstack/react-virtual';
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
type MRT_ColumnVirtualizer,
|
|
10
|
+
type MRT_RowData,
|
|
11
|
+
type MRT_TableInstance,
|
|
12
|
+
} from '../types';
|
|
13
|
+
import { parseFromValuesOrFunc } from '../utils/utils';
|
|
14
|
+
import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
|
|
15
|
+
import { useMRT_VirtualizerScrollElement } from './useMRT_VirtualizerScrollElement';
|
|
16
|
+
|
|
17
|
+
export const useMRT_ColumnVirtualizer = <
|
|
18
|
+
TData extends MRT_RowData,
|
|
19
|
+
TScrollElement extends Element | Window = HTMLDivElement,
|
|
20
|
+
TItemElement extends Element = HTMLTableCellElement,
|
|
21
|
+
>(
|
|
22
|
+
table: MRT_TableInstance<TData>,
|
|
23
|
+
): MRT_ColumnVirtualizer | undefined => {
|
|
24
|
+
const {
|
|
25
|
+
getLeftLeafColumns,
|
|
26
|
+
getRightLeafColumns,
|
|
27
|
+
getState,
|
|
28
|
+
getVisibleLeafColumns,
|
|
29
|
+
options: {
|
|
30
|
+
columnVirtualizerInstanceRef,
|
|
31
|
+
columnVirtualizerOptions,
|
|
32
|
+
enableColumnPinning,
|
|
33
|
+
enableColumnVirtualization,
|
|
34
|
+
},
|
|
35
|
+
refs: { scrollAreaViewportRef, tableContainerRef },
|
|
36
|
+
} = table;
|
|
37
|
+
const { columnPinning, draggingColumn } = getState();
|
|
38
|
+
|
|
39
|
+
if (!enableColumnVirtualization) return undefined;
|
|
40
|
+
|
|
41
|
+
const columnVirtualizerProps = parseFromValuesOrFunc(
|
|
42
|
+
columnVirtualizerOptions,
|
|
43
|
+
{
|
|
44
|
+
table,
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const visibleColumns = getVisibleLeafColumns();
|
|
49
|
+
|
|
50
|
+
const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(
|
|
51
|
+
() =>
|
|
52
|
+
enableColumnPinning
|
|
53
|
+
? [
|
|
54
|
+
getLeftLeafColumns().map((c) => c.getPinnedIndex()),
|
|
55
|
+
getRightLeafColumns()
|
|
56
|
+
.map(
|
|
57
|
+
(column) => visibleColumns.length - column.getPinnedIndex() - 1,
|
|
58
|
+
)
|
|
59
|
+
.sort((a, b) => a - b),
|
|
60
|
+
]
|
|
61
|
+
: [[], []],
|
|
62
|
+
[visibleColumns.length, columnPinning, enableColumnPinning],
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const numPinnedLeft = leftPinnedIndexes.length;
|
|
66
|
+
const numPinnedRight = rightPinnedIndexes.length;
|
|
67
|
+
|
|
68
|
+
const draggingColumnIndex = useMemo(
|
|
69
|
+
() =>
|
|
70
|
+
draggingColumn?.id
|
|
71
|
+
? visibleColumns.findIndex((c) => c.id === draggingColumn?.id)
|
|
72
|
+
: undefined,
|
|
73
|
+
[draggingColumn?.id],
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
const columnVirtualizer = useVirtualizer({
|
|
77
|
+
count: visibleColumns.length,
|
|
78
|
+
estimateSize: (index) => visibleColumns[index].getSize(),
|
|
79
|
+
getScrollElement: () =>
|
|
80
|
+
scrollAreaViewportRef.current ?? tableContainerRef.current,
|
|
81
|
+
horizontal: true,
|
|
82
|
+
overscan: 3,
|
|
83
|
+
rangeExtractor: useCallback(
|
|
84
|
+
(range: Range) => {
|
|
85
|
+
const newIndexes = extraIndexRangeExtractor(range, draggingColumnIndex);
|
|
86
|
+
if (!numPinnedLeft && !numPinnedRight) {
|
|
87
|
+
return newIndexes;
|
|
88
|
+
}
|
|
89
|
+
return [
|
|
90
|
+
...new Set([
|
|
91
|
+
...leftPinnedIndexes,
|
|
92
|
+
...newIndexes,
|
|
93
|
+
...rightPinnedIndexes,
|
|
94
|
+
]),
|
|
95
|
+
];
|
|
96
|
+
},
|
|
97
|
+
[leftPinnedIndexes, rightPinnedIndexes, draggingColumnIndex],
|
|
98
|
+
),
|
|
99
|
+
...columnVirtualizerProps,
|
|
100
|
+
}) as unknown as MRT_ColumnVirtualizer<TScrollElement, TItemElement>;
|
|
101
|
+
|
|
102
|
+
useMRT_VirtualizerScrollElement(columnVirtualizer);
|
|
103
|
+
|
|
104
|
+
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
105
|
+
columnVirtualizer.virtualColumns = virtualColumns as any;
|
|
106
|
+
const numColumns = virtualColumns.length;
|
|
107
|
+
|
|
108
|
+
if (numColumns) {
|
|
109
|
+
const totalSize = columnVirtualizer.getTotalSize();
|
|
110
|
+
|
|
111
|
+
const leftNonPinnedStart = virtualColumns[numPinnedLeft]?.start || 0;
|
|
112
|
+
const leftNonPinnedEnd =
|
|
113
|
+
virtualColumns[leftPinnedIndexes.length - 1]?.end || 0;
|
|
114
|
+
|
|
115
|
+
const rightNonPinnedStart =
|
|
116
|
+
virtualColumns[numColumns - numPinnedRight]?.start || 0;
|
|
117
|
+
const rightNonPinnedEnd =
|
|
118
|
+
virtualColumns[numColumns - numPinnedRight - 1]?.end || 0;
|
|
119
|
+
|
|
120
|
+
columnVirtualizer.virtualPaddingLeft =
|
|
121
|
+
leftNonPinnedStart - leftNonPinnedEnd;
|
|
122
|
+
|
|
123
|
+
columnVirtualizer.virtualPaddingRight =
|
|
124
|
+
totalSize -
|
|
125
|
+
rightNonPinnedEnd -
|
|
126
|
+
(numPinnedRight ? totalSize - rightNonPinnedStart : 0);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (columnVirtualizerInstanceRef) {
|
|
130
|
+
//@ts-ignore
|
|
131
|
+
columnVirtualizerInstanceRef.current = columnVirtualizer;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return columnVirtualizer as any;
|
|
135
|
+
};
|