@lminii/material-react-table 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +234 -0
- package/dist/index.d.mts +2408 -0
- package/dist/index.d.ts +2408 -0
- package/dist/index.js +4825 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +4631 -0
- package/dist/index.mjs.map +1 -0
- package/locales/ar/index.d.mts +3 -0
- package/locales/ar/index.d.ts +3 -0
- package/locales/ar/index.js +100 -0
- package/locales/ar/index.mjs +96 -0
- package/locales/ar/package.json +6 -0
- package/locales/az/index.d.mts +3 -0
- package/locales/az/index.d.ts +3 -0
- package/locales/az/index.js +100 -0
- package/locales/az/index.mjs +96 -0
- package/locales/az/package.json +6 -0
- package/locales/bg/index.d.mts +3 -0
- package/locales/bg/index.d.ts +3 -0
- package/locales/bg/index.js +100 -0
- package/locales/bg/index.mjs +96 -0
- package/locales/bg/package.json +6 -0
- package/locales/cs/index.d.mts +3 -0
- package/locales/cs/index.d.ts +3 -0
- package/locales/cs/index.js +100 -0
- package/locales/cs/index.mjs +96 -0
- package/locales/cs/package.json +6 -0
- package/locales/da/index.d.mts +3 -0
- package/locales/da/index.d.ts +3 -0
- package/locales/da/index.js +100 -0
- package/locales/da/index.mjs +96 -0
- package/locales/da/package.json +6 -0
- package/locales/de/index.d.mts +3 -0
- package/locales/de/index.d.ts +3 -0
- package/locales/de/index.js +100 -0
- package/locales/de/index.mjs +96 -0
- package/locales/de/package.json +6 -0
- package/locales/el/index.d.mts +3 -0
- package/locales/el/index.d.ts +3 -0
- package/locales/el/index.js +100 -0
- package/locales/el/index.mjs +96 -0
- package/locales/el/package.json +6 -0
- package/locales/en/index.d.mts +3 -0
- package/locales/en/index.d.ts +3 -0
- package/locales/en/index.js +100 -0
- package/locales/en/index.mjs +96 -0
- package/locales/en/package.json +6 -0
- package/locales/es/index.d.mts +3 -0
- package/locales/es/index.d.ts +3 -0
- package/locales/es/index.js +100 -0
- package/locales/es/index.mjs +96 -0
- package/locales/es/package.json +6 -0
- package/locales/et/index.d.mts +3 -0
- package/locales/et/index.d.ts +3 -0
- package/locales/et/index.js +100 -0
- package/locales/et/index.mjs +96 -0
- package/locales/et/package.json +6 -0
- package/locales/fa/index.d.mts +3 -0
- package/locales/fa/index.d.ts +3 -0
- package/locales/fa/index.js +100 -0
- package/locales/fa/index.mjs +96 -0
- package/locales/fa/package.json +6 -0
- package/locales/fi/index.d.mts +3 -0
- package/locales/fi/index.d.ts +3 -0
- package/locales/fi/index.js +100 -0
- package/locales/fi/index.mjs +96 -0
- package/locales/fi/package.json +6 -0
- package/locales/fr/index.d.mts +3 -0
- package/locales/fr/index.d.ts +3 -0
- package/locales/fr/index.js +100 -0
- package/locales/fr/index.mjs +96 -0
- package/locales/fr/package.json +6 -0
- package/locales/he/index.d.mts +3 -0
- package/locales/he/index.d.ts +3 -0
- package/locales/he/index.js +100 -0
- package/locales/he/index.mjs +96 -0
- package/locales/he/package.json +6 -0
- package/locales/hr/index.d.mts +3 -0
- package/locales/hr/index.d.ts +3 -0
- package/locales/hr/index.js +100 -0
- package/locales/hr/index.mjs +96 -0
- package/locales/hr/package.json +6 -0
- package/locales/hu/index.d.mts +3 -0
- package/locales/hu/index.d.ts +3 -0
- package/locales/hu/index.js +100 -0
- package/locales/hu/index.mjs +96 -0
- package/locales/hu/package.json +6 -0
- package/locales/hy/index.d.mts +3 -0
- package/locales/hy/index.d.ts +3 -0
- package/locales/hy/index.js +100 -0
- package/locales/hy/index.mjs +96 -0
- package/locales/hy/package.json +6 -0
- package/locales/id/index.d.mts +3 -0
- package/locales/id/index.d.ts +3 -0
- package/locales/id/index.js +100 -0
- package/locales/id/index.mjs +96 -0
- package/locales/id/package.json +6 -0
- package/locales/it/index.d.mts +3 -0
- package/locales/it/index.d.ts +3 -0
- package/locales/it/index.js +100 -0
- package/locales/it/index.mjs +96 -0
- package/locales/it/package.json +6 -0
- package/locales/ja/index.d.mts +3 -0
- package/locales/ja/index.d.ts +3 -0
- package/locales/ja/index.js +100 -0
- package/locales/ja/index.mjs +96 -0
- package/locales/ja/package.json +6 -0
- package/locales/ko/index.d.mts +3 -0
- package/locales/ko/index.d.ts +3 -0
- package/locales/ko/index.js +100 -0
- package/locales/ko/index.mjs +96 -0
- package/locales/ko/package.json +6 -0
- package/locales/nl/index.d.mts +3 -0
- package/locales/nl/index.d.ts +3 -0
- package/locales/nl/index.js +100 -0
- package/locales/nl/index.mjs +96 -0
- package/locales/nl/package.json +6 -0
- package/locales/no/index.d.mts +3 -0
- package/locales/no/index.d.ts +3 -0
- package/locales/no/index.js +100 -0
- package/locales/no/index.mjs +96 -0
- package/locales/no/package.json +6 -0
- package/locales/np/index.d.mts +3 -0
- package/locales/np/index.d.ts +3 -0
- package/locales/np/index.js +100 -0
- package/locales/np/index.mjs +96 -0
- package/locales/np/package.json +6 -0
- package/locales/pl/index.d.mts +3 -0
- package/locales/pl/index.d.ts +3 -0
- package/locales/pl/index.js +100 -0
- package/locales/pl/index.mjs +96 -0
- package/locales/pl/package.json +6 -0
- package/locales/pt/index.d.mts +3 -0
- package/locales/pt/index.d.ts +3 -0
- package/locales/pt/index.js +100 -0
- package/locales/pt/index.mjs +96 -0
- package/locales/pt/package.json +6 -0
- package/locales/pt-BR/index.d.mts +3 -0
- package/locales/pt-BR/index.d.ts +3 -0
- package/locales/pt-BR/index.js +100 -0
- package/locales/pt-BR/index.mjs +96 -0
- package/locales/pt-BR/package.json +6 -0
- package/locales/ro/index.d.mts +3 -0
- package/locales/ro/index.d.ts +3 -0
- package/locales/ro/index.js +100 -0
- package/locales/ro/index.mjs +96 -0
- package/locales/ro/package.json +6 -0
- package/locales/ru/index.d.mts +3 -0
- package/locales/ru/index.d.ts +3 -0
- package/locales/ru/index.js +100 -0
- package/locales/ru/index.mjs +96 -0
- package/locales/ru/package.json +6 -0
- package/locales/sk/index.d.mts +3 -0
- package/locales/sk/index.d.ts +3 -0
- package/locales/sk/index.js +100 -0
- package/locales/sk/index.mjs +96 -0
- package/locales/sk/package.json +6 -0
- package/locales/sr-Cyrl-RS/index.d.mts +3 -0
- package/locales/sr-Cyrl-RS/index.d.ts +3 -0
- package/locales/sr-Cyrl-RS/index.js +100 -0
- package/locales/sr-Cyrl-RS/index.mjs +96 -0
- package/locales/sr-Cyrl-RS/package.json +6 -0
- package/locales/sr-Latn-RS/index.d.mts +3 -0
- package/locales/sr-Latn-RS/index.d.ts +3 -0
- package/locales/sr-Latn-RS/index.js +100 -0
- package/locales/sr-Latn-RS/index.mjs +96 -0
- package/locales/sr-Latn-RS/package.json +6 -0
- package/locales/sv/index.d.mts +3 -0
- package/locales/sv/index.d.ts +3 -0
- package/locales/sv/index.js +100 -0
- package/locales/sv/index.mjs +96 -0
- package/locales/sv/package.json +6 -0
- package/locales/tr/index.d.mts +3 -0
- package/locales/tr/index.d.ts +3 -0
- package/locales/tr/index.js +100 -0
- package/locales/tr/index.mjs +96 -0
- package/locales/tr/package.json +6 -0
- package/locales/uk/index.d.mts +3 -0
- package/locales/uk/index.d.ts +3 -0
- package/locales/uk/index.js +100 -0
- package/locales/uk/index.mjs +96 -0
- package/locales/uk/package.json +6 -0
- package/locales/vi/index.d.mts +3 -0
- package/locales/vi/index.d.ts +3 -0
- package/locales/vi/index.js +100 -0
- package/locales/vi/index.mjs +96 -0
- package/locales/vi/package.json +6 -0
- package/locales/zh-Hans/index.d.mts +3 -0
- package/locales/zh-Hans/index.d.ts +3 -0
- package/locales/zh-Hans/index.js +100 -0
- package/locales/zh-Hans/index.mjs +96 -0
- package/locales/zh-Hans/package.json +6 -0
- package/locales/zh-Hant/index.d.mts +3 -0
- package/locales/zh-Hant/index.d.ts +3 -0
- package/locales/zh-Hant/index.js +100 -0
- package/locales/zh-Hant/index.mjs +96 -0
- package/locales/zh-Hant/package.json +6 -0
- package/package.json +147 -0
- package/skills/README.md +81 -0
- package/skills/composable-components/SKILL.md +189 -0
- package/skills/customization/SKILL.md +190 -0
- package/skills/drag-and-drop-ordering/SKILL.md +227 -0
- package/skills/editing/SKILL.md +243 -0
- package/skills/filtering/SKILL.md +213 -0
- package/skills/getting-started/SKILL.md +213 -0
- package/skills/localization/SKILL.md +182 -0
- package/skills/migrate-v3-to-v4/SKILL.md +161 -0
- package/skills/state-and-server-data/SKILL.md +200 -0
- package/skills/virtualization/SKILL.md +203 -0
- package/src/components/MaterialReactTable.tsx +36 -0
- package/src/components/body/MRT_TableBody.tsx +221 -0
- package/src/components/body/MRT_TableBodyCell.tsx +351 -0
- package/src/components/body/MRT_TableBodyCellValue.tsx +130 -0
- package/src/components/body/MRT_TableBodyRow.tsx +288 -0
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +61 -0
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +58 -0
- package/src/components/body/MRT_TableDetailPanel.tsx +110 -0
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +72 -0
- package/src/components/buttons/MRT_CopyButton.tsx +87 -0
- package/src/components/buttons/MRT_EditActionButtons.tsx +134 -0
- package/src/components/buttons/MRT_ExpandAllButton.tsx +78 -0
- package/src/components/buttons/MRT_ExpandButton.tsx +102 -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 +50 -0
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +52 -0
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +40 -0
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +51 -0
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +46 -0
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +126 -0
- package/src/components/footer/MRT_TableFooter.tsx +88 -0
- package/src/components/footer/MRT_TableFooterCell.tsx +107 -0
- package/src/components/footer/MRT_TableFooterRow.tsx +95 -0
- package/src/components/head/MRT_TableHead.tsx +91 -0
- package/src/components/head/MRT_TableHeadCell.tsx +351 -0
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +96 -0
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +52 -0
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +178 -0
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +91 -0
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +96 -0
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +101 -0
- package/src/components/head/MRT_TableHeadRow.tsx +90 -0
- package/src/components/inputs/MRT_EditCellTextField.tsx +202 -0
- package/src/components/inputs/MRT_FilterCheckbox.tsx +90 -0
- package/src/components/inputs/MRT_FilterRangeFields.tsx +41 -0
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +143 -0
- package/src/components/inputs/MRT_FilterTextField.tsx +592 -0
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +167 -0
- package/src/components/inputs/MRT_SelectCheckbox.tsx +135 -0
- package/src/components/menus/MRT_ActionMenuItem.tsx +62 -0
- package/src/components/menus/MRT_CellActionMenu.tsx +107 -0
- package/src/components/menus/MRT_ColumnActionMenu.tsx +352 -0
- package/src/components/menus/MRT_FilterOptionMenu.tsx +292 -0
- package/src/components/menus/MRT_RowActionMenu.tsx +88 -0
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +181 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +203 -0
- package/src/components/modals/MRT_EditRowModal.tsx +114 -0
- package/src/components/table/MRT_Table.tsx +84 -0
- package/src/components/table/MRT_TableContainer.tsx +111 -0
- package/src/components/table/MRT_TableLoadingOverlay.tsx +58 -0
- package/src/components/table/MRT_TablePaper.tsx +89 -0
- package/src/components/toolbar/MRT_BottomToolbar.tsx +111 -0
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +53 -0
- package/src/components/toolbar/MRT_TablePagination.tsx +241 -0
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +184 -0
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +83 -0
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +72 -0
- package/src/components/toolbar/MRT_TopToolbar.tsx +130 -0
- package/src/features/mrtCellActionsFeature.ts +67 -0
- package/src/features/mrtColumnDraggingFeature.ts +83 -0
- package/src/features/mrtDensityFeature.ts +64 -0
- package/src/features/mrtEditingFeature.ts +102 -0
- package/src/features/mrtFeatures.ts +103 -0
- package/src/features/mrtFilterModesFeature.ts +99 -0
- package/src/features/mrtFnsFeature.ts +46 -0
- package/src/features/mrtFullScreenFeature.ts +63 -0
- package/src/features/mrtLoadingFeature.ts +35 -0
- package/src/features/mrtRefsFeature.ts +60 -0
- package/src/features/mrtRowDraggingFeature.ts +81 -0
- package/src/features/mrtStateCompatFeature.ts +43 -0
- package/src/features/mrtToolbarsFeature.ts +76 -0
- package/src/fns/aggregationFns.ts +3 -0
- package/src/fns/filterFns.ts +196 -0
- package/src/fns/sortingFns.ts +31 -0
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +28 -0
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +29 -0
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +97 -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 +33 -0
- package/src/hooks/useMRT_ColumnVirtualizer.ts +124 -0
- package/src/hooks/useMRT_Effects.ts +108 -0
- package/src/hooks/useMRT_RowVirtualizer.ts +88 -0
- package/src/hooks/useMRT_Rows.ts +44 -0
- package/src/hooks/useMRT_TableInstance.ts +181 -0
- package/src/hooks/useMRT_TableOptions.ts +241 -0
- package/src/hooks/useMaterialReactTable.ts +12 -0
- package/src/icons.ts +73 -0
- package/src/index.ts +91 -0
- package/src/locales/ar.ts +97 -0
- package/src/locales/az.ts +97 -0
- package/src/locales/bg.ts +97 -0
- package/src/locales/cs.ts +98 -0
- package/src/locales/da.ts +97 -0
- package/src/locales/de.ts +97 -0
- package/src/locales/el.ts +97 -0
- package/src/locales/en.ts +97 -0
- package/src/locales/es.ts +97 -0
- package/src/locales/et.ts +98 -0
- package/src/locales/fa.ts +97 -0
- package/src/locales/fi.ts +98 -0
- package/src/locales/fr.ts +97 -0
- package/src/locales/he.ts +97 -0
- package/src/locales/hr.ts +97 -0
- package/src/locales/hu.ts +97 -0
- package/src/locales/hy.ts +97 -0
- package/src/locales/id.ts +98 -0
- package/src/locales/it.ts +97 -0
- package/src/locales/ja.ts +97 -0
- package/src/locales/ko.ts +97 -0
- package/src/locales/mk.ts +96 -0
- package/src/locales/nl.ts +97 -0
- package/src/locales/no.ts +99 -0
- package/src/locales/np.ts +98 -0
- package/src/locales/pl.ts +97 -0
- package/src/locales/pt-BR.ts +97 -0
- package/src/locales/pt.ts +97 -0
- package/src/locales/ro.ts +97 -0
- package/src/locales/ru.ts +97 -0
- package/src/locales/sk.ts +98 -0
- package/src/locales/sr-Cyrl-RS.ts +97 -0
- package/src/locales/sr-Latn-RS.ts +97 -0
- package/src/locales/sv.ts +97 -0
- package/src/locales/tr.ts +97 -0
- package/src/locales/uk.ts +97 -0
- package/src/locales/vi.ts +97 -0
- package/src/locales/zh-Hans.ts +96 -0
- package/src/locales/zh-Hant.ts +96 -0
- package/src/types.ts +1314 -0
- package/src/utils/cell.utils.ts +234 -0
- package/src/utils/column.utils.ts +204 -0
- package/src/utils/displayColumn.utils.ts +152 -0
- package/src/utils/row.utils.ts +258 -0
- package/src/utils/style.utils.ts +211 -0
- package/src/utils/tanstack.helpers.ts +64 -0
- package/src/utils/utils.ts +34 -0
- package/src/utils/virtualization.utils.ts +24 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignTableAPIs,
|
|
3
|
+
functionalUpdate,
|
|
4
|
+
makeStateUpdater,
|
|
5
|
+
type OnChangeFn,
|
|
6
|
+
type RowData,
|
|
7
|
+
type TableFeature,
|
|
8
|
+
type TableFeatures,
|
|
9
|
+
type Updater,
|
|
10
|
+
} from '@tanstack/react-table';
|
|
11
|
+
import { type MRT_Cell, type MRT_Row } from '../types';
|
|
12
|
+
import { createRow } from '../utils/tanstack.helpers';
|
|
13
|
+
|
|
14
|
+
export interface MRT_Table_Editing<TData extends RowData> {
|
|
15
|
+
setCreatingRow: (updater: Updater<MRT_Row<TData> | null | true>) => void;
|
|
16
|
+
setEditingCell: (updater: Updater<MRT_Cell<TData> | null>) => void;
|
|
17
|
+
setEditingRow: (updater: Updater<MRT_Row<TData> | null>) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MRT_TableOptions_Editing<TData extends RowData> {
|
|
21
|
+
onCreatingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
22
|
+
onEditingCellChange?: OnChangeFn<MRT_Cell<TData> | null>;
|
|
23
|
+
onEditingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface MRT_TableState_Editing {
|
|
27
|
+
creatingRow: MRT_Row<any> | null;
|
|
28
|
+
editingCell: MRT_Cell<any> | null;
|
|
29
|
+
editingRow: MRT_Row<any> | null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare module '@tanstack/react-table' {
|
|
33
|
+
interface Plugins {
|
|
34
|
+
mrtEditingFeature: TableFeature;
|
|
35
|
+
}
|
|
36
|
+
interface Table_FeatureMap<
|
|
37
|
+
TFeatures extends TableFeatures,
|
|
38
|
+
TData extends RowData,
|
|
39
|
+
> {
|
|
40
|
+
mrtEditingFeature: MRT_Table_Editing<TData>;
|
|
41
|
+
}
|
|
42
|
+
interface TableOptions_FeatureMap<
|
|
43
|
+
TFeatures extends TableFeatures,
|
|
44
|
+
TData extends RowData,
|
|
45
|
+
> {
|
|
46
|
+
mrtEditingFeature: MRT_TableOptions_Editing<TData>;
|
|
47
|
+
}
|
|
48
|
+
interface TableState_FeatureMap {
|
|
49
|
+
mrtEditingFeature: MRT_TableState_Editing;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export const mrtEditingFeature: TableFeature = {
|
|
54
|
+
constructTableAPIs: (table) => {
|
|
55
|
+
assignTableAPIs('mrtEditingFeature', table, {
|
|
56
|
+
table_setCreatingRow: {
|
|
57
|
+
fn: (updater: Updater<MRT_Row<any> | null | true>) =>
|
|
58
|
+
(
|
|
59
|
+
table.options as MRT_TableOptions_Editing<any>
|
|
60
|
+
).onCreatingRowChange?.((old) => {
|
|
61
|
+
const next = functionalUpdate(
|
|
62
|
+
updater,
|
|
63
|
+
old as MRT_Row<any> | null | true,
|
|
64
|
+
);
|
|
65
|
+
return next === true ? createRow(table as any) : next;
|
|
66
|
+
}),
|
|
67
|
+
},
|
|
68
|
+
table_setEditingCell: {
|
|
69
|
+
fn: (updater: Updater<MRT_Cell<any> | null>) =>
|
|
70
|
+
(
|
|
71
|
+
table.options as MRT_TableOptions_Editing<any>
|
|
72
|
+
).onEditingCellChange?.((old) => functionalUpdate(updater, old)),
|
|
73
|
+
},
|
|
74
|
+
table_setEditingRow: {
|
|
75
|
+
fn: (updater: Updater<MRT_Row<any> | null>) =>
|
|
76
|
+
(table.options as MRT_TableOptions_Editing<any>).onEditingRowChange?.(
|
|
77
|
+
(old) => functionalUpdate(updater, old),
|
|
78
|
+
),
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
},
|
|
82
|
+
getDefaultTableOptions: (table) => ({
|
|
83
|
+
onCreatingRowChange: makeStateUpdater(
|
|
84
|
+
'creatingRow',
|
|
85
|
+
table,
|
|
86
|
+
) as OnChangeFn<any>,
|
|
87
|
+
onEditingCellChange: makeStateUpdater(
|
|
88
|
+
'editingCell',
|
|
89
|
+
table,
|
|
90
|
+
) as OnChangeFn<any>,
|
|
91
|
+
onEditingRowChange: makeStateUpdater(
|
|
92
|
+
'editingRow',
|
|
93
|
+
table,
|
|
94
|
+
) as OnChangeFn<any>,
|
|
95
|
+
}),
|
|
96
|
+
getInitialState: (initialState) => ({
|
|
97
|
+
creatingRow: null,
|
|
98
|
+
editingCell: null,
|
|
99
|
+
editingRow: null,
|
|
100
|
+
...initialState,
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import {
|
|
2
|
+
columnFacetingFeature,
|
|
3
|
+
columnFilteringFeature,
|
|
4
|
+
columnGroupingFeature,
|
|
5
|
+
columnOrderingFeature,
|
|
6
|
+
columnPinningFeature,
|
|
7
|
+
columnResizingFeature,
|
|
8
|
+
columnSizingFeature,
|
|
9
|
+
columnVisibilityFeature,
|
|
10
|
+
createExpandedRowModel,
|
|
11
|
+
createFacetedMinMaxValues,
|
|
12
|
+
createFacetedRowModel,
|
|
13
|
+
createFacetedUniqueValues,
|
|
14
|
+
createFilteredRowModel,
|
|
15
|
+
createGroupedRowModel,
|
|
16
|
+
createPaginatedRowModel,
|
|
17
|
+
createSortedRowModel,
|
|
18
|
+
globalFilteringFeature,
|
|
19
|
+
rowAggregationFeature,
|
|
20
|
+
rowExpandingFeature,
|
|
21
|
+
rowPaginationFeature,
|
|
22
|
+
rowPinningFeature,
|
|
23
|
+
rowSelectionFeature,
|
|
24
|
+
rowSortingFeature,
|
|
25
|
+
tableFeatures,
|
|
26
|
+
} from '@tanstack/react-table';
|
|
27
|
+
import { mrtCellActionsFeature } from './mrtCellActionsFeature';
|
|
28
|
+
import { mrtColumnDraggingFeature } from './mrtColumnDraggingFeature';
|
|
29
|
+
import { mrtDensityFeature } from './mrtDensityFeature';
|
|
30
|
+
import { mrtEditingFeature } from './mrtEditingFeature';
|
|
31
|
+
import { mrtFilterModesFeature } from './mrtFilterModesFeature';
|
|
32
|
+
import { mrtFnsFeature } from './mrtFnsFeature';
|
|
33
|
+
import { mrtFullScreenFeature } from './mrtFullScreenFeature';
|
|
34
|
+
import { mrtLoadingFeature } from './mrtLoadingFeature';
|
|
35
|
+
import { mrtRefsFeature } from './mrtRefsFeature';
|
|
36
|
+
import { mrtRowDraggingFeature } from './mrtRowDraggingFeature';
|
|
37
|
+
import { mrtStateCompatFeature } from './mrtStateCompatFeature';
|
|
38
|
+
import { mrtToolbarsFeature } from './mrtToolbarsFeature';
|
|
39
|
+
import { MRT_AggregationFns } from '../fns/aggregationFns';
|
|
40
|
+
import { MRT_FilterFns } from '../fns/filterFns';
|
|
41
|
+
import { MRT_SortingFns } from '../fns/sortingFns';
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* The static feature registry every MRT table is built from. Row models are
|
|
45
|
+
* registered unconditionally; core skips a stage at runtime when its `manual*`
|
|
46
|
+
* option is set, and a feature with empty state is an identity pass. The
|
|
47
|
+
* faceted models are the exception, see `mrtFeaturesWithoutFacetedValues`.
|
|
48
|
+
*/
|
|
49
|
+
export const mrtFeatures = tableFeatures({
|
|
50
|
+
aggregationFns: MRT_AggregationFns,
|
|
51
|
+
columnFacetingFeature,
|
|
52
|
+
columnFilteringFeature,
|
|
53
|
+
columnGroupingFeature,
|
|
54
|
+
columnOrderingFeature,
|
|
55
|
+
columnPinningFeature,
|
|
56
|
+
columnResizingFeature,
|
|
57
|
+
columnSizingFeature,
|
|
58
|
+
columnVisibilityFeature,
|
|
59
|
+
expandedRowModel: createExpandedRowModel(),
|
|
60
|
+
facetedMinMaxValues: createFacetedMinMaxValues(),
|
|
61
|
+
facetedRowModel: createFacetedRowModel(),
|
|
62
|
+
facetedUniqueValues: createFacetedUniqueValues(),
|
|
63
|
+
filteredRowModel: createFilteredRowModel(),
|
|
64
|
+
filterFns: MRT_FilterFns,
|
|
65
|
+
globalFilteringFeature,
|
|
66
|
+
groupedRowModel: createGroupedRowModel(),
|
|
67
|
+
mrtCellActionsFeature,
|
|
68
|
+
mrtColumnDraggingFeature,
|
|
69
|
+
mrtDensityFeature,
|
|
70
|
+
mrtEditingFeature,
|
|
71
|
+
mrtFilterModesFeature,
|
|
72
|
+
mrtFnsFeature,
|
|
73
|
+
mrtFullScreenFeature,
|
|
74
|
+
mrtLoadingFeature,
|
|
75
|
+
mrtRefsFeature,
|
|
76
|
+
mrtRowDraggingFeature,
|
|
77
|
+
mrtStateCompatFeature,
|
|
78
|
+
mrtToolbarsFeature,
|
|
79
|
+
paginatedRowModel: createPaginatedRowModel(),
|
|
80
|
+
rowAggregationFeature,
|
|
81
|
+
rowExpandingFeature,
|
|
82
|
+
rowPaginationFeature,
|
|
83
|
+
rowPinningFeature,
|
|
84
|
+
rowSelectionFeature,
|
|
85
|
+
rowSortingFeature,
|
|
86
|
+
sortedRowModel: createSortedRowModel(),
|
|
87
|
+
sortFns: MRT_SortingFns,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Used when `enableFacetedValues` is off. Without the factories, core returns
|
|
92
|
+
* an empty Map for unique values, `undefined` for min/max values, and the
|
|
93
|
+
* pre-filtered row model for the faceted row model, so accessors are never
|
|
94
|
+
* run just to build facets.
|
|
95
|
+
*/
|
|
96
|
+
export const mrtFeaturesWithoutFacetedValues = {
|
|
97
|
+
...mrtFeatures,
|
|
98
|
+
facetedMinMaxValues: undefined,
|
|
99
|
+
facetedRowModel: undefined,
|
|
100
|
+
facetedUniqueValues: undefined,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export type MRT_Features = typeof mrtFeatures;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignTableAPIs,
|
|
3
|
+
functionalUpdate,
|
|
4
|
+
makeStateUpdater,
|
|
5
|
+
type OnChangeFn,
|
|
6
|
+
type RowData,
|
|
7
|
+
type TableFeature,
|
|
8
|
+
type TableFeatures,
|
|
9
|
+
type Updater,
|
|
10
|
+
} from '@tanstack/react-table';
|
|
11
|
+
import { type MRT_ColumnFilterFnsState, type MRT_FilterOption } from '../types';
|
|
12
|
+
|
|
13
|
+
export interface MRT_Table_FilterModes {
|
|
14
|
+
setColumnFilterFns: (updater: Updater<MRT_ColumnFilterFnsState>) => void;
|
|
15
|
+
setGlobalFilterFn: (updater: Updater<MRT_FilterOption>) => void;
|
|
16
|
+
setShowColumnFilters: (updater: Updater<boolean>) => void;
|
|
17
|
+
setShowGlobalFilter: (updater: Updater<boolean>) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MRT_TableOptions_FilterModes {
|
|
21
|
+
onColumnFilterFnsChange?: OnChangeFn<MRT_ColumnFilterFnsState>;
|
|
22
|
+
onGlobalFilterFnChange?: OnChangeFn<MRT_FilterOption>;
|
|
23
|
+
onShowColumnFiltersChange?: OnChangeFn<boolean>;
|
|
24
|
+
onShowGlobalFilterChange?: OnChangeFn<boolean>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface MRT_TableState_FilterModes {
|
|
28
|
+
columnFilterFns: MRT_ColumnFilterFnsState;
|
|
29
|
+
globalFilterFn: MRT_FilterOption;
|
|
30
|
+
showColumnFilters: boolean;
|
|
31
|
+
showGlobalFilter: boolean;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
declare module '@tanstack/react-table' {
|
|
35
|
+
interface Plugins {
|
|
36
|
+
mrtFilterModesFeature: TableFeature;
|
|
37
|
+
}
|
|
38
|
+
interface Table_FeatureMap<
|
|
39
|
+
TFeatures extends TableFeatures,
|
|
40
|
+
TData extends RowData,
|
|
41
|
+
> {
|
|
42
|
+
mrtFilterModesFeature: MRT_Table_FilterModes;
|
|
43
|
+
}
|
|
44
|
+
interface TableOptions_FeatureMap<
|
|
45
|
+
TFeatures extends TableFeatures,
|
|
46
|
+
TData extends RowData,
|
|
47
|
+
> {
|
|
48
|
+
mrtFilterModesFeature: MRT_TableOptions_FilterModes;
|
|
49
|
+
}
|
|
50
|
+
interface TableState_FeatureMap {
|
|
51
|
+
mrtFilterModesFeature: MRT_TableState_FilterModes;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export const mrtFilterModesFeature: TableFeature = {
|
|
56
|
+
constructTableAPIs: (table) => {
|
|
57
|
+
assignTableAPIs('mrtFilterModesFeature', table, {
|
|
58
|
+
table_setColumnFilterFns: {
|
|
59
|
+
fn: (updater: Updater<MRT_ColumnFilterFnsState>) =>
|
|
60
|
+
(
|
|
61
|
+
table.options as MRT_TableOptions_FilterModes
|
|
62
|
+
).onColumnFilterFnsChange?.((old) => functionalUpdate(updater, old)),
|
|
63
|
+
},
|
|
64
|
+
table_setGlobalFilterFn: {
|
|
65
|
+
fn: (updater: Updater<MRT_FilterOption>) =>
|
|
66
|
+
(
|
|
67
|
+
table.options as MRT_TableOptions_FilterModes
|
|
68
|
+
).onGlobalFilterFnChange?.((old) => functionalUpdate(updater, old)),
|
|
69
|
+
},
|
|
70
|
+
table_setShowColumnFilters: {
|
|
71
|
+
fn: (updater: Updater<boolean>) =>
|
|
72
|
+
(
|
|
73
|
+
table.options as MRT_TableOptions_FilterModes
|
|
74
|
+
).onShowColumnFiltersChange?.((old) =>
|
|
75
|
+
functionalUpdate(updater, old),
|
|
76
|
+
),
|
|
77
|
+
},
|
|
78
|
+
table_setShowGlobalFilter: {
|
|
79
|
+
fn: (updater: Updater<boolean>) =>
|
|
80
|
+
(
|
|
81
|
+
table.options as MRT_TableOptions_FilterModes
|
|
82
|
+
).onShowGlobalFilterChange?.((old) => functionalUpdate(updater, old)),
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
},
|
|
86
|
+
getDefaultTableOptions: (table) => ({
|
|
87
|
+
onColumnFilterFnsChange: makeStateUpdater('columnFilterFns', table),
|
|
88
|
+
onGlobalFilterFnChange: makeStateUpdater('globalFilterFn', table),
|
|
89
|
+
onShowColumnFiltersChange: makeStateUpdater('showColumnFilters', table),
|
|
90
|
+
onShowGlobalFilterChange: makeStateUpdater('showGlobalFilter', table),
|
|
91
|
+
}),
|
|
92
|
+
getInitialState: (initialState) => ({
|
|
93
|
+
columnFilterFns: {},
|
|
94
|
+
globalFilterFn: 'fuzzy',
|
|
95
|
+
showColumnFilters: false,
|
|
96
|
+
showGlobalFilter: false,
|
|
97
|
+
...initialState,
|
|
98
|
+
}),
|
|
99
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AggregationFnDef,
|
|
3
|
+
type FilterFn,
|
|
4
|
+
type RowData,
|
|
5
|
+
type SortFn,
|
|
6
|
+
type TableFeature,
|
|
7
|
+
type TableFeatures,
|
|
8
|
+
} from '@tanstack/react-table';
|
|
9
|
+
|
|
10
|
+
export interface MRT_TableOptions_Fns {
|
|
11
|
+
aggregationFns?: Record<string, AggregationFnDef<any, any, any, any>>;
|
|
12
|
+
filterFns?: Record<string, FilterFn<any, any>>;
|
|
13
|
+
sortFns?: Record<string, SortFn<any, any>>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare module '@tanstack/react-table' {
|
|
17
|
+
interface Plugins {
|
|
18
|
+
mrtFnsFeature: TableFeature;
|
|
19
|
+
}
|
|
20
|
+
interface TableOptions_FeatureMap<
|
|
21
|
+
TFeatures extends TableFeatures,
|
|
22
|
+
TData extends RowData,
|
|
23
|
+
> {
|
|
24
|
+
mrtFnsFeature: MRT_TableOptions_Fns;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Core resolves string fn names through `table._rowModelFns`, which are the
|
|
30
|
+
* registry objects registered on the features. Custom fns passed as table
|
|
31
|
+
* options are merged over them per table, so a user's `filterFns: { myFn }`
|
|
32
|
+
* keeps resolving from `filterFn: 'myFn'` as it did in v3.
|
|
33
|
+
*/
|
|
34
|
+
export const mrtFnsFeature: TableFeature = {
|
|
35
|
+
initTableInstanceData: (table) => {
|
|
36
|
+
const { aggregationFns, filterFns, sortFns } =
|
|
37
|
+
table.options as MRT_TableOptions_Fns;
|
|
38
|
+
const registries = (table as any)._rowModelFns;
|
|
39
|
+
registries.aggregationFns = {
|
|
40
|
+
...registries.aggregationFns,
|
|
41
|
+
...aggregationFns,
|
|
42
|
+
};
|
|
43
|
+
registries.filterFns = { ...registries.filterFns, ...filterFns };
|
|
44
|
+
registries.sortFns = { ...registries.sortFns, ...sortFns };
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignTableAPIs,
|
|
3
|
+
functionalUpdate,
|
|
4
|
+
makeStateUpdater,
|
|
5
|
+
type OnChangeFn,
|
|
6
|
+
type RowData,
|
|
7
|
+
type TableFeature,
|
|
8
|
+
type TableFeatures,
|
|
9
|
+
type Updater,
|
|
10
|
+
} from '@tanstack/react-table';
|
|
11
|
+
|
|
12
|
+
export interface MRT_Table_FullScreen {
|
|
13
|
+
setIsFullScreen: (updater: Updater<boolean>) => void;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface MRT_TableOptions_FullScreen {
|
|
17
|
+
onIsFullScreenChange?: OnChangeFn<boolean>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export interface MRT_TableState_FullScreen {
|
|
21
|
+
isFullScreen: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
declare module '@tanstack/react-table' {
|
|
25
|
+
interface Plugins {
|
|
26
|
+
mrtFullScreenFeature: TableFeature;
|
|
27
|
+
}
|
|
28
|
+
interface Table_FeatureMap<
|
|
29
|
+
TFeatures extends TableFeatures,
|
|
30
|
+
TData extends RowData,
|
|
31
|
+
> {
|
|
32
|
+
mrtFullScreenFeature: MRT_Table_FullScreen;
|
|
33
|
+
}
|
|
34
|
+
interface TableOptions_FeatureMap<
|
|
35
|
+
TFeatures extends TableFeatures,
|
|
36
|
+
TData extends RowData,
|
|
37
|
+
> {
|
|
38
|
+
mrtFullScreenFeature: MRT_TableOptions_FullScreen;
|
|
39
|
+
}
|
|
40
|
+
interface TableState_FeatureMap {
|
|
41
|
+
mrtFullScreenFeature: MRT_TableState_FullScreen;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export const mrtFullScreenFeature: TableFeature = {
|
|
46
|
+
constructTableAPIs: (table) => {
|
|
47
|
+
assignTableAPIs('mrtFullScreenFeature', table, {
|
|
48
|
+
table_setIsFullScreen: {
|
|
49
|
+
fn: (updater: Updater<boolean>) =>
|
|
50
|
+
(table.options as MRT_TableOptions_FullScreen).onIsFullScreenChange?.(
|
|
51
|
+
(old) => functionalUpdate(updater, old),
|
|
52
|
+
),
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
getDefaultTableOptions: (table) => ({
|
|
57
|
+
onIsFullScreenChange: makeStateUpdater('isFullScreen', table),
|
|
58
|
+
}),
|
|
59
|
+
getInitialState: (initialState) => ({
|
|
60
|
+
isFullScreen: false,
|
|
61
|
+
...initialState,
|
|
62
|
+
}),
|
|
63
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type TableFeature } from '@tanstack/react-table';
|
|
2
|
+
|
|
3
|
+
export interface MRT_TableState_Loading {
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
isSaving: boolean;
|
|
6
|
+
showLoadingOverlay: boolean;
|
|
7
|
+
showProgressBars: boolean;
|
|
8
|
+
showSkeletons: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare module '@tanstack/react-table' {
|
|
12
|
+
interface Plugins {
|
|
13
|
+
mrtLoadingFeature: TableFeature;
|
|
14
|
+
}
|
|
15
|
+
interface TableState_FeatureMap {
|
|
16
|
+
mrtLoadingFeature: MRT_TableState_Loading;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Loading flags are only ever set through the `state` table option, so this
|
|
22
|
+
* feature owns the slices without exposing setters. `showSkeletons` stays
|
|
23
|
+
* undefined by default: an explicit `false` opts out of skeletons while
|
|
24
|
+
* loading, and the key must still be present for core to track the slice.
|
|
25
|
+
*/
|
|
26
|
+
export const mrtLoadingFeature: TableFeature = {
|
|
27
|
+
getInitialState: (initialState) => ({
|
|
28
|
+
isLoading: false,
|
|
29
|
+
isSaving: false,
|
|
30
|
+
showLoadingOverlay: false,
|
|
31
|
+
showProgressBars: false,
|
|
32
|
+
showSkeletons: undefined,
|
|
33
|
+
...initialState,
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type RefObject } from 'react';
|
|
2
|
+
import {
|
|
3
|
+
type RowData,
|
|
4
|
+
type TableFeature,
|
|
5
|
+
type TableFeatures,
|
|
6
|
+
} from '@tanstack/react-table';
|
|
7
|
+
|
|
8
|
+
export interface MRT_Table_Refs {
|
|
9
|
+
refs: MRT_TableRefs;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface MRT_TableRefs {
|
|
13
|
+
actionCellRef: RefObject<HTMLTableCellElement | null>;
|
|
14
|
+
bottomToolbarRef: RefObject<HTMLDivElement | null>;
|
|
15
|
+
editInputRefs: RefObject<null | Record<string, HTMLInputElement>>;
|
|
16
|
+
filterInputRefs: RefObject<null | Record<string, HTMLInputElement>>;
|
|
17
|
+
lastSelectedRowId: RefObject<null | string>;
|
|
18
|
+
searchInputRef: RefObject<HTMLInputElement | null>;
|
|
19
|
+
tableContainerRef: RefObject<HTMLDivElement | null>;
|
|
20
|
+
tableFooterRef: RefObject<HTMLTableSectionElement | null>;
|
|
21
|
+
tableHeadCellRefs: RefObject<null | Record<string, HTMLTableCellElement>>;
|
|
22
|
+
tableHeadRef: RefObject<HTMLTableSectionElement | null>;
|
|
23
|
+
tablePaperRef: RefObject<HTMLDivElement | null>;
|
|
24
|
+
topToolbarRef: RefObject<HTMLDivElement | null>;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
declare module '@tanstack/react-table' {
|
|
28
|
+
interface Plugins {
|
|
29
|
+
mrtRefsFeature: TableFeature;
|
|
30
|
+
}
|
|
31
|
+
interface Table_FeatureMap<
|
|
32
|
+
TFeatures extends TableFeatures,
|
|
33
|
+
TData extends RowData,
|
|
34
|
+
> {
|
|
35
|
+
mrtRefsFeature: MRT_Table_Refs;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The table instance is constructed once per table, so these plain ref objects
|
|
41
|
+
* live as long as the table does.
|
|
42
|
+
*/
|
|
43
|
+
export const mrtRefsFeature: TableFeature = {
|
|
44
|
+
initTableInstanceData: (table) => {
|
|
45
|
+
(table as unknown as MRT_Table_Refs).refs = {
|
|
46
|
+
actionCellRef: { current: null },
|
|
47
|
+
bottomToolbarRef: { current: null },
|
|
48
|
+
editInputRefs: { current: {} },
|
|
49
|
+
filterInputRefs: { current: {} },
|
|
50
|
+
lastSelectedRowId: { current: null },
|
|
51
|
+
searchInputRef: { current: null },
|
|
52
|
+
tableContainerRef: { current: null },
|
|
53
|
+
tableFooterRef: { current: null },
|
|
54
|
+
tableHeadCellRefs: { current: {} },
|
|
55
|
+
tableHeadRef: { current: null },
|
|
56
|
+
tablePaperRef: { current: null },
|
|
57
|
+
topToolbarRef: { current: null },
|
|
58
|
+
};
|
|
59
|
+
},
|
|
60
|
+
};
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignTableAPIs,
|
|
3
|
+
functionalUpdate,
|
|
4
|
+
makeStateUpdater,
|
|
5
|
+
type OnChangeFn,
|
|
6
|
+
type RowData,
|
|
7
|
+
type TableFeature,
|
|
8
|
+
type TableFeatures,
|
|
9
|
+
type Updater,
|
|
10
|
+
} from '@tanstack/react-table';
|
|
11
|
+
import { type MRT_Row } from '../types';
|
|
12
|
+
|
|
13
|
+
export interface MRT_Table_RowDragging<TData extends RowData> {
|
|
14
|
+
setDraggingRow: (updater: Updater<MRT_Row<TData> | null>) => void;
|
|
15
|
+
setHoveredRow: (updater: Updater<null | Partial<MRT_Row<TData>>>) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface MRT_TableOptions_RowDragging<TData extends RowData> {
|
|
19
|
+
onDraggingRowChange?: OnChangeFn<MRT_Row<TData> | null>;
|
|
20
|
+
onHoveredRowChange?: OnChangeFn<null | Partial<MRT_Row<TData>>>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface MRT_TableState_RowDragging {
|
|
24
|
+
draggingRow: MRT_Row<any> | null;
|
|
25
|
+
hoveredRow: null | Partial<MRT_Row<any>>;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare module '@tanstack/react-table' {
|
|
29
|
+
interface Plugins {
|
|
30
|
+
mrtRowDraggingFeature: TableFeature;
|
|
31
|
+
}
|
|
32
|
+
interface Table_FeatureMap<
|
|
33
|
+
TFeatures extends TableFeatures,
|
|
34
|
+
TData extends RowData,
|
|
35
|
+
> {
|
|
36
|
+
mrtRowDraggingFeature: MRT_Table_RowDragging<TData>;
|
|
37
|
+
}
|
|
38
|
+
interface TableOptions_FeatureMap<
|
|
39
|
+
TFeatures extends TableFeatures,
|
|
40
|
+
TData extends RowData,
|
|
41
|
+
> {
|
|
42
|
+
mrtRowDraggingFeature: MRT_TableOptions_RowDragging<TData>;
|
|
43
|
+
}
|
|
44
|
+
interface TableState_FeatureMap {
|
|
45
|
+
mrtRowDraggingFeature: MRT_TableState_RowDragging;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export const mrtRowDraggingFeature: TableFeature = {
|
|
50
|
+
constructTableAPIs: (table) => {
|
|
51
|
+
assignTableAPIs('mrtRowDraggingFeature', table, {
|
|
52
|
+
table_setDraggingRow: {
|
|
53
|
+
fn: (updater: Updater<MRT_Row<any> | null>) =>
|
|
54
|
+
(
|
|
55
|
+
table.options as MRT_TableOptions_RowDragging<any>
|
|
56
|
+
).onDraggingRowChange?.((old) => functionalUpdate(updater, old)),
|
|
57
|
+
},
|
|
58
|
+
table_setHoveredRow: {
|
|
59
|
+
fn: (updater: Updater<null | Partial<MRT_Row<any>>>) =>
|
|
60
|
+
(
|
|
61
|
+
table.options as MRT_TableOptions_RowDragging<any>
|
|
62
|
+
).onHoveredRowChange?.((old) => functionalUpdate(updater, old)),
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
getDefaultTableOptions: (table) => ({
|
|
67
|
+
onDraggingRowChange: makeStateUpdater(
|
|
68
|
+
'draggingRow',
|
|
69
|
+
table,
|
|
70
|
+
) as OnChangeFn<any>,
|
|
71
|
+
onHoveredRowChange: makeStateUpdater(
|
|
72
|
+
'hoveredRow',
|
|
73
|
+
table,
|
|
74
|
+
) as OnChangeFn<any>,
|
|
75
|
+
}),
|
|
76
|
+
getInitialState: (initialState) => ({
|
|
77
|
+
draggingRow: null,
|
|
78
|
+
hoveredRow: null,
|
|
79
|
+
...initialState,
|
|
80
|
+
}),
|
|
81
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import {
|
|
2
|
+
assignTableAPIs,
|
|
3
|
+
type RowData,
|
|
4
|
+
type TableFeature,
|
|
5
|
+
type TableFeatures,
|
|
6
|
+
type TableState,
|
|
7
|
+
} from '@tanstack/react-table';
|
|
8
|
+
|
|
9
|
+
export interface MRT_Table_StateCompat<TFeatures extends TableFeatures> {
|
|
10
|
+
/**
|
|
11
|
+
* Snapshot of the full table state, kept for the v3 public API. Inside MRT
|
|
12
|
+
* read `table.state` instead; it is what the component subscribed to.
|
|
13
|
+
*/
|
|
14
|
+
getState: () => TableState<TFeatures>;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare module '@tanstack/react-table' {
|
|
18
|
+
interface Plugins {
|
|
19
|
+
mrtStateCompatFeature: TableFeature;
|
|
20
|
+
}
|
|
21
|
+
interface Table_FeatureMap<
|
|
22
|
+
TFeatures extends TableFeatures,
|
|
23
|
+
TData extends RowData,
|
|
24
|
+
> {
|
|
25
|
+
mrtStateCompatFeature: MRT_Table_StateCompat<TFeatures>;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const mrtStateCompatFeature: TableFeature = {
|
|
30
|
+
constructTableAPIs: (table) => {
|
|
31
|
+
assignTableAPIs('mrtStateCompatFeature', table, {
|
|
32
|
+
table_getState: { fn: () => table.store.state },
|
|
33
|
+
});
|
|
34
|
+
//`header.getContext()` and `cell.getContext()` hand out the core instance,
|
|
35
|
+
//not the React wrapper that carries the subscribed `state`, so MRT
|
|
36
|
+
//components rendered through `flexRender` need the slice here too
|
|
37
|
+
Object.defineProperty(table, 'state', {
|
|
38
|
+
configurable: true,
|
|
39
|
+
enumerable: false,
|
|
40
|
+
get: () => table.store.state,
|
|
41
|
+
});
|
|
42
|
+
},
|
|
43
|
+
};
|