@cutting/material-react-table 5.0.0 → 5.1.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/README.md +1 -4
- package/dist/index.d.ts +186 -524
- package/dist/index.js +323 -342
- package/dist/index.js.map +1 -1
- package/locales/ar/index.mjs +1 -2
- package/locales/az/index.mjs +1 -2
- package/locales/bg/index.mjs +1 -2
- package/locales/cs/index.mjs +1 -2
- package/locales/da/index.mjs +1 -2
- package/locales/de/index.mjs +1 -2
- package/locales/el/index.mjs +1 -2
- package/locales/en/index.mjs +1 -2
- package/locales/es/index.mjs +1 -2
- package/locales/et/index.mjs +1 -2
- package/locales/fa/index.mjs +1 -2
- package/locales/fi/index.mjs +1 -2
- package/locales/fr/index.mjs +1 -2
- package/locales/he/index.mjs +1 -2
- package/locales/hr/index.mjs +1 -2
- package/locales/hu/index.mjs +1 -2
- package/locales/hy/index.mjs +1 -2
- package/locales/id/index.mjs +1 -2
- package/locales/it/index.mjs +1 -2
- package/locales/ja/index.mjs +1 -2
- package/locales/ko/index.mjs +1 -2
- package/locales/nl/index.mjs +1 -2
- package/locales/no/index.mjs +1 -2
- package/locales/np/index.mjs +1 -2
- package/locales/pl/index.mjs +1 -2
- package/locales/pt/index.mjs +1 -2
- package/locales/pt-BR/index.mjs +1 -2
- package/locales/ro/index.mjs +1 -2
- package/locales/ru/index.mjs +1 -2
- package/locales/sk/index.mjs +1 -2
- package/locales/sr-Cyrl-RS/index.mjs +1 -2
- package/locales/sr-Latn-RS/index.mjs +1 -2
- package/locales/sv/index.mjs +1 -2
- package/locales/tr/index.mjs +1 -2
- package/locales/uk/index.mjs +1 -2
- package/locales/vi/index.mjs +1 -2
- package/locales/zh-Hans/index.mjs +1 -2
- package/locales/zh-Hant/index.mjs +1 -2
- package/package.json +19 -27
- package/src/MaterialReactTable.smoke.test.tsx +3 -9
- package/src/components/MaterialReactTable.tsx +13 -21
- package/src/components/body/MRT_TableBody.tsx +67 -82
- package/src/components/body/MRT_TableBodyCell.tsx +38 -80
- package/src/components/body/MRT_TableBodyCellValue.tsx +5 -14
- package/src/components/body/MRT_TableBodyRow.tsx +55 -102
- package/src/components/body/MRT_TableBodyRowGrabHandle.test.tsx +2 -6
- package/src/components/body/MRT_TableBodyRowGrabHandle.tsx +4 -9
- package/src/components/body/MRT_TableBodyRowPinButton.tsx +8 -14
- package/src/components/body/MRT_TableDetailPanel.test.tsx +3 -9
- package/src/components/body/MRT_TableDetailPanel.tsx +8 -14
- package/src/components/buttons/MRT_ColumnPinningButtons.test.tsx +6 -16
- package/src/components/buttons/MRT_ColumnPinningButtons.tsx +6 -12
- package/src/components/buttons/MRT_CopyButton.tsx +7 -15
- package/src/components/buttons/MRT_EditActionButtons.test.tsx +2 -6
- package/src/components/buttons/MRT_EditActionButtons.tsx +15 -37
- package/src/components/buttons/MRT_ExpandAllButton.tsx +8 -16
- package/src/components/buttons/MRT_ExpandButton.tsx +9 -21
- package/src/components/buttons/MRT_GrabHandleButton.tsx +6 -10
- package/src/components/buttons/MRT_RowPinButton.tsx +8 -23
- package/src/components/buttons/MRT_ShowHideColumnsButton.tsx +5 -18
- package/src/components/buttons/MRT_ToggleDensePaddingButton.test.tsx +4 -12
- package/src/components/buttons/MRT_ToggleDensePaddingButton.tsx +4 -11
- package/src/components/buttons/MRT_ToggleFiltersButton.test.tsx +4 -13
- package/src/components/buttons/MRT_ToggleFiltersButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleFullScreenButton.test.tsx +3 -11
- package/src/components/buttons/MRT_ToggleFullScreenButton.tsx +4 -9
- package/src/components/buttons/MRT_ToggleGlobalFilterButton.tsx +3 -5
- package/src/components/buttons/MRT_ToggleRowActionMenuButton.tsx +7 -15
- package/src/components/footer/MRT_TableFooter.tsx +9 -16
- package/src/components/footer/MRT_TableFooterCell.tsx +9 -32
- package/src/components/footer/MRT_TableFooterRow.tsx +18 -32
- package/src/components/head/MRT_TableHead.tsx +8 -18
- package/src/components/head/MRT_TableHeadCell.tsx +46 -100
- package/src/components/head/MRT_TableHeadCellColumnActionsButton.tsx +10 -30
- package/src/components/head/MRT_TableHeadCellFilterContainer.tsx +4 -15
- package/src/components/head/MRT_TableHeadCellFilterLabel.tsx +20 -54
- package/src/components/head/MRT_TableHeadCellGrabHandle.test.tsx +5 -19
- package/src/components/head/MRT_TableHeadCellGrabHandle.tsx +9 -38
- package/src/components/head/MRT_TableHeadCellResizeHandle.test.tsx +3 -13
- package/src/components/head/MRT_TableHeadCellResizeHandle.tsx +10 -24
- package/src/components/head/MRT_TableHeadCellSortLabel.tsx +10 -26
- package/src/components/head/MRT_TableHeadRow.tsx +24 -36
- package/src/components/inputs/MRT_EditCellTextField.test.tsx +2 -9
- package/src/components/inputs/MRT_EditCellTextField.tsx +9 -28
- package/src/components/inputs/MRT_FilterCheckbox.tsx +9 -23
- package/src/components/inputs/MRT_FilterRangeFields.tsx +6 -15
- package/src/components/inputs/MRT_FilterRangeSlider.tsx +24 -32
- package/src/components/inputs/MRT_FilterTextField.test.tsx +72 -14
- package/src/components/inputs/MRT_FilterTextField.tsx +77 -138
- package/src/components/inputs/MRT_GlobalFilterTextField.tsx +10 -32
- package/src/components/inputs/MRT_SelectCheckbox.test.tsx +4 -11
- package/src/components/inputs/MRT_SelectCheckbox.tsx +17 -36
- package/src/components/menus/MRT_ActionMenuItem.tsx +6 -15
- package/src/components/menus/MRT_CellActionMenu.tsx +6 -9
- package/src/components/menus/MRT_ColumnActionMenu.tsx +22 -57
- package/src/components/menus/MRT_FilterOptionMenu.tsx +38 -65
- package/src/components/menus/MRT_RowActionMenu.tsx +33 -22
- package/src/components/menus/MRT_ShowHideColumnsMenu.tsx +29 -65
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.test.tsx +43 -0
- package/src/components/menus/MRT_ShowHideColumnsMenuItems.tsx +14 -50
- package/src/components/modals/MRT_EditRowModal.test.tsx +5 -21
- package/src/components/modals/MRT_EditRowModal.tsx +8 -26
- package/src/components/table/MRT_Table.tsx +12 -20
- package/src/components/table/MRT_TableContainer.test.tsx +147 -0
- package/src/components/table/MRT_TableContainer.tsx +33 -37
- package/src/components/table/MRT_TableLoadingOverlay.tsx +3 -5
- package/src/components/table/MRT_TablePaper.tsx +7 -14
- package/src/components/toolbar/MRT_BottomToolbar.tsx +11 -23
- package/src/components/toolbar/MRT_LinearProgressBar.tsx +4 -11
- package/src/components/toolbar/MRT_TablePagination.tsx +33 -40
- package/src/components/toolbar/MRT_ToolbarAlertBanner.tsx +21 -50
- package/src/components/toolbar/MRT_ToolbarDropZone.test.tsx +26 -10
- package/src/components/toolbar/MRT_ToolbarDropZone.tsx +23 -21
- package/src/components/toolbar/MRT_ToolbarInternalButtons.tsx +11 -21
- package/src/components/toolbar/MRT_TopToolbar.tsx +12 -28
- package/src/fns/aggregationFns.test.tsx +1 -3
- package/src/fns/filterFns.test.tsx +8 -37
- package/src/fns/filterFns.ts +71 -96
- package/src/fns/sortingFns.test.tsx +5 -21
- package/src/fns/sortingFns.ts +10 -14
- package/src/fns/tableFeatures.test.tsx +6 -29
- package/src/fns/tableFeatures.ts +5 -4
- package/src/hooks/display-columns/getMRT_RowActionsColumnDef.tsx +2 -11
- package/src/hooks/display-columns/getMRT_RowDragColumnDef.tsx +2 -10
- package/src/hooks/display-columns/getMRT_RowExpandColumnDef.tsx +8 -17
- package/src/hooks/display-columns/getMRT_RowNumbersColumnDef.tsx +3 -8
- package/src/hooks/display-columns/getMRT_RowPinningColumnDef.tsx +2 -8
- package/src/hooks/display-columns/getMRT_RowSelectColumnDef.tsx +3 -13
- package/src/hooks/display-columns/getMRT_RowSpacerColumnDef.tsx +1 -5
- package/src/hooks/useMRT_ColumnVirtualizer.ts +28 -49
- package/src/hooks/useMRT_Effects.test.tsx +114 -0
- package/src/hooks/useMRT_Effects.ts +26 -27
- package/src/hooks/useMRT_RowVirtualizer.ts +18 -33
- package/src/hooks/useMRT_Rows.ts +3 -42
- package/src/hooks/useMRT_TableInstance.ts +63 -129
- package/src/hooks/useMRT_TableOptions.ts +15 -29
- package/src/hooks/useMaterialReactTable.ts +2 -7
- package/src/icons.ts +38 -1
- package/src/index.ts +0 -4
- package/src/locales/ar.ts +1 -2
- package/src/locales/az.ts +1 -2
- package/src/locales/bg.ts +1 -2
- package/src/locales/cs.ts +2 -4
- package/src/locales/da.ts +1 -2
- package/src/locales/de.ts +1 -2
- package/src/locales/el.ts +1 -2
- package/src/locales/en.ts +1 -2
- package/src/locales/es.ts +1 -2
- package/src/locales/et.ts +2 -4
- package/src/locales/fa.ts +1 -2
- package/src/locales/fi.ts +2 -4
- package/src/locales/fr.ts +1 -2
- package/src/locales/he.ts +1 -2
- package/src/locales/hr.ts +1 -2
- package/src/locales/hu.ts +1 -2
- package/src/locales/hy.ts +1 -2
- package/src/locales/id.ts +2 -4
- package/src/locales/it.ts +1 -2
- package/src/locales/ja.ts +1 -2
- package/src/locales/ko.ts +1 -2
- package/src/locales/nl.ts +1 -2
- package/src/locales/no.ts +2 -4
- package/src/locales/np.ts +2 -4
- package/src/locales/pl.ts +1 -2
- package/src/locales/pt-BR.ts +1 -2
- package/src/locales/pt.ts +1 -2
- package/src/locales/ro.ts +1 -2
- package/src/locales/ru.ts +1 -2
- package/src/locales/sk.ts +2 -4
- package/src/locales/sr-Cyrl-RS.ts +1 -2
- package/src/locales/sr-Latn-RS.ts +1 -2
- package/src/locales/sv.ts +1 -2
- package/src/locales/tr.ts +1 -2
- package/src/locales/uk.ts +1 -2
- package/src/locales/vi.ts +1 -2
- package/src/types.ts +156 -349
- package/src/utils/cell.utils.ts +30 -68
- package/src/utils/column.utils.ts +61 -49
- package/src/utils/displayColumn.utils.ts +16 -38
- package/src/utils/highlight.utils.ts +7 -11
- package/src/utils/row.utils.ts +40 -65
- package/src/utils/slotProps.utils.ts +1 -4
- package/src/utils/style.utils.ts +18 -46
- package/src/utils/tanstack.helpers.ts +10 -17
- package/src/utils/utils.ts +6 -10
- package/src/utils/virtualization.utils.ts +5 -9
package/src/utils/cell.utils.ts
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
type MRT_Header,
|
|
4
|
-
type MRT_RowData,
|
|
5
|
-
type MRT_TableInstance,
|
|
6
|
-
} from '../types';
|
|
7
|
-
import {
|
|
8
|
-
getMRT_RowSelectionHandler,
|
|
9
|
-
getMRT_SelectAllHandler,
|
|
10
|
-
} from './row.utils';
|
|
1
|
+
import { type MRT_Cell, type MRT_Header, type MRT_RowData, type MRT_TableInstance } from '../types';
|
|
2
|
+
import { getMRT_RowSelectionHandler, getMRT_SelectAllHandler } from './row.utils';
|
|
11
3
|
import { parseFromValuesOrFunc } from './utils';
|
|
12
4
|
|
|
13
5
|
const isWinCtrlMacMeta = (event: React.KeyboardEvent<HTMLTableCellElement>) => {
|
|
@@ -23,7 +15,7 @@ export const isCellEditable = <TData extends MRT_RowData>({
|
|
|
23
15
|
}: {
|
|
24
16
|
cell: MRT_Cell<TData>;
|
|
25
17
|
table: MRT_TableInstance<TData>;
|
|
26
|
-
}) => {
|
|
18
|
+
}): boolean | undefined => {
|
|
27
19
|
const { enableEditing } = table.options;
|
|
28
20
|
const {
|
|
29
21
|
column: { columnDef },
|
|
@@ -42,7 +34,7 @@ export const openEditingCell = <TData extends MRT_RowData>({
|
|
|
42
34
|
}: {
|
|
43
35
|
cell: MRT_Cell<TData>;
|
|
44
36
|
table: MRT_TableInstance<TData>;
|
|
45
|
-
}) => {
|
|
37
|
+
}): void => {
|
|
46
38
|
const {
|
|
47
39
|
options: { editDisplayMode },
|
|
48
40
|
refs: { editInputRefs },
|
|
@@ -79,9 +71,13 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
|
|
|
79
71
|
header?: MRT_Header<TData>;
|
|
80
72
|
parentElement?: HTMLTableRowElement;
|
|
81
73
|
table: MRT_TableInstance<TData>;
|
|
82
|
-
}) => {
|
|
83
|
-
if (!table.options.enableKeyboardShortcuts)
|
|
84
|
-
|
|
74
|
+
}): void => {
|
|
75
|
+
if (!table.options.enableKeyboardShortcuts) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (event.isPropagationStopped()) {
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
85
81
|
const currentCell = event.currentTarget;
|
|
86
82
|
|
|
87
83
|
if (cellValue && isWinCtrlMacMeta(event) && event.key === 'c') {
|
|
@@ -91,40 +87,30 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
|
|
|
91
87
|
event.preventDefault();
|
|
92
88
|
getMRT_RowSelectionHandler({
|
|
93
89
|
row: cell.row,
|
|
94
|
-
|
|
95
|
-
staticRowIndex: +event.target.getAttribute('data-index'),
|
|
90
|
+
staticRowIndex: Number((event.target as HTMLElement).getAttribute('data-index')),
|
|
96
91
|
table,
|
|
97
|
-
})(event
|
|
98
|
-
} else if (
|
|
99
|
-
header?.column?.id === 'mrt-row-select' &&
|
|
100
|
-
table.options.enableSelectAll
|
|
101
|
-
) {
|
|
92
|
+
})(event);
|
|
93
|
+
} else if (header?.column?.id === 'mrt-row-select' && table.options.enableSelectAll) {
|
|
102
94
|
event.preventDefault();
|
|
103
95
|
getMRT_SelectAllHandler({
|
|
104
96
|
table,
|
|
105
|
-
})(event
|
|
97
|
+
})(event);
|
|
106
98
|
} else if (
|
|
107
99
|
cell?.column?.id === 'mrt-row-expand' &&
|
|
108
|
-
(cell.row.getCanExpand() ||
|
|
109
|
-
table.options.renderDetailPanel?.({ row: cell.row, table }))
|
|
100
|
+
(cell.row.getCanExpand() || table.options.renderDetailPanel?.({ row: cell.row, table }))
|
|
110
101
|
) {
|
|
111
102
|
event.preventDefault();
|
|
112
103
|
cell.row.toggleExpanded();
|
|
113
|
-
} else if (
|
|
114
|
-
header?.column?.id === 'mrt-row-expand' &&
|
|
115
|
-
table.options.enableExpandAll
|
|
116
|
-
) {
|
|
104
|
+
} else if (header?.column?.id === 'mrt-row-expand' && table.options.enableExpandAll) {
|
|
117
105
|
event.preventDefault();
|
|
118
106
|
table.toggleAllRowsExpanded();
|
|
119
107
|
} else if (cell?.column.id === 'mrt-row-pin') {
|
|
120
108
|
event.preventDefault();
|
|
121
|
-
cell.row.getIsPinned()
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
: 'top',
|
|
127
|
-
);
|
|
109
|
+
if (cell.row.getIsPinned()) {
|
|
110
|
+
cell.row.pin(false);
|
|
111
|
+
} else {
|
|
112
|
+
cell.row.pin(table.options.rowPinningDisplayMode?.includes('bottom') ? 'bottom' : 'top');
|
|
113
|
+
}
|
|
128
114
|
} else if (header && isWinCtrlMacMeta(event)) {
|
|
129
115
|
const actionsButton = currentCell.querySelector(
|
|
130
116
|
`button[aria-label="${table.options.localization.columnActions}"]`,
|
|
@@ -137,29 +123,16 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
|
|
|
137
123
|
header.column.toggleSorting();
|
|
138
124
|
}
|
|
139
125
|
} else if (
|
|
140
|
-
[
|
|
141
|
-
'ArrowDown',
|
|
142
|
-
'ArrowLeft',
|
|
143
|
-
'ArrowRight',
|
|
144
|
-
'ArrowUp',
|
|
145
|
-
'End',
|
|
146
|
-
'Home',
|
|
147
|
-
'PageDown',
|
|
148
|
-
'PageUp',
|
|
149
|
-
].includes(event.key)
|
|
126
|
+
['ArrowDown', 'ArrowLeft', 'ArrowRight', 'ArrowUp', 'End', 'Home', 'PageDown', 'PageUp'].includes(event.key)
|
|
150
127
|
) {
|
|
151
128
|
event.preventDefault();
|
|
152
129
|
|
|
153
130
|
const currentRow = parentElement || currentCell.closest('tr');
|
|
154
131
|
const tableElement = containerElement || currentCell.closest('table');
|
|
155
|
-
const allCells =
|
|
156
|
-
cellElements ||
|
|
157
|
-
Array.from(tableElement?.querySelectorAll('th, td') || []);
|
|
132
|
+
const allCells = cellElements || Array.from(tableElement?.querySelectorAll('th, td') || []);
|
|
158
133
|
const currentCellIndex = allCells.indexOf(currentCell);
|
|
159
134
|
|
|
160
|
-
const currentIndex = parseInt(
|
|
161
|
-
currentCell.getAttribute('data-index') || '0',
|
|
162
|
-
);
|
|
135
|
+
const currentIndex = parseInt(currentCell.getAttribute('data-index') || '0');
|
|
163
136
|
let nextCell: HTMLElement | undefined = undefined;
|
|
164
137
|
|
|
165
138
|
//home/end first or last cell in row
|
|
@@ -171,33 +144,22 @@ export const cellKeyboardShortcuts = <TData extends MRT_RowData = MRT_RowData>({
|
|
|
171
144
|
? tableElement?.querySelector('tr')
|
|
172
145
|
: tableElement?.lastElementChild?.lastElementChild;
|
|
173
146
|
const rowCells = Array.from(row?.children || []);
|
|
174
|
-
const targetCell =
|
|
175
|
-
edge === 'f' ? rowCells[0] : rowCells[rowCells.length - 1];
|
|
147
|
+
const targetCell = edge === 'f' ? rowCells[0] : rowCells[rowCells.length - 1];
|
|
176
148
|
return targetCell as HTMLElement;
|
|
177
149
|
};
|
|
178
150
|
|
|
179
151
|
//page up/down first or last cell in column
|
|
180
152
|
const findBottomTopCell = (columnIndex: number, edge: 'b' | 't') => {
|
|
181
|
-
const row =
|
|
182
|
-
edge === 't'
|
|
183
|
-
? tableElement?.querySelector('tr')
|
|
184
|
-
: tableElement?.lastElementChild?.lastElementChild;
|
|
153
|
+
const row = edge === 't' ? tableElement?.querySelector('tr') : tableElement?.lastElementChild?.lastElementChild;
|
|
185
154
|
const rowCells = Array.from(row?.children || []);
|
|
186
155
|
const targetCell = rowCells[columnIndex];
|
|
187
156
|
return targetCell as HTMLElement;
|
|
188
157
|
};
|
|
189
158
|
|
|
190
|
-
const findAdjacentCell = (
|
|
191
|
-
columnIndex: number,
|
|
192
|
-
searchDirection: 'b' | 'f',
|
|
193
|
-
) => {
|
|
159
|
+
const findAdjacentCell = (columnIndex: number, searchDirection: 'b' | 'f') => {
|
|
194
160
|
const searchArray =
|
|
195
|
-
searchDirection === 'f'
|
|
196
|
-
|
|
197
|
-
: allCells.slice(0, currentCellIndex).reverse();
|
|
198
|
-
return searchArray.find((cell) =>
|
|
199
|
-
cell.matches(`[data-index="${columnIndex}"]`),
|
|
200
|
-
) as HTMLElement | undefined;
|
|
161
|
+
searchDirection === 'f' ? allCells.slice(currentCellIndex + 1) : allCells.slice(0, currentCellIndex).reverse();
|
|
162
|
+
return searchArray.find((cell) => cell.matches(`[data-index="${columnIndex}"]`)) as HTMLElement | undefined;
|
|
201
163
|
};
|
|
202
164
|
|
|
203
165
|
switch (event.key) {
|
|
@@ -9,23 +9,17 @@ import {
|
|
|
9
9
|
type MRT_DefinedTableOptions,
|
|
10
10
|
type MRT_FilterOption,
|
|
11
11
|
type MRT_Header,
|
|
12
|
+
type MRT_Localization,
|
|
12
13
|
type MRT_RowData,
|
|
13
14
|
type MRT_TableInstance,
|
|
14
15
|
} from '../types';
|
|
15
16
|
|
|
16
17
|
export const getSubColumnDefs = <TData extends MRT_RowData>(
|
|
17
18
|
columnDef: MRT_ColumnDef<TData>,
|
|
18
|
-
): ReadonlyArray<MRT_ColumnDef<TData>> | undefined =>
|
|
19
|
-
'columns' in columnDef ? columnDef.columns : undefined;
|
|
19
|
+
): ReadonlyArray<MRT_ColumnDef<TData>> | undefined => ('columns' in columnDef ? columnDef.columns : undefined);
|
|
20
20
|
|
|
21
|
-
export const getColumnId = <TData extends MRT_RowData>(
|
|
22
|
-
columnDef:
|
|
23
|
-
): string =>
|
|
24
|
-
columnDef.id ??
|
|
25
|
-
('accessorKey' in columnDef
|
|
26
|
-
? columnDef.accessorKey?.toString?.()
|
|
27
|
-
: undefined) ??
|
|
28
|
-
columnDef.header;
|
|
21
|
+
export const getColumnId = <TData extends MRT_RowData>(columnDef: MRT_ColumnDef<TData>): string =>
|
|
22
|
+
columnDef.id ?? ('accessorKey' in columnDef ? columnDef.accessorKey?.toString?.() : undefined) ?? columnDef.header;
|
|
29
23
|
|
|
30
24
|
export const getAllLeafColumnDefs = <TData extends MRT_RowData>(
|
|
31
25
|
columns: ReadonlyArray<MRT_ColumnDef<TData>>,
|
|
@@ -61,9 +55,13 @@ export const prepareColumns = <TData extends MRT_RowData>({
|
|
|
61
55
|
} = tableOptions;
|
|
62
56
|
return columnDefs.map((columnDef) => {
|
|
63
57
|
//assign columnId
|
|
64
|
-
if (!columnDef.id)
|
|
58
|
+
if (!columnDef.id) {
|
|
59
|
+
columnDef.id = getColumnId(columnDef);
|
|
60
|
+
}
|
|
65
61
|
//assign columnDefType
|
|
66
|
-
if (!columnDef.columnDefType)
|
|
62
|
+
if (!columnDef.columnDefType) {
|
|
63
|
+
columnDef.columnDefType = 'data';
|
|
64
|
+
}
|
|
67
65
|
const subColumnDefs = getSubColumnDefs(columnDef);
|
|
68
66
|
if (subColumnDefs?.length && 'columns' in columnDef) {
|
|
69
67
|
columnDef.columnDefType = 'group';
|
|
@@ -77,17 +75,14 @@ export const prepareColumns = <TData extends MRT_RowData>({
|
|
|
77
75
|
if (Array.isArray(columnDef.aggregationFn)) {
|
|
78
76
|
const aggFns = columnDef.aggregationFn as string[];
|
|
79
77
|
columnDef.aggregationFn = {
|
|
80
|
-
aggregate: (context) =>
|
|
81
|
-
aggFns.map((fn) => aggregationFns[fn]?.aggregate(context)),
|
|
78
|
+
aggregate: (context) => aggFns.map((fn) => aggregationFns[fn]?.aggregate(context)),
|
|
82
79
|
};
|
|
83
80
|
}
|
|
84
81
|
|
|
85
82
|
//assign filterFns
|
|
86
83
|
if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
|
|
87
|
-
columnDef.filterFn =
|
|
88
|
-
|
|
89
|
-
(columnDef as MRT_DefinedColumnDef<TData>)._filterFn =
|
|
90
|
-
columnFilterFns[columnDef.id];
|
|
84
|
+
columnDef.filterFn = filterFns[columnFilterFns[columnDef.id]] ?? filterFns.fuzzy;
|
|
85
|
+
(columnDef as MRT_DefinedColumnDef<TData>)._filterFn = columnFilterFns[columnDef.id];
|
|
91
86
|
}
|
|
92
87
|
|
|
93
88
|
//assign sortFns
|
|
@@ -121,24 +116,57 @@ export const reorderColumn = <TData extends MRT_RowData>(
|
|
|
121
116
|
return newColumnOrder;
|
|
122
117
|
};
|
|
123
118
|
|
|
119
|
+
export const moveColumn = <TData extends MRT_RowData>(
|
|
120
|
+
table: MRT_TableInstance<TData>,
|
|
121
|
+
draggedColumn: MRT_Column<TData>,
|
|
122
|
+
targetColumn: MRT_Column<TData>,
|
|
123
|
+
): void => {
|
|
124
|
+
const reorderedColumns = reorderColumn(draggedColumn, targetColumn, table.state.columnOrder);
|
|
125
|
+
table.setColumnOrder(reorderedColumns);
|
|
126
|
+
table.setColumnPinning(({ end = [], start = [] }) => ({
|
|
127
|
+
end: reorderedColumns.filter((header) => end.includes(header)),
|
|
128
|
+
start: reorderedColumns.filter((header) => start.includes(header)),
|
|
129
|
+
}));
|
|
130
|
+
};
|
|
131
|
+
|
|
124
132
|
export const getDefaultColumnFilterFn = <TData extends MRT_RowData>(
|
|
125
133
|
columnDef: Pick<MRT_ColumnDef<TData>, 'filterVariant'>,
|
|
126
134
|
): MRT_FilterOption => {
|
|
127
135
|
const { filterVariant } = columnDef;
|
|
128
|
-
if (filterVariant === 'multi-select')
|
|
129
|
-
|
|
130
|
-
|
|
136
|
+
if (filterVariant === 'multi-select') {
|
|
137
|
+
return 'arrIncludesSome';
|
|
138
|
+
}
|
|
139
|
+
if (filterVariant?.includes('range')) {
|
|
140
|
+
return 'betweenInclusive';
|
|
141
|
+
}
|
|
142
|
+
if (filterVariant === 'select' || filterVariant === 'checkbox') {
|
|
131
143
|
return 'equals';
|
|
144
|
+
}
|
|
132
145
|
return 'fuzzy';
|
|
133
146
|
};
|
|
134
147
|
|
|
148
|
+
export interface MRT_ColumnFilterInfo<TData extends MRT_RowData> {
|
|
149
|
+
allowedColumnFilterOptions: MRT_ColumnDef<TData>['columnFilterModeOptions'];
|
|
150
|
+
currentFilterOption: MRT_FilterOption;
|
|
151
|
+
facetedUniqueValues: ReturnType<MRT_Column<TData>['getFacetedUniqueValues']>;
|
|
152
|
+
isAutocompleteFilter: boolean;
|
|
153
|
+
isDateFilter: boolean;
|
|
154
|
+
isMultiSelectFilter: boolean;
|
|
155
|
+
isRangeFilter: boolean;
|
|
156
|
+
isSelectFilter: boolean;
|
|
157
|
+
isTextboxFilter: boolean;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export const getFilterOptionLabel = (localization: MRT_Localization, filterOption: MRT_FilterOption): string =>
|
|
161
|
+
localization[`filter${filterOption.charAt(0).toUpperCase() + filterOption.slice(1)}` as keyof MRT_Localization];
|
|
162
|
+
|
|
135
163
|
export const getColumnFilterInfo = <TData extends MRT_RowData>({
|
|
136
164
|
header,
|
|
137
165
|
table,
|
|
138
166
|
}: {
|
|
139
167
|
header: MRT_Header<TData>;
|
|
140
168
|
table: MRT_TableInstance<TData>;
|
|
141
|
-
}) => {
|
|
169
|
+
}): MRT_ColumnFilterInfo<TData> => {
|
|
142
170
|
const {
|
|
143
171
|
options: { columnFilterModeOptions },
|
|
144
172
|
} = table;
|
|
@@ -146,26 +174,18 @@ export const getColumnFilterInfo = <TData extends MRT_RowData>({
|
|
|
146
174
|
const { columnDef } = column;
|
|
147
175
|
const { filterVariant } = columnDef;
|
|
148
176
|
|
|
149
|
-
const isDateFilter = !!(
|
|
150
|
-
filterVariant?.startsWith('date') || filterVariant?.startsWith('time')
|
|
151
|
-
);
|
|
177
|
+
const isDateFilter = !!(filterVariant?.startsWith('date') || filterVariant?.startsWith('time'));
|
|
152
178
|
const isAutocompleteFilter = filterVariant === 'autocomplete';
|
|
153
|
-
const currentFilterOption =
|
|
154
|
-
columnDef._filterFn ?? getDefaultColumnFilterFn(columnDef);
|
|
179
|
+
const currentFilterOption = columnDef._filterFn ?? getDefaultColumnFilterFn(columnDef);
|
|
155
180
|
|
|
156
181
|
const isRangeFilter =
|
|
157
|
-
filterVariant?.includes('range') ||
|
|
158
|
-
['between', 'betweenInclusive', 'inNumberRange'].includes(
|
|
159
|
-
currentFilterOption,
|
|
160
|
-
);
|
|
182
|
+
filterVariant?.includes('range') || ['between', 'betweenInclusive', 'inNumberRange'].includes(currentFilterOption);
|
|
161
183
|
const isSelectFilter = filterVariant === 'select';
|
|
162
184
|
const isMultiSelectFilter = filterVariant === 'multi-select';
|
|
163
185
|
const isTextboxFilter =
|
|
164
|
-
['autocomplete', 'text'].includes(filterVariant!) ||
|
|
165
|
-
(!isSelectFilter && !isMultiSelectFilter);
|
|
186
|
+
['autocomplete', 'text'].includes(filterVariant!) || (!isSelectFilter && !isMultiSelectFilter);
|
|
166
187
|
|
|
167
|
-
const allowedColumnFilterOptions =
|
|
168
|
-
columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
|
|
188
|
+
const allowedColumnFilterOptions = columnDef?.columnFilterModeOptions ?? columnFilterModeOptions;
|
|
169
189
|
|
|
170
190
|
const facetedUniqueValues = column.getFacetedUniqueValues();
|
|
171
191
|
|
|
@@ -191,27 +211,19 @@ export const useDropdownOptions = <TData extends MRT_RowData>({
|
|
|
191
211
|
}): DropdownOption[] | undefined => {
|
|
192
212
|
const { column } = header;
|
|
193
213
|
const { columnDef } = column;
|
|
194
|
-
const {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
isSelectFilter,
|
|
199
|
-
} = getColumnFilterInfo({ header, table });
|
|
214
|
+
const { facetedUniqueValues, isAutocompleteFilter, isMultiSelectFilter, isSelectFilter } = getColumnFilterInfo({
|
|
215
|
+
header,
|
|
216
|
+
table,
|
|
217
|
+
});
|
|
200
218
|
|
|
201
219
|
return useMemo<DropdownOption[] | undefined>(
|
|
202
220
|
() =>
|
|
203
221
|
columnDef.filterSelectOptions ??
|
|
204
|
-
((isSelectFilter || isMultiSelectFilter || isAutocompleteFilter) &&
|
|
205
|
-
facetedUniqueValues
|
|
222
|
+
((isSelectFilter || isMultiSelectFilter || isAutocompleteFilter) && facetedUniqueValues
|
|
206
223
|
? Array.from(facetedUniqueValues.keys())
|
|
207
224
|
.filter((value) => value !== null && value !== undefined)
|
|
208
225
|
.sort((a, b) => a.localeCompare(b))
|
|
209
226
|
: undefined),
|
|
210
|
-
[
|
|
211
|
-
columnDef.filterSelectOptions,
|
|
212
|
-
facetedUniqueValues,
|
|
213
|
-
isMultiSelectFilter,
|
|
214
|
-
isSelectFilter,
|
|
215
|
-
],
|
|
227
|
+
[columnDef.filterSelectOptions, facetedUniqueValues, isAutocompleteFilter, isMultiSelectFilter, isSelectFilter],
|
|
216
228
|
);
|
|
217
229
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
type MRT_DefinedTableOptions,
|
|
3
|
+
type MRT_DisplayColumnDef,
|
|
3
4
|
type MRT_DisplayColumnIds,
|
|
4
5
|
type MRT_Localization,
|
|
5
6
|
type MRT_RowData,
|
|
@@ -17,9 +18,8 @@ export function defaultDisplayColumnProps<TData extends MRT_RowData>({
|
|
|
17
18
|
id: MRT_DisplayColumnIds;
|
|
18
19
|
size: number;
|
|
19
20
|
tableOptions: MRT_DefinedTableOptions<TData>;
|
|
20
|
-
}) {
|
|
21
|
-
const { defaultDisplayColumn, displayColumnDefOptions, localization } =
|
|
22
|
-
tableOptions;
|
|
21
|
+
}): Partial<MRT_DisplayColumnDef<TData>> & { header: string; id: MRT_DisplayColumnIds; size: number } {
|
|
22
|
+
const { defaultDisplayColumn, displayColumnDefOptions, localization } = tableOptions;
|
|
23
23
|
return {
|
|
24
24
|
...defaultDisplayColumn,
|
|
25
25
|
header: header ? localization[header]! : '',
|
|
@@ -52,11 +52,7 @@ export const showRowExpandColumn = <TData extends MRT_RowData>(
|
|
|
52
52
|
renderDetailPanel,
|
|
53
53
|
state: { grouping },
|
|
54
54
|
} = tableOptions;
|
|
55
|
-
return !!(
|
|
56
|
-
enableExpanding ||
|
|
57
|
-
(enableGrouping && grouping?.length) ||
|
|
58
|
-
renderDetailPanel
|
|
59
|
-
);
|
|
55
|
+
return !!(enableExpanding || (enableGrouping && grouping?.length) || renderDetailPanel);
|
|
60
56
|
};
|
|
61
57
|
|
|
62
58
|
export const showRowActionsColumn = <TData extends MRT_RowData>(
|
|
@@ -90,63 +86,45 @@ export const showRowSpacerColumn = <TData extends MRT_RowData>(
|
|
|
90
86
|
|
|
91
87
|
export const getLeadingDisplayColumnIds = <TData extends MRT_RowData>(
|
|
92
88
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
93
|
-
) =>
|
|
89
|
+
): MRT_DisplayColumnIds[] =>
|
|
94
90
|
[
|
|
95
91
|
showRowPinningColumn(tableOptions) && 'mrt-row-pin',
|
|
96
92
|
showRowDragColumn(tableOptions) && 'mrt-row-drag',
|
|
97
|
-
tableOptions.positionActionsColumn === 'first' &&
|
|
98
|
-
|
|
99
|
-
'mrt-row-actions',
|
|
100
|
-
tableOptions.positionExpandColumn === 'first' &&
|
|
101
|
-
showRowExpandColumn(tableOptions) &&
|
|
102
|
-
'mrt-row-expand',
|
|
93
|
+
tableOptions.positionActionsColumn === 'first' && showRowActionsColumn(tableOptions) && 'mrt-row-actions',
|
|
94
|
+
tableOptions.positionExpandColumn === 'first' && showRowExpandColumn(tableOptions) && 'mrt-row-expand',
|
|
103
95
|
showRowSelectionColumn(tableOptions) && 'mrt-row-select',
|
|
104
96
|
showRowNumbersColumn(tableOptions) && 'mrt-row-numbers',
|
|
105
97
|
].filter(Boolean) as MRT_DisplayColumnIds[];
|
|
106
98
|
|
|
107
99
|
export const getTrailingDisplayColumnIds = <TData extends MRT_RowData>(
|
|
108
100
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
109
|
-
) =>
|
|
101
|
+
): MRT_DisplayColumnIds[] =>
|
|
110
102
|
[
|
|
111
|
-
tableOptions.positionActionsColumn === 'last' &&
|
|
112
|
-
|
|
113
|
-
'mrt-row-actions',
|
|
114
|
-
tableOptions.positionExpandColumn === 'last' &&
|
|
115
|
-
showRowExpandColumn(tableOptions) &&
|
|
116
|
-
'mrt-row-expand',
|
|
103
|
+
tableOptions.positionActionsColumn === 'last' && showRowActionsColumn(tableOptions) && 'mrt-row-actions',
|
|
104
|
+
tableOptions.positionExpandColumn === 'last' && showRowExpandColumn(tableOptions) && 'mrt-row-expand',
|
|
117
105
|
showRowSpacerColumn(tableOptions) && 'mrt-row-spacer',
|
|
118
106
|
].filter(Boolean) as MRT_DisplayColumnIds[];
|
|
119
107
|
|
|
120
108
|
export const getDefaultColumnOrderIds = <TData extends MRT_RowData>(
|
|
121
109
|
tableOptions: MRT_StatefulTableOptions<TData>,
|
|
122
110
|
reset = false,
|
|
123
|
-
) => {
|
|
111
|
+
): string[] => {
|
|
124
112
|
const {
|
|
125
113
|
state: { columnOrder: currentColumnOrderIds = [] },
|
|
126
114
|
} = tableOptions;
|
|
127
115
|
|
|
128
|
-
const leadingDisplayColIds: string[] =
|
|
129
|
-
|
|
130
|
-
const trailingDisplayColIds: string[] =
|
|
131
|
-
getTrailingDisplayColumnIds(tableOptions);
|
|
116
|
+
const leadingDisplayColIds: string[] = getLeadingDisplayColumnIds(tableOptions);
|
|
117
|
+
const trailingDisplayColIds: string[] = getTrailingDisplayColumnIds(tableOptions);
|
|
132
118
|
|
|
133
|
-
const defaultColumnDefIds = getAllLeafColumnDefs(tableOptions.columns).map(
|
|
134
|
-
(columnDef) => getColumnId(columnDef),
|
|
135
|
-
);
|
|
119
|
+
const defaultColumnDefIds = getAllLeafColumnDefs(tableOptions.columns).map((columnDef) => getColumnId(columnDef));
|
|
136
120
|
|
|
137
121
|
let allLeafColumnDefIds = reset
|
|
138
122
|
? defaultColumnDefIds
|
|
139
123
|
: Array.from(new Set([...currentColumnOrderIds, ...defaultColumnDefIds]));
|
|
140
124
|
|
|
141
125
|
allLeafColumnDefIds = allLeafColumnDefIds.filter(
|
|
142
|
-
(colId) =>
|
|
143
|
-
!leadingDisplayColIds.includes(colId) &&
|
|
144
|
-
!trailingDisplayColIds.includes(colId),
|
|
126
|
+
(colId) => !leadingDisplayColIds.includes(colId) && !trailingDisplayColIds.includes(colId),
|
|
145
127
|
);
|
|
146
128
|
|
|
147
|
-
return [
|
|
148
|
-
...leadingDisplayColIds,
|
|
149
|
-
...allLeafColumnDefIds,
|
|
150
|
-
...trailingDisplayColIds,
|
|
151
|
-
];
|
|
129
|
+
return [...leadingDisplayColIds, ...allLeafColumnDefIds, ...trailingDisplayColIds];
|
|
152
130
|
};
|
|
@@ -10,11 +10,13 @@ interface HighlightWordsArgs {
|
|
|
10
10
|
text: string;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
-
const escapeRegExp = (term: string): string =>
|
|
14
|
-
term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
|
|
13
|
+
const escapeRegExp = (term: string): string => term.replace(/[|\\{}()[\]^$+*?.-]/g, (char) => `\\${char}`);
|
|
15
14
|
|
|
16
15
|
const termsToRegExpString = (terms: string): string =>
|
|
17
|
-
terms
|
|
16
|
+
terms
|
|
17
|
+
.replace(/\s{2,}/g, ' ')
|
|
18
|
+
.split(' ')
|
|
19
|
+
.join('|');
|
|
18
20
|
|
|
19
21
|
const buildRegExp = (terms: string, matchExactly: boolean): RegExp => {
|
|
20
22
|
const fromString = /^([/~@;%#'])(.*?)\1([gimsuy]*)$/.exec(terms);
|
|
@@ -29,11 +31,7 @@ const buildRegExp = (terms: string, matchExactly: boolean): RegExp => {
|
|
|
29
31
|
let uidCounter = 0;
|
|
30
32
|
const uid = (): string => `mrt-hl-${(uidCounter += 1).toString(36)}`;
|
|
31
33
|
|
|
32
|
-
export const highlightWords = ({
|
|
33
|
-
matchExactly = false,
|
|
34
|
-
query,
|
|
35
|
-
text,
|
|
36
|
-
}: HighlightWordsArgs): HighlightChunk[] => {
|
|
34
|
+
export const highlightWords = ({ matchExactly = false, query, text }: HighlightWordsArgs): HighlightChunk[] => {
|
|
37
35
|
const safeQuery = typeof query === 'string' ? query.trim() : query;
|
|
38
36
|
if (safeQuery === '') {
|
|
39
37
|
return [{ key: uid(), match: false, text }];
|
|
@@ -44,9 +42,7 @@ export const highlightWords = ({
|
|
|
44
42
|
.filter((str) => str.length > 0)
|
|
45
43
|
.map((str) => ({
|
|
46
44
|
key: uid(),
|
|
47
|
-
match: matchExactly
|
|
48
|
-
? str.toLowerCase() === safeQuery.toLowerCase()
|
|
49
|
-
: searchRegexp.test(str),
|
|
45
|
+
match: matchExactly ? str.toLowerCase() === safeQuery.toLowerCase() : searchRegexp.test(str),
|
|
50
46
|
text: str,
|
|
51
47
|
}));
|
|
52
48
|
};
|