@kissesses/mantine-react-table-open 9.0.3
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 +196 -0
- package/dist/index.cjs +3769 -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 +3664 -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/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 +154 -0
- package/src/components/MantineReactTable.tsx +37 -0
- package/src/components/body/MRT_TableBody.module.css +42 -0
- package/src/components/body/MRT_TableBody.tsx +215 -0
- package/src/components/body/MRT_TableBodyCell.module.css +107 -0
- package/src/components/body/MRT_TableBodyCell.tsx +351 -0
- package/src/components/body/MRT_TableBodyCellValue.tsx +113 -0
- package/src/components/body/MRT_TableBodyEmptyRow.tsx +110 -0
- package/src/components/body/MRT_TableBodyRow.module.css +252 -0
- package/src/components/body/MRT_TableBodyRow.tsx +263 -0
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +58 -0
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +58 -0
- package/src/components/body/MRT_TableDetailPanel.module.css +35 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +131 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.module.css +11 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +68 -0
- package/src/components/buttons/MRT_CopyButton.module.css +27 -0
- package/src/components/buttons/MRT_CopyButton.tsx +83 -0
- package/src/components/buttons/MRT_EditActionButtons.module.css +4 -0
- package/src/components/buttons/MRT_EditActionButtons.tsx +128 -0
- package/src/components/buttons/MRT_ExpandAllButton.module.css +26 -0
- package/src/components/buttons/MRT_ExpandAllButton.tsx +83 -0
- package/src/components/buttons/MRT_ExpandButton.module.css +37 -0
- package/src/components/buttons/MRT_ExpandButton.tsx +120 -0
- package/src/components/buttons/MRT_GrabHandleButton.module.css +6 -0
- package/src/components/buttons/MRT_GrabHandleButton.tsx +64 -0
- package/src/components/buttons/MRT_RowPinButton.tsx +83 -0
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +45 -0
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +65 -0
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +44 -0
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +58 -0
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +51 -0
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +86 -0
- package/src/components/footer/MRT_TableFooter.module.css +17 -0
- package/src/components/footer/MRT_TableFooter.tsx +72 -0
- package/src/components/footer/MRT_TableFooterCell.module.css +50 -0
- package/src/components/footer/MRT_TableFooterCell.tsx +122 -0
- package/src/components/footer/MRT_TableFooterRow.module.css +10 -0
- package/src/components/footer/MRT_TableFooterRow.tsx +94 -0
- package/src/components/head/MRT_TableHead.module.css +32 -0
- package/src/components/head/MRT_TableHead.tsx +108 -0
- package/src/components/head/MRT_TableHeadCell.module.css +163 -0
- package/src/components/head/MRT_TableHeadCell.tsx +322 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.module.css +5 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +147 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.module.css +14 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +171 -0
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +81 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.module.css +44 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +67 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.module.css +22 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +89 -0
- package/src/components/head/MRT_TableHeadRow.module.css +12 -0
- package/src/components/head/MRT_TableHeadRow.tsx +87 -0
- package/src/components/inputs/MRT_EditCellTextInput.tsx +218 -0
- package/src/components/inputs/MRT_FilterCheckBox.module.css +4 -0
- package/src/components/inputs/MRT_FilterCheckbox.tsx +79 -0
- package/src/components/inputs/MRT_FilterRangeFields.module.css +5 -0
- package/src/components/inputs/MRT_FilterRangeFields.tsx +35 -0
- package/src/components/inputs/MRT_FilterRangeSlider.module.css +6 -0
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +106 -0
- package/src/components/inputs/MRT_FilterTextInput.module.css +27 -0
- package/src/components/inputs/MRT_FilterTextInput.tsx +417 -0
- package/src/components/inputs/MRT_GlobalFilterTextInput.module.css +11 -0
- package/src/components/inputs/MRT_GlobalFilterTextInput.tsx +141 -0
- package/src/components/inputs/MRT_SelectCheckbox.tsx +137 -0
- package/src/components/menus/MRT_ColumnActionMenu.module.css +7 -0
- package/src/components/menus/MRT_ColumnActionMenu.tsx +287 -0
- package/src/components/menus/MRT_FilterOptionMenu.module.css +6 -0
- package/src/components/menus/MRT_FilterOptionMenu.tsx +274 -0
- package/src/components/menus/MRT_RowActionMenu.tsx +74 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.module.css +10 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +135 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.module.css +35 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +170 -0
- package/src/components/modals/MRT_EditRowModal.tsx +97 -0
- package/src/components/table/MRT_Table.module.css +7 -0
- package/src/components/table/MRT_Table.tsx +110 -0
- package/src/components/table/MRT_TableContainer.module.css +20 -0
- package/src/components/table/MRT_TableContainer.tsx +109 -0
- package/src/components/table/MRT_TablePaper.module.css +88 -0
- package/src/components/table/MRT_TablePaper.tsx +92 -0
- package/src/components/toolbar/MRT_BottomToolbar.module.css +40 -0
- package/src/components/toolbar/MRT_BottomToolbar.tsx +100 -0
- package/src/components/toolbar/MRT_ProgressBar.module.css +10 -0
- package/src/components/toolbar/MRT_ProgressBar.tsx +53 -0
- package/src/components/toolbar/MRT_TablePagination.module.css +20 -0
- package/src/components/toolbar/MRT_TablePagination.tsx +166 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.module.css +37 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +168 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.module.css +23 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +67 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.module.css +6 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +73 -0
- package/src/components/toolbar/MRT_TopToolbar.module.css +24 -0
- package/src/components/toolbar/MRT_TopToolbar.tsx +128 -0
- package/src/components/toolbar/common.styles.module.css +10 -0
- package/src/fns/aggregationFns.ts +3 -0
- package/src/fns/filterFns.ts +272 -0
- package/src/fns/sortingFns.ts +34 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +23 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +30 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +92 -0
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +30 -0
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +24 -0
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +34 -0
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +34 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +129 -0
- package/src/hooks/useMRT_Effects.ts +105 -0
- package/src/hooks/useMRT_RowVirtualizer.ts +95 -0
- package/src/hooks/useMRT_Rows.ts +46 -0
- package/src/hooks/useMRT_TableInstance.ts +314 -0
- package/src/hooks/useMRT_TableOptions.ts +264 -0
- package/src/hooks/useMantineReactTable.ts +14 -0
- package/src/icons.ts +73 -0
- package/src/index.ts +90 -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/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 +1276 -0
- package/src/typings.d.ts +1 -0
- package/src/utils/column.utils.ts +124 -0
- package/src/utils/displayColumn.utils.ts +153 -0
- package/src/utils/row.utils.ts +263 -0
- package/src/utils/style.utils.ts +32 -0
- package/src/utils/tanstack.helpers.ts +66 -0
- package/src/utils/utils.ts +4 -0
- package/src/utils/virtualization.utils.ts +19 -0
- package/styles.css +1320 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { MRT_DefaultDisplayColumn } from '../useMRT_TableOptions';
|
|
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
|
+
const blankColProps = {
|
|
11
|
+
children: null,
|
|
12
|
+
style: {
|
|
13
|
+
minWidth: 0,
|
|
14
|
+
padding: 0,
|
|
15
|
+
width: 0,
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export const getMRT_RowSpacerColumnDef = <TData extends MRT_RowData>(
|
|
20
|
+
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
21
|
+
): MRT_ColumnDef<TData> | null => {
|
|
22
|
+
return {
|
|
23
|
+
...defaultDisplayColumnProps({
|
|
24
|
+
id: 'mrt-row-spacer',
|
|
25
|
+
size: 0,
|
|
26
|
+
tableOptions,
|
|
27
|
+
}),
|
|
28
|
+
grow: true,
|
|
29
|
+
...MRT_DefaultDisplayColumn,
|
|
30
|
+
mantineTableBodyCellProps: blankColProps,
|
|
31
|
+
mantineTableFooterCellProps: blankColProps,
|
|
32
|
+
mantineTableHeadCellProps: blankColProps,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { type Range, useVirtualizer } from '@tanstack/react-virtual';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type MRT_ColumnVirtualizer,
|
|
7
|
+
type MRT_RowData,
|
|
8
|
+
type MRT_TableInstance,
|
|
9
|
+
} from '../types';
|
|
10
|
+
import { parseFromValuesOrFunc } from '../utils/utils';
|
|
11
|
+
import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
|
|
12
|
+
|
|
13
|
+
export const useMRT_ColumnVirtualizer = <
|
|
14
|
+
TData extends MRT_RowData,
|
|
15
|
+
TScrollElement extends Element | Window = HTMLDivElement,
|
|
16
|
+
TItemElement extends Element = HTMLTableCellElement,
|
|
17
|
+
>(
|
|
18
|
+
table: MRT_TableInstance<TData>,
|
|
19
|
+
): MRT_ColumnVirtualizer | undefined => {
|
|
20
|
+
'use no memo';
|
|
21
|
+
const {
|
|
22
|
+
getLeftLeafColumns,
|
|
23
|
+
getRightLeafColumns,
|
|
24
|
+
getState,
|
|
25
|
+
getVisibleLeafColumns,
|
|
26
|
+
options: {
|
|
27
|
+
columnVirtualizerInstanceRef,
|
|
28
|
+
columnVirtualizerOptions,
|
|
29
|
+
enableColumnPinning,
|
|
30
|
+
enableColumnVirtualization,
|
|
31
|
+
},
|
|
32
|
+
refs: { tableContainerRef },
|
|
33
|
+
} = table;
|
|
34
|
+
const { columnPinning, draggingColumn } = getState();
|
|
35
|
+
|
|
36
|
+
if (!enableColumnVirtualization) return undefined;
|
|
37
|
+
|
|
38
|
+
const columnVirtualizerProps = parseFromValuesOrFunc(
|
|
39
|
+
columnVirtualizerOptions,
|
|
40
|
+
{
|
|
41
|
+
table,
|
|
42
|
+
},
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const visibleColumns = getVisibleLeafColumns();
|
|
46
|
+
|
|
47
|
+
const [leftPinnedIndexes, rightPinnedIndexes] = useMemo(
|
|
48
|
+
() =>
|
|
49
|
+
enableColumnPinning
|
|
50
|
+
? [
|
|
51
|
+
getLeftLeafColumns().map((c) => c.getPinnedIndex()),
|
|
52
|
+
getRightLeafColumns()
|
|
53
|
+
.map(
|
|
54
|
+
(column) => visibleColumns.length - column.getPinnedIndex() - 1,
|
|
55
|
+
)
|
|
56
|
+
.sort((a, b) => a - b),
|
|
57
|
+
]
|
|
58
|
+
: [[], []],
|
|
59
|
+
[visibleColumns.length, columnPinning, enableColumnPinning],
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
const numPinnedLeft = leftPinnedIndexes.length;
|
|
63
|
+
const numPinnedRight = rightPinnedIndexes.length;
|
|
64
|
+
|
|
65
|
+
const draggingColumnIndex = useMemo(
|
|
66
|
+
() =>
|
|
67
|
+
draggingColumn?.id
|
|
68
|
+
? visibleColumns.findIndex((c) => c.id === draggingColumn?.id)
|
|
69
|
+
: undefined,
|
|
70
|
+
[draggingColumn?.id],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const columnVirtualizer = useVirtualizer({
|
|
74
|
+
count: visibleColumns.length,
|
|
75
|
+
estimateSize: (index) => visibleColumns[index].getSize(),
|
|
76
|
+
getScrollElement: () => tableContainerRef.current,
|
|
77
|
+
horizontal: true,
|
|
78
|
+
overscan: 3,
|
|
79
|
+
rangeExtractor: useCallback(
|
|
80
|
+
(range: Range) => {
|
|
81
|
+
const newIndexes = extraIndexRangeExtractor(range, draggingColumnIndex);
|
|
82
|
+
if (!numPinnedLeft && !numPinnedRight) {
|
|
83
|
+
return newIndexes;
|
|
84
|
+
}
|
|
85
|
+
return [
|
|
86
|
+
...new Set([
|
|
87
|
+
...leftPinnedIndexes,
|
|
88
|
+
...newIndexes,
|
|
89
|
+
...rightPinnedIndexes,
|
|
90
|
+
]),
|
|
91
|
+
];
|
|
92
|
+
},
|
|
93
|
+
[leftPinnedIndexes, rightPinnedIndexes, draggingColumnIndex],
|
|
94
|
+
),
|
|
95
|
+
...columnVirtualizerProps,
|
|
96
|
+
}) as unknown as MRT_ColumnVirtualizer<TScrollElement, TItemElement>;
|
|
97
|
+
|
|
98
|
+
const virtualColumns = columnVirtualizer.getVirtualItems();
|
|
99
|
+
columnVirtualizer.virtualColumns = virtualColumns as any;
|
|
100
|
+
const numColumns = virtualColumns.length;
|
|
101
|
+
|
|
102
|
+
if (numColumns) {
|
|
103
|
+
const totalSize = columnVirtualizer.getTotalSize();
|
|
104
|
+
|
|
105
|
+
const leftNonPinnedStart = virtualColumns[numPinnedLeft]?.start || 0;
|
|
106
|
+
const leftNonPinnedEnd =
|
|
107
|
+
virtualColumns[leftPinnedIndexes.length - 1]?.end || 0;
|
|
108
|
+
|
|
109
|
+
const rightNonPinnedStart =
|
|
110
|
+
virtualColumns[numColumns - numPinnedRight]?.start || 0;
|
|
111
|
+
const rightNonPinnedEnd =
|
|
112
|
+
virtualColumns[numColumns - numPinnedRight - 1]?.end || 0;
|
|
113
|
+
|
|
114
|
+
columnVirtualizer.virtualPaddingLeft =
|
|
115
|
+
leftNonPinnedStart - leftNonPinnedEnd;
|
|
116
|
+
|
|
117
|
+
columnVirtualizer.virtualPaddingRight =
|
|
118
|
+
totalSize -
|
|
119
|
+
rightNonPinnedEnd -
|
|
120
|
+
(numPinnedRight ? totalSize - rightNonPinnedStart : 0);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (columnVirtualizerInstanceRef) {
|
|
124
|
+
//@ts-ignore
|
|
125
|
+
columnVirtualizerInstanceRef.current = columnVirtualizer;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
return columnVirtualizer as any;
|
|
129
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useEffect, useReducer, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type MRT_RowData,
|
|
5
|
+
type MRT_SortingState,
|
|
6
|
+
type MRT_TableInstance,
|
|
7
|
+
} from '../types';
|
|
8
|
+
import { getDefaultColumnOrderIds } from '../utils/displayColumn.utils';
|
|
9
|
+
import { getCanRankRows } from '../utils/row.utils';
|
|
10
|
+
|
|
11
|
+
export const useMRT_Effects = <TData extends MRT_RowData>(
|
|
12
|
+
table: MRT_TableInstance<TData>,
|
|
13
|
+
) => {
|
|
14
|
+
'use no memo';
|
|
15
|
+
const {
|
|
16
|
+
getIsSomeRowsPinned,
|
|
17
|
+
getPrePaginationRowModel,
|
|
18
|
+
getState,
|
|
19
|
+
options: { enablePagination, enableRowPinning, rowCount },
|
|
20
|
+
} = table;
|
|
21
|
+
const {
|
|
22
|
+
columnOrder,
|
|
23
|
+
density,
|
|
24
|
+
globalFilter,
|
|
25
|
+
isFullScreen,
|
|
26
|
+
isLoading,
|
|
27
|
+
pagination,
|
|
28
|
+
showSkeletons,
|
|
29
|
+
sorting,
|
|
30
|
+
} = getState();
|
|
31
|
+
|
|
32
|
+
const totalColumnCount = table.options.columns.length;
|
|
33
|
+
const totalRowCount = rowCount ?? getPrePaginationRowModel().rows.length;
|
|
34
|
+
|
|
35
|
+
const rerender = useReducer(() => ({}), {})[1];
|
|
36
|
+
const initialBodyHeight = useRef<string | undefined>(undefined);
|
|
37
|
+
const previousTop = useRef<number | undefined>(undefined);
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (typeof window !== 'undefined') {
|
|
41
|
+
initialBodyHeight.current = document.body.style.height;
|
|
42
|
+
}
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
//hide scrollbars when table is in full screen mode, preserve body scroll position after full screen exit
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
if (typeof window !== 'undefined') {
|
|
48
|
+
if (isFullScreen) {
|
|
49
|
+
previousTop.current = document.body.getBoundingClientRect().top; //save scroll position
|
|
50
|
+
document.body.style.height = '100dvh'; //hide page scrollbars when table is in full screen mode
|
|
51
|
+
} else {
|
|
52
|
+
document.body.style.height = initialBodyHeight.current as string;
|
|
53
|
+
if (!previousTop.current) return;
|
|
54
|
+
//restore scroll position
|
|
55
|
+
window.scrollTo({
|
|
56
|
+
behavior: 'instant',
|
|
57
|
+
top: -1 * (previousTop.current as number),
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}, [isFullScreen]);
|
|
62
|
+
|
|
63
|
+
//recalculate column order when columns change or features are toggled on/off
|
|
64
|
+
useEffect(() => {
|
|
65
|
+
if (totalColumnCount !== columnOrder.length) {
|
|
66
|
+
table.setColumnOrder(getDefaultColumnOrderIds(table.options));
|
|
67
|
+
}
|
|
68
|
+
}, [totalColumnCount]);
|
|
69
|
+
|
|
70
|
+
//if page index is out of bounds, set it to the last page
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
if (!enablePagination || isLoading || showSkeletons) return;
|
|
73
|
+
const { pageIndex, pageSize } = pagination;
|
|
74
|
+
const firstVisibleRowIndex = pageIndex * pageSize;
|
|
75
|
+
if (firstVisibleRowIndex >= totalRowCount && firstVisibleRowIndex > 0) {
|
|
76
|
+
table.setPageIndex(Math.ceil(totalRowCount / pageSize) - 1);
|
|
77
|
+
}
|
|
78
|
+
}, [totalRowCount]);
|
|
79
|
+
|
|
80
|
+
//turn off sort when global filter is looking for ranked results
|
|
81
|
+
const appliedSort = useRef<MRT_SortingState>(sorting);
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (sorting.length) {
|
|
84
|
+
appliedSort.current = sorting;
|
|
85
|
+
}
|
|
86
|
+
}, [sorting]);
|
|
87
|
+
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!getCanRankRows(table)) return;
|
|
90
|
+
if (globalFilter) {
|
|
91
|
+
table.setSorting([]);
|
|
92
|
+
} else {
|
|
93
|
+
table.setSorting(() => appliedSort.current || []);
|
|
94
|
+
}
|
|
95
|
+
}, [globalFilter]);
|
|
96
|
+
|
|
97
|
+
//fix pinned row top style when density changes
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
if (enableRowPinning && getIsSomeRowsPinned()) {
|
|
100
|
+
setTimeout(() => {
|
|
101
|
+
rerender();
|
|
102
|
+
}, 150);
|
|
103
|
+
}
|
|
104
|
+
}, [density]);
|
|
105
|
+
};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { type Range, useVirtualizer } from '@tanstack/react-virtual';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
type MRT_DensityState,
|
|
7
|
+
type MRT_Row,
|
|
8
|
+
type MRT_RowData,
|
|
9
|
+
type MRT_RowVirtualizer,
|
|
10
|
+
type MRT_TableInstance,
|
|
11
|
+
} from '../types';
|
|
12
|
+
import { parseFromValuesOrFunc } from '../utils/utils';
|
|
13
|
+
import { extraIndexRangeExtractor } from '../utils/virtualization.utils';
|
|
14
|
+
|
|
15
|
+
export const useMRT_RowVirtualizer = <
|
|
16
|
+
TData extends MRT_RowData,
|
|
17
|
+
TScrollElement extends Element | Window = HTMLDivElement,
|
|
18
|
+
TItemElement extends Element = HTMLTableRowElement,
|
|
19
|
+
>(
|
|
20
|
+
table: MRT_TableInstance<TData>,
|
|
21
|
+
rows?: MRT_Row<TData>[],
|
|
22
|
+
): MRT_RowVirtualizer<TScrollElement, TItemElement> | undefined => {
|
|
23
|
+
'use no memo';
|
|
24
|
+
const {
|
|
25
|
+
getRowModel,
|
|
26
|
+
getState,
|
|
27
|
+
options: {
|
|
28
|
+
enableRowVirtualization,
|
|
29
|
+
renderDetailPanel,
|
|
30
|
+
rowVirtualizerInstanceRef,
|
|
31
|
+
rowVirtualizerOptions,
|
|
32
|
+
},
|
|
33
|
+
refs: { tableContainerRef },
|
|
34
|
+
} = table;
|
|
35
|
+
const { density, draggingRow, expanded } = getState();
|
|
36
|
+
|
|
37
|
+
if (!enableRowVirtualization) return undefined;
|
|
38
|
+
|
|
39
|
+
const rowVirtualizerProps = parseFromValuesOrFunc(rowVirtualizerOptions, {
|
|
40
|
+
table,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const rowCount = rows?.length ?? getRowModel().rows.length;
|
|
44
|
+
|
|
45
|
+
const defaultRowHeightByDensity: Record<MRT_DensityState, number> = {
|
|
46
|
+
lg: 62.7,
|
|
47
|
+
md: 54.7,
|
|
48
|
+
sm: 48.7,
|
|
49
|
+
xl: 70.7,
|
|
50
|
+
xs: 42.7,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const normalRowHeight =
|
|
54
|
+
defaultRowHeightByDensity[density] ?? defaultRowHeightByDensity['md'];
|
|
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
|
+
const current_index = getRowModel().rows.findIndex(
|
|
74
|
+
(row) => row.id === draggingRow?.id,
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
return extraIndexRangeExtractor(
|
|
78
|
+
range,
|
|
79
|
+
current_index >= 0 ? current_index : 0,
|
|
80
|
+
);
|
|
81
|
+
},
|
|
82
|
+
[draggingRow],
|
|
83
|
+
),
|
|
84
|
+
...rowVirtualizerProps,
|
|
85
|
+
}) as unknown as MRT_RowVirtualizer<TScrollElement, TItemElement>;
|
|
86
|
+
|
|
87
|
+
rowVirtualizer.virtualRows = rowVirtualizer.getVirtualItems() as any;
|
|
88
|
+
|
|
89
|
+
if (rowVirtualizerInstanceRef) {
|
|
90
|
+
//@ts-ignore
|
|
91
|
+
rowVirtualizerInstanceRef.current = rowVirtualizer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return rowVirtualizer;
|
|
95
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
type MRT_Row,
|
|
5
|
+
type MRT_RowData,
|
|
6
|
+
type MRT_TableInstance,
|
|
7
|
+
} from '../types';
|
|
8
|
+
import { getMRT_Rows } from '../utils/row.utils';
|
|
9
|
+
|
|
10
|
+
export const useMRT_Rows = <TData extends MRT_RowData>(
|
|
11
|
+
table: MRT_TableInstance<TData>,
|
|
12
|
+
): MRT_Row<TData>[] => {
|
|
13
|
+
'use no memo';
|
|
14
|
+
const {
|
|
15
|
+
getRowModel,
|
|
16
|
+
getState,
|
|
17
|
+
options: { data, enableGlobalFilterRankedResults, positionCreatingRow },
|
|
18
|
+
} = table;
|
|
19
|
+
const {
|
|
20
|
+
creatingRow,
|
|
21
|
+
expanded,
|
|
22
|
+
globalFilter,
|
|
23
|
+
pagination,
|
|
24
|
+
rowPinning,
|
|
25
|
+
sorting,
|
|
26
|
+
} = getState();
|
|
27
|
+
|
|
28
|
+
const rows = useMemo(
|
|
29
|
+
() => getMRT_Rows(table),
|
|
30
|
+
[
|
|
31
|
+
creatingRow,
|
|
32
|
+
data,
|
|
33
|
+
enableGlobalFilterRankedResults,
|
|
34
|
+
expanded,
|
|
35
|
+
getRowModel().rows,
|
|
36
|
+
globalFilter,
|
|
37
|
+
pagination.pageIndex,
|
|
38
|
+
pagination.pageSize,
|
|
39
|
+
positionCreatingRow,
|
|
40
|
+
rowPinning,
|
|
41
|
+
sorting,
|
|
42
|
+
],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
return rows;
|
|
46
|
+
};
|