material-react-table 1.1.0-beta.0 → 1.1.0-beta.1

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
2
  import type { MRT_Cell, MRT_Column, MRT_ColumnDef, MRT_FilterOption, MRT_Row, MRT_TableInstance, MRT_TableState, MaterialReactTableProps, MRT_Localization } from '..';
3
- export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(props: Omit<Partial<import("@tanstack/table-core").TableOptions<TData>>, "state" | "data" | "onStateChange" | "initialState" | "columns" | "defaultColumn" | "enableRowSelection" | "expandRowsFn"> & {
3
+ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(props: Omit<Partial<import("@tanstack/table-core").TableOptions<TData>>, "initialState" | "state" | "onStateChange" | "data" | "columns" | "defaultColumn" | "enableRowSelection" | "expandRowsFn"> & {
4
4
  columnFilterModeOptions?: (string | (string & Record<never, never>))[] | null | undefined;
5
5
  columns: MRT_ColumnDef<TData>[];
6
6
  data: TData[];
@@ -13,7 +13,7 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
13
13
  "mrt-row-select": Partial<MRT_ColumnDef<{}>>;
14
14
  "mrt-row-numbers": Partial<MRT_ColumnDef<{}>>;
15
15
  }> | undefined;
16
- editingMode?: "cell" | "row" | "table" | "modal" | undefined;
16
+ editingMode?: "row" | "cell" | "table" | "modal" | undefined;
17
17
  enableBottomToolbar?: boolean | undefined;
18
18
  enableClickToCopy?: boolean | undefined;
19
19
  enableColumnActions?: boolean | undefined;
@@ -45,7 +45,7 @@ export declare const MRT_TableRoot: <TData extends Record<string, any> = {}>(pro
45
45
  icons?: Partial<import("..").MRT_Icons> | undefined;
46
46
  initialState?: Partial<MRT_TableState<TData>> | undefined;
47
47
  localization?: Partial<MRT_Localization> | undefined;
48
- memoMode?: "cell" | "row" | "table-body" | undefined;
48
+ memoMode?: "row" | "cell" | "table-body" | undefined;
49
49
  muiBottomToolbarProps?: import("@mui/material").ToolbarProps<"div", {}> | (({ table }: {
50
50
  table: MRT_TableInstance<TData>;
51
51
  }) => import("@mui/material").ToolbarProps<"div", {}>) | undefined;
@@ -2,8 +2,8 @@ import { Dispatch, MutableRefObject, ReactNode, SetStateAction } from 'react';
2
2
  import type { AlertProps, ButtonProps, CheckboxProps, ChipProps, IconButtonProps, LinearProgressProps, PaperProps, RadioProps, SkeletonProps, TableBodyProps, TableCellProps, TableContainerProps, TableFooterProps, TableHeadProps, TablePaginationProps, TableProps, TableRowProps, TextFieldProps, ToolbarProps } from '@mui/material';
3
3
  import type { Cell, Column, ColumnDef, DeepKeys, FilterFn, Header, HeaderGroup, OnChangeFn, Row, SortingFn, Table, TableOptions, TableState } from '@tanstack/react-table';
4
4
  import type { Options as VirtualizerOptions, VirtualItem } from 'react-virtual';
5
- import { MRT_Icons } from './icons';
6
5
  import { MRT_FilterFns } from './filterFns';
6
+ import { MRT_Icons } from './icons';
7
7
  import { MRT_SortingFns } from './sortingFns';
8
8
  /**
9
9
  * Most of this file is just TypeScript types
@@ -329,7 +329,7 @@ export declare type MRT_ColumnDef<TData extends Record<string, any> = {}> = Omit
329
329
  onSelectFilterMode: (filterMode: MRT_FilterOption) => void;
330
330
  table: MRT_TableInstance<TData>;
331
331
  }) => ReactNode[];
332
- sortingFn?: MRT_SortingFn;
332
+ sortingFn?: MRT_SortingFn<TData>;
333
333
  };
334
334
  export declare type MRT_DefinedColumnDef<TData extends Record<string, any> = {}> = Omit<MRT_ColumnDef<TData>, 'id' | 'defaultDisplayColumn'> & {
335
335
  defaultDisplayColumn: Partial<MRT_ColumnDef<TData>>;
@@ -0,0 +1,2 @@
1
+ import { MRT_Localization } from '../MaterialReactTable';
2
+ export declare const MRT_Localization_JA: MRT_Localization;
@@ -1,8 +1,8 @@
1
1
  import React, { useMemo, useRef, useState, useCallback, useEffect, Fragment, memo, useLayoutEffect } from 'react';
2
2
  import { aggregationFns, filterFns, sortingFns, useReactTable, getCoreRowModel, getExpandedRowModel, getFacetedRowModel, getFilteredRowModel, getGroupedRowModel, getPaginationRowModel, getSortedRowModel } from '@tanstack/react-table';
3
- import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityLarge, DensityMedium, DensitySmall, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, KeyboardDoubleArrowDown, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
3
+ import { alpha, lighten, Tooltip, IconButton, Menu, MenuItem, Box, FormControlLabel, Switch, Typography, Button, Divider, ListItemIcon, Radio, Checkbox, debounce, Collapse, TextField, InputAdornment, LinearProgress, TablePagination, Chip, Alert, AlertTitle, Fade, useMediaQuery, Toolbar, Grow, TableSortLabel, useTheme, TableCell, TableRow, TableHead, darken, Skeleton, TableBody, TableFooter, Table, TableContainer, Paper, Dialog, DialogTitle, DialogContent, Stack, DialogActions } from '@mui/material';
4
4
  import { rankItem, rankings, compareItems } from '@tanstack/match-sorter-utils';
5
- import { Tooltip, IconButton, Menu, MenuItem, Box, alpha, lighten, FormControlLabel, Switch, Typography, Button, Divider, ListItemIcon, Radio, Checkbox, debounce, Collapse, TextField, InputAdornment, LinearProgress, TablePagination, Chip, Alert, AlertTitle, Fade, useMediaQuery, Toolbar, Grow, TableSortLabel, useTheme, TableCell, TableRow, TableHead, darken, Skeleton, TableBody, TableFooter, Table, TableContainer, Paper, Dialog, DialogTitle, DialogContent, Stack, DialogActions } from '@mui/material';
5
+ import { ArrowRight, Cancel, CheckBox, ClearAll, Close, DensityLarge, DensityMedium, DensitySmall, DragHandle, DynamicFeed, Edit, ExpandLess, ExpandMore, FilterAlt, FilterAltOff, FilterList, FilterListOff, FullscreenExit, Fullscreen, KeyboardDoubleArrowDown, MoreHoriz, MoreVert, PushPin, RestartAlt, Save, Search, SearchOff, Sort, ViewColumn, VisibilityOff } from '@mui/icons-material';
6
6
  import { useVirtual } from 'react-virtual';
7
7
 
8
8
  /******************************************************************************
@@ -34,37 +34,161 @@ function __rest(s, e) {
34
34
 
35
35
  const MRT_AggregationFns = Object.assign({}, aggregationFns);
36
36
 
37
- const MRT_Default_Icons = {
38
- ArrowRightIcon: ArrowRight,
39
- CancelIcon: Cancel,
40
- CheckBoxIcon: CheckBox,
41
- ClearAllIcon: ClearAll,
42
- CloseIcon: Close,
43
- DensityLargeIcon: DensityLarge,
44
- DensityMediumIcon: DensityMedium,
45
- DensitySmallIcon: DensitySmall,
46
- DragHandleIcon: DragHandle,
47
- DynamicFeedIcon: DynamicFeed,
48
- EditIcon: Edit,
49
- ExpandLessIcon: ExpandLess,
50
- ExpandMoreIcon: ExpandMore,
51
- FilterAltIcon: FilterAlt,
52
- FilterAltOffIcon: FilterAltOff,
53
- FilterListIcon: FilterList,
54
- FilterListOffIcon: FilterListOff,
55
- FullscreenExitIcon: FullscreenExit,
56
- FullscreenIcon: Fullscreen,
57
- KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
58
- MoreHorizIcon: MoreHoriz,
59
- MoreVertIcon: MoreVert,
60
- PushPinIcon: PushPin,
61
- RestartAltIcon: RestartAlt,
62
- SaveIcon: Save,
63
- SearchIcon: Search,
64
- SearchOffIcon: SearchOff,
65
- SortIcon: Sort,
66
- ViewColumnIcon: ViewColumn,
67
- VisibilityOffIcon: VisibilityOff,
37
+ const getColumnId = (columnDef) => { var _a, _b, _c, _d; return (_d = (_a = columnDef.id) !== null && _a !== void 0 ? _a : (_c = (_b = columnDef.accessorKey) === null || _b === void 0 ? void 0 : _b.toString) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : columnDef.header; };
38
+ const getAllLeafColumnDefs = (columns) => {
39
+ const allLeafColumnDefs = [];
40
+ const getLeafColumns = (cols) => {
41
+ cols.forEach((col) => {
42
+ if (col.columns) {
43
+ getLeafColumns(col.columns);
44
+ }
45
+ else {
46
+ allLeafColumnDefs.push(col);
47
+ }
48
+ });
49
+ };
50
+ getLeafColumns(columns);
51
+ return allLeafColumnDefs;
52
+ };
53
+ const prepareColumns = ({ columnDefs, columnFilterFns, defaultDisplayColumn, filterFns, sortingFns, }) => columnDefs.map((columnDef) => {
54
+ var _a, _b;
55
+ if (!columnDef.id)
56
+ columnDef.id = getColumnId(columnDef);
57
+ if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
58
+ console.error('Column definitions must have a valid `accessorKey` or `id` property');
59
+ }
60
+ if (!columnDef.columnDefType)
61
+ columnDef.columnDefType = 'data';
62
+ if (!!((_a = columnDef.columns) === null || _a === void 0 ? void 0 : _a.length)) {
63
+ columnDef.columnDefType = 'group';
64
+ columnDef.columns = prepareColumns({
65
+ columnDefs: columnDef.columns,
66
+ columnFilterFns,
67
+ defaultDisplayColumn,
68
+ filterFns,
69
+ sortingFns,
70
+ });
71
+ }
72
+ else if (columnDef.columnDefType === 'data') {
73
+ if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
74
+ columnDef.filterFn =
75
+ (_b = filterFns[columnFilterFns[columnDef.id]]) !== null && _b !== void 0 ? _b : filterFns.fuzzy;
76
+ columnDef._filterFn =
77
+ columnFilterFns[columnDef.id];
78
+ }
79
+ if (Object.keys(sortingFns).includes(columnDef.sortingFn)) {
80
+ // @ts-ignore
81
+ columnDef.sortingFn = sortingFns[columnDef.sortingFn];
82
+ }
83
+ }
84
+ else if (columnDef.columnDefType === 'display') {
85
+ columnDef = Object.assign(Object.assign({}, defaultDisplayColumn), columnDef);
86
+ }
87
+ return columnDef;
88
+ });
89
+ const reorderColumn = (draggedColumn, targetColumn, columnOrder) => {
90
+ if (draggedColumn.getCanPin()) {
91
+ draggedColumn.pin(targetColumn.getIsPinned());
92
+ }
93
+ columnOrder.splice(columnOrder.indexOf(targetColumn.id), 0, columnOrder.splice(columnOrder.indexOf(draggedColumn.id), 1)[0]);
94
+ return [...columnOrder];
95
+ };
96
+ const showExpandColumn = (props, grouping) => !!(props.enableExpanding ||
97
+ (props.enableGrouping && (grouping === undefined || (grouping === null || grouping === void 0 ? void 0 : grouping.length))) ||
98
+ props.renderDetailPanel);
99
+ const getLeadingDisplayColumnIds = (props) => {
100
+ var _a;
101
+ return [
102
+ (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
103
+ props.positionActionsColumn === 'first' &&
104
+ (props.enableRowActions ||
105
+ (props.enableEditing &&
106
+ ['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
107
+ 'mrt-row-actions',
108
+ props.positionExpandColumn === 'first' &&
109
+ showExpandColumn(props) &&
110
+ 'mrt-row-expand',
111
+ props.enableRowSelection && 'mrt-row-select',
112
+ props.enableRowNumbers && 'mrt-row-numbers',
113
+ ].filter(Boolean);
114
+ };
115
+ const getTrailingDisplayColumnIds = (props) => {
116
+ var _a;
117
+ return [
118
+ props.positionActionsColumn === 'last' &&
119
+ (props.enableRowActions ||
120
+ (props.enableEditing &&
121
+ ['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
122
+ 'mrt-row-actions',
123
+ props.positionExpandColumn === 'last' &&
124
+ showExpandColumn(props) &&
125
+ 'mrt-row-expand',
126
+ ];
127
+ };
128
+ const getDefaultColumnOrderIds = (props) => [
129
+ ...getLeadingDisplayColumnIds(props),
130
+ ...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
131
+ ...getTrailingDisplayColumnIds(props),
132
+ ].filter(Boolean);
133
+ const getDefaultColumnFilterFn = (columnDef) => {
134
+ if (columnDef.filterVariant === 'multi-select')
135
+ return 'arrIncludesSome';
136
+ if (columnDef.filterVariant === 'range')
137
+ return 'betweenInclusive';
138
+ if (columnDef.filterVariant === 'select' ||
139
+ columnDef.filterVariant === 'checkbox')
140
+ return 'equals';
141
+ return 'fuzzy';
142
+ };
143
+ const getIsLastLeftPinnedColumn = (table, column) => {
144
+ return (column.getIsPinned() === 'left' &&
145
+ table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
146
+ };
147
+ const getIsFirstRightPinnedColumn = (column) => {
148
+ return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
149
+ };
150
+ const getTotalRight = (table, column) => {
151
+ return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160);
152
+ };
153
+ const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
154
+ var _a, _b, _c, _d;
155
+ return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
156
+ ? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
157
+ : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
158
+ ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
159
+ : getIsFirstRightPinnedColumn(column)
160
+ ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
161
+ : undefined, left: column.getIsPinned() === 'left'
162
+ ? `${column.getStart('left')}px`
163
+ : undefined, opacity: ((_a = table.getState().draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id ||
164
+ ((_b = table.getState().hoveredColumn) === null || _b === void 0 ? void 0 : _b.id) === column.id
165
+ ? 0.5
166
+ : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
167
+ ? 'sticky'
168
+ : undefined, right: column.getIsPinned() === 'right'
169
+ ? `${getTotalRight(table, column)}px`
170
+ : undefined, transition: `all ${column.getIsResizing() ? 0 : '150ms'} ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
171
+ ? tableCellProps.sx(theme)
172
+ : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { maxWidth: `min(${column.getSize()}px, fit-content)`, minWidth: `max(${column.getSize()}px, ${(_c = column.columnDef.minSize) !== null && _c !== void 0 ? _c : 30}px)`, width: (_d = header === null || header === void 0 ? void 0 : header.getSize()) !== null && _d !== void 0 ? _d : column.getSize() }));
173
+ };
174
+ const MRT_DefaultColumn = {
175
+ minSize: 40,
176
+ maxSize: 1000,
177
+ size: 180,
178
+ };
179
+ const MRT_DefaultDisplayColumn = {
180
+ columnDefType: 'display',
181
+ enableClickToCopy: false,
182
+ enableColumnActions: false,
183
+ enableColumnDragging: false,
184
+ enableColumnFilter: false,
185
+ enableColumnOrdering: false,
186
+ enableEditing: false,
187
+ enableGlobalFilter: false,
188
+ enableGrouping: false,
189
+ enableHiding: false,
190
+ enableResizing: false,
191
+ enableSorting: false,
68
192
  };
69
193
 
70
194
  const fuzzy$1 = (row, columnId, filterValue, addMeta) => {
@@ -151,94 +275,37 @@ const MRT_FilterFns = Object.assign(Object.assign({}, filterFns), { between,
151
275
  notEquals,
152
276
  startsWith });
153
277
 
154
- const MRT_Localization_EN = {
155
- actions: 'Actions',
156
- and: 'and',
157
- cancel: 'Cancel',
158
- changeFilterMode: 'Change filter mode',
159
- changeSearchMode: 'Change search mode',
160
- clearFilter: 'Clear filter',
161
- clearSearch: 'Clear search',
162
- clearSort: 'Clear sort',
163
- clickToCopy: 'Click to copy',
164
- columnActions: 'Column Actions',
165
- copiedToClipboard: 'Copied to clipboard',
166
- dropToGroupBy: 'Drop to group by {column}',
167
- edit: 'Edit',
168
- expand: 'Expand',
169
- expandAll: 'Expand all',
170
- filterArrIncludes: 'Includes',
171
- filterArrIncludesAll: 'Includes all',
172
- filterArrIncludesSome: 'Includes',
173
- filterBetween: 'Between',
174
- filterBetweenInclusive: 'Between Inclusive',
175
- filterByColumn: 'Filter by {column}',
176
- filterContains: 'Contains',
177
- filterEmpty: 'Empty',
178
- filterEndsWith: 'Ends With',
179
- filterEquals: 'Equals',
180
- filterEqualsString: 'Equals',
181
- filterFuzzy: 'Fuzzy',
182
- filterGreaterThan: 'Greater Than',
183
- filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
184
- filterInNumberRange: 'Between',
185
- filterIncludesString: 'Contains',
186
- filterIncludesStringSensitive: 'Contains',
187
- filterLessThan: 'Less Than',
188
- filterLessThanOrEqualTo: 'Less Than Or Equal To',
189
- filterMode: 'Filter Mode: {filterType}',
190
- filterNotEmpty: 'Not Empty',
191
- filterNotEquals: 'Not Equals',
192
- filterStartsWith: 'Starts With',
193
- filterWeakEquals: 'Equals',
194
- filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
195
- goToFirstPage: 'Go to first page',
196
- goToLastPage: 'Go to last page',
197
- goToNextPage: 'Go to next page',
198
- goToPreviousPage: 'Go to previous page',
199
- grab: 'Grab',
200
- groupByColumn: 'Group by {column}',
201
- groupedBy: 'Grouped by ',
202
- hideAll: 'Hide all',
203
- hideColumn: 'Hide {column} column',
204
- max: 'Max',
205
- min: 'Min',
206
- move: 'Move',
207
- noRecordsToDisplay: 'No records to display',
208
- noResultsFound: 'No results found',
209
- of: 'of',
210
- or: 'or',
211
- pinToLeft: 'Pin to left',
212
- pinToRight: 'Pin to right',
213
- resetColumnSize: 'Reset column size',
214
- resetOrder: 'Reset order',
215
- rowActions: 'Row Actions',
216
- rowNumber: '#',
217
- rowNumbers: 'Row Numbers',
218
- rowsPerPage: 'Rows per page',
219
- save: 'Save',
220
- search: 'Search',
221
- selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
222
- select: 'Select',
223
- showAll: 'Show all',
224
- showAllColumns: 'Show all columns',
225
- showHideColumns: 'Show/Hide columns',
226
- showHideFilters: 'Show/Hide filters',
227
- showHideSearch: 'Show/Hide search',
228
- sortByColumnAsc: 'Sort by {column} ascending',
229
- sortByColumnDesc: 'Sort by {column} descending',
230
- sortedByColumnAsc: 'Sorted by {column} ascending',
231
- sortedByColumnDesc: 'Sorted by {column} descending',
232
- thenBy: ', then by ',
233
- toggleDensity: 'Toggle density',
234
- toggleFullScreen: 'Toggle full screen',
235
- toggleSelectAll: 'Toggle select all',
236
- toggleSelectRow: 'Toggle select row',
237
- toggleVisibility: 'Toggle visibility',
238
- ungroupByColumn: 'Ungroup by {column}',
239
- unpin: 'Unpin',
240
- unpinAll: 'Unpin all',
241
- unsorted: 'Unsorted',
278
+ const MRT_Default_Icons = {
279
+ ArrowRightIcon: ArrowRight,
280
+ CancelIcon: Cancel,
281
+ CheckBoxIcon: CheckBox,
282
+ ClearAllIcon: ClearAll,
283
+ CloseIcon: Close,
284
+ DensityLargeIcon: DensityLarge,
285
+ DensityMediumIcon: DensityMedium,
286
+ DensitySmallIcon: DensitySmall,
287
+ DragHandleIcon: DragHandle,
288
+ DynamicFeedIcon: DynamicFeed,
289
+ EditIcon: Edit,
290
+ ExpandLessIcon: ExpandLess,
291
+ ExpandMoreIcon: ExpandMore,
292
+ FilterAltIcon: FilterAlt,
293
+ FilterAltOffIcon: FilterAltOff,
294
+ FilterListIcon: FilterList,
295
+ FilterListOffIcon: FilterListOff,
296
+ FullscreenExitIcon: FullscreenExit,
297
+ FullscreenIcon: Fullscreen,
298
+ KeyboardDoubleArrowDownIcon: KeyboardDoubleArrowDown,
299
+ MoreHorizIcon: MoreHoriz,
300
+ MoreVertIcon: MoreVert,
301
+ PushPinIcon: PushPin,
302
+ RestartAltIcon: RestartAlt,
303
+ SaveIcon: Save,
304
+ SearchIcon: Search,
305
+ SearchOffIcon: SearchOff,
306
+ SortIcon: Sort,
307
+ ViewColumnIcon: ViewColumn,
308
+ VisibilityOffIcon: VisibilityOff,
242
309
  };
243
310
 
244
311
  const fuzzy = (rowA, rowB, columnId) => {
@@ -500,163 +567,6 @@ const MRT_GrabHandleButton = ({ iconButtonProps, onDragEnd, onDragStart, table,
500
567
  React.createElement(DragHandleIcon, null))));
501
568
  };
502
569
 
503
- const getColumnId = (columnDef) => { var _a, _b, _c, _d; return (_d = (_a = columnDef.id) !== null && _a !== void 0 ? _a : (_c = (_b = columnDef.accessorKey) === null || _b === void 0 ? void 0 : _b.toString) === null || _c === void 0 ? void 0 : _c.call(_b)) !== null && _d !== void 0 ? _d : columnDef.header; };
504
- const getAllLeafColumnDefs = (columns) => {
505
- const allLeafColumnDefs = [];
506
- const getLeafColumns = (cols) => {
507
- cols.forEach((col) => {
508
- if (col.columns) {
509
- getLeafColumns(col.columns);
510
- }
511
- else {
512
- allLeafColumnDefs.push(col);
513
- }
514
- });
515
- };
516
- getLeafColumns(columns);
517
- return allLeafColumnDefs;
518
- };
519
- const prepareColumns = ({ columnDefs, columnFilterFns, defaultDisplayColumn, filterFns, sortingFns, }) => columnDefs.map((columnDef) => {
520
- var _a, _b;
521
- if (!columnDef.id)
522
- columnDef.id = getColumnId(columnDef);
523
- if (process.env.NODE_ENV !== 'production' && !columnDef.id) {
524
- console.error('Column definitions must have a valid `accessorKey` or `id` property');
525
- }
526
- if (!columnDef.columnDefType)
527
- columnDef.columnDefType = 'data';
528
- if (!!((_a = columnDef.columns) === null || _a === void 0 ? void 0 : _a.length)) {
529
- columnDef.columnDefType = 'group';
530
- columnDef.columns = prepareColumns({
531
- columnDefs: columnDef.columns,
532
- columnFilterFns,
533
- defaultDisplayColumn,
534
- filterFns,
535
- sortingFns,
536
- });
537
- }
538
- else if (columnDef.columnDefType === 'data') {
539
- if (Object.keys(filterFns).includes(columnFilterFns[columnDef.id])) {
540
- columnDef.filterFn =
541
- (_b = filterFns[columnFilterFns[columnDef.id]]) !== null && _b !== void 0 ? _b : filterFns.fuzzy;
542
- columnDef._filterFn =
543
- columnFilterFns[columnDef.id];
544
- }
545
- if (Object.keys(sortingFns).includes(columnDef.sortingFn)) {
546
- // @ts-ignore
547
- columnDef.sortingFn = sortingFns[columnDef.sortingFn];
548
- }
549
- }
550
- else if (columnDef.columnDefType === 'display') {
551
- columnDef = Object.assign(Object.assign({}, defaultDisplayColumn), columnDef);
552
- }
553
- return columnDef;
554
- });
555
- const reorderColumn = (draggedColumn, targetColumn, columnOrder) => {
556
- if (draggedColumn.getCanPin()) {
557
- draggedColumn.pin(targetColumn.getIsPinned());
558
- }
559
- columnOrder.splice(columnOrder.indexOf(targetColumn.id), 0, columnOrder.splice(columnOrder.indexOf(draggedColumn.id), 1)[0]);
560
- return [...columnOrder];
561
- };
562
- const showExpandColumn = (props, grouping) => !!(props.enableExpanding ||
563
- (props.enableGrouping && (grouping === undefined || (grouping === null || grouping === void 0 ? void 0 : grouping.length))) ||
564
- props.renderDetailPanel);
565
- const getLeadingDisplayColumnIds = (props) => {
566
- var _a;
567
- return [
568
- (props.enableRowDragging || props.enableRowOrdering) && 'mrt-row-drag',
569
- props.positionActionsColumn === 'first' &&
570
- (props.enableRowActions ||
571
- (props.enableEditing &&
572
- ['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
573
- 'mrt-row-actions',
574
- props.positionExpandColumn === 'first' &&
575
- showExpandColumn(props) &&
576
- 'mrt-row-expand',
577
- props.enableRowSelection && 'mrt-row-select',
578
- props.enableRowNumbers && 'mrt-row-numbers',
579
- ].filter(Boolean);
580
- };
581
- const getTrailingDisplayColumnIds = (props) => {
582
- var _a;
583
- return [
584
- props.positionActionsColumn === 'last' &&
585
- (props.enableRowActions ||
586
- (props.enableEditing &&
587
- ['row', 'modal'].includes((_a = props.editingMode) !== null && _a !== void 0 ? _a : ''))) &&
588
- 'mrt-row-actions',
589
- props.positionExpandColumn === 'last' &&
590
- showExpandColumn(props) &&
591
- 'mrt-row-expand',
592
- ];
593
- };
594
- const getDefaultColumnOrderIds = (props) => [
595
- ...getLeadingDisplayColumnIds(props),
596
- ...getAllLeafColumnDefs(props.columns).map((columnDef) => getColumnId(columnDef)),
597
- ...getTrailingDisplayColumnIds(props),
598
- ].filter(Boolean);
599
- const getDefaultColumnFilterFn = (columnDef) => {
600
- if (columnDef.filterVariant === 'multi-select')
601
- return 'arrIncludesSome';
602
- if (columnDef.filterVariant === 'range')
603
- return 'betweenInclusive';
604
- if (columnDef.filterVariant === 'select' ||
605
- columnDef.filterVariant === 'checkbox')
606
- return 'equals';
607
- return 'fuzzy';
608
- };
609
- const getIsLastLeftPinnedColumn = (table, column) => {
610
- return (column.getIsPinned() === 'left' &&
611
- table.getLeftLeafHeaders().length - 1 === column.getPinnedIndex());
612
- };
613
- const getIsFirstRightPinnedColumn = (column) => {
614
- return column.getIsPinned() === 'right' && column.getPinnedIndex() === 0;
615
- };
616
- const getTotalRight = (table, column) => {
617
- return ((table.getRightLeafHeaders().length - 1 - column.getPinnedIndex()) * 160);
618
- };
619
- const getCommonCellStyles = ({ column, header, table, tableCellProps, theme, }) => {
620
- var _a, _b, _c, _d;
621
- return (Object.assign(Object.assign({ backgroundColor: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
622
- ? alpha(lighten(theme.palette.background.default, 0.04), 0.97)
623
- : 'inherit', backgroundImage: 'inherit', boxShadow: getIsLastLeftPinnedColumn(table, column)
624
- ? `-4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
625
- : getIsFirstRightPinnedColumn(column)
626
- ? `4px 0 8px -6px ${alpha(theme.palette.common.black, 0.2)} inset`
627
- : undefined, left: column.getIsPinned() === 'left'
628
- ? `${column.getStart('left')}px`
629
- : undefined, opacity: ((_a = table.getState().draggingColumn) === null || _a === void 0 ? void 0 : _a.id) === column.id ||
630
- ((_b = table.getState().hoveredColumn) === null || _b === void 0 ? void 0 : _b.id) === column.id
631
- ? 0.5
632
- : 1, position: column.getIsPinned() && column.columnDef.columnDefType !== 'group'
633
- ? 'sticky'
634
- : undefined, right: column.getIsPinned() === 'right'
635
- ? `${getTotalRight(table, column)}px`
636
- : undefined, transition: `all ${column.getIsResizing() ? 0 : '150ms'} ease-in-out` }, ((tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx) instanceof Function
637
- ? tableCellProps.sx(theme)
638
- : tableCellProps === null || tableCellProps === void 0 ? void 0 : tableCellProps.sx)), { maxWidth: `min(${column.getSize()}px, fit-content)`, minWidth: `max(${column.getSize()}px, ${(_c = column.columnDef.minSize) !== null && _c !== void 0 ? _c : 30}px)`, width: (_d = header === null || header === void 0 ? void 0 : header.getSize()) !== null && _d !== void 0 ? _d : column.getSize() }));
639
- };
640
- const MRT_DefaultColumn = {
641
- minSize: 40,
642
- maxSize: 1000,
643
- size: 180,
644
- };
645
- const MRT_DefaultDisplayColumn = {
646
- columnDefType: 'display',
647
- enableClickToCopy: false,
648
- enableColumnActions: false,
649
- enableColumnDragging: false,
650
- enableColumnFilter: false,
651
- enableColumnOrdering: false,
652
- enableEditing: false,
653
- enableGlobalFilter: false,
654
- enableGrouping: false,
655
- enableHiding: false,
656
- enableResizing: false,
657
- enableSorting: false,
658
- };
659
-
660
570
  const MRT_ShowHideColumnsMenuItems = ({ allColumns, hoveredColumn, setHoveredColumn, column, isSubMenu, table, }) => {
661
571
  var _a;
662
572
  const { getState, options: { enableColumnOrdering, enableHiding, enablePinning, localization, }, setColumnOrder, } = table;
@@ -2711,6 +2621,96 @@ const MRT_TableRoot = (props) => {
2711
2621
  editingRow && props.editingMode === 'modal' && (React.createElement(MRT_EditRowModal, { row: editingRow, table: table, open: true }))));
2712
2622
  };
2713
2623
 
2624
+ const MRT_Localization_EN = {
2625
+ actions: 'Actions',
2626
+ and: 'and',
2627
+ cancel: 'Cancel',
2628
+ changeFilterMode: 'Change filter mode',
2629
+ changeSearchMode: 'Change search mode',
2630
+ clearFilter: 'Clear filter',
2631
+ clearSearch: 'Clear search',
2632
+ clearSort: 'Clear sort',
2633
+ clickToCopy: 'Click to copy',
2634
+ columnActions: 'Column Actions',
2635
+ copiedToClipboard: 'Copied to clipboard',
2636
+ dropToGroupBy: 'Drop to group by {column}',
2637
+ edit: 'Edit',
2638
+ expand: 'Expand',
2639
+ expandAll: 'Expand all',
2640
+ filterArrIncludes: 'Includes',
2641
+ filterArrIncludesAll: 'Includes all',
2642
+ filterArrIncludesSome: 'Includes',
2643
+ filterBetween: 'Between',
2644
+ filterBetweenInclusive: 'Between Inclusive',
2645
+ filterByColumn: 'Filter by {column}',
2646
+ filterContains: 'Contains',
2647
+ filterEmpty: 'Empty',
2648
+ filterEndsWith: 'Ends With',
2649
+ filterEquals: 'Equals',
2650
+ filterEqualsString: 'Equals',
2651
+ filterFuzzy: 'Fuzzy',
2652
+ filterGreaterThan: 'Greater Than',
2653
+ filterGreaterThanOrEqualTo: 'Greater Than Or Equal To',
2654
+ filterInNumberRange: 'Between',
2655
+ filterIncludesString: 'Contains',
2656
+ filterIncludesStringSensitive: 'Contains',
2657
+ filterLessThan: 'Less Than',
2658
+ filterLessThanOrEqualTo: 'Less Than Or Equal To',
2659
+ filterMode: 'Filter Mode: {filterType}',
2660
+ filterNotEmpty: 'Not Empty',
2661
+ filterNotEquals: 'Not Equals',
2662
+ filterStartsWith: 'Starts With',
2663
+ filterWeakEquals: 'Equals',
2664
+ filteringByColumn: 'Filtering by {column} - {filterType} {filterValue}',
2665
+ goToFirstPage: 'Go to first page',
2666
+ goToLastPage: 'Go to last page',
2667
+ goToNextPage: 'Go to next page',
2668
+ goToPreviousPage: 'Go to previous page',
2669
+ grab: 'Grab',
2670
+ groupByColumn: 'Group by {column}',
2671
+ groupedBy: 'Grouped by ',
2672
+ hideAll: 'Hide all',
2673
+ hideColumn: 'Hide {column} column',
2674
+ max: 'Max',
2675
+ min: 'Min',
2676
+ move: 'Move',
2677
+ noRecordsToDisplay: 'No records to display',
2678
+ noResultsFound: 'No results found',
2679
+ of: 'of',
2680
+ or: 'or',
2681
+ pinToLeft: 'Pin to left',
2682
+ pinToRight: 'Pin to right',
2683
+ resetColumnSize: 'Reset column size',
2684
+ resetOrder: 'Reset order',
2685
+ rowActions: 'Row Actions',
2686
+ rowNumber: '#',
2687
+ rowNumbers: 'Row Numbers',
2688
+ rowsPerPage: 'Rows per page',
2689
+ save: 'Save',
2690
+ search: 'Search',
2691
+ selectedCountOfRowCountRowsSelected: '{selectedCount} of {rowCount} row(s) selected',
2692
+ select: 'Select',
2693
+ showAll: 'Show all',
2694
+ showAllColumns: 'Show all columns',
2695
+ showHideColumns: 'Show/Hide columns',
2696
+ showHideFilters: 'Show/Hide filters',
2697
+ showHideSearch: 'Show/Hide search',
2698
+ sortByColumnAsc: 'Sort by {column} ascending',
2699
+ sortByColumnDesc: 'Sort by {column} descending',
2700
+ sortedByColumnAsc: 'Sorted by {column} ascending',
2701
+ sortedByColumnDesc: 'Sorted by {column} descending',
2702
+ thenBy: ', then by ',
2703
+ toggleDensity: 'Toggle density',
2704
+ toggleFullScreen: 'Toggle full screen',
2705
+ toggleSelectAll: 'Toggle select all',
2706
+ toggleSelectRow: 'Toggle select row',
2707
+ toggleVisibility: 'Toggle visibility',
2708
+ ungroupByColumn: 'Ungroup by {column}',
2709
+ unpin: 'Unpin',
2710
+ unpinAll: 'Unpin all',
2711
+ unsorted: 'Unsorted',
2712
+ };
2713
+
2714
2714
  const MaterialReactTable = (_a) => {
2715
2715
  var { aggregationFns, autoResetExpanded = false, columnResizeMode = 'onEnd', defaultColumn, defaultDisplayColumn, editingMode = 'modal', enableBottomToolbar = true, enableColumnActions = true, enableColumnFilters = true, enableColumnOrdering = false, enableColumnResizing = false, enableDensityToggle = true, enableExpandAll = true, enableFilters = true, enableFullScreenToggle = true, enableGlobalFilter = true, enableGlobalFilterRankedResults = true, enableGrouping = false, enableHiding = true, enableMultiRowSelection = true, enableMultiSort = true, enablePagination = true, enablePinning = false, enableRowSelection = false, enableSelectAll = true, enableSorting = true, enableStickyHeader = false, enableTableFooter = true, enableTableHead = true, enableToolbarInternalActions = true, enableTopToolbar = true, filterFns, icons, localization, positionActionsColumn = 'first', positionExpandColumn = 'first', positionGlobalFilter = 'right', positionPagination = 'bottom', positionToolbarAlertBanner = 'top', positionToolbarDropZone = 'top', rowNumberMode = 'original', selectAllMode = 'page', sortingFns } = _a, rest = __rest(_a, ["aggregationFns", "autoResetExpanded", "columnResizeMode", "defaultColumn", "defaultDisplayColumn", "editingMode", "enableBottomToolbar", "enableColumnActions", "enableColumnFilters", "enableColumnOrdering", "enableColumnResizing", "enableDensityToggle", "enableExpandAll", "enableFilters", "enableFullScreenToggle", "enableGlobalFilter", "enableGlobalFilterRankedResults", "enableGrouping", "enableHiding", "enableMultiRowSelection", "enableMultiSort", "enablePagination", "enablePinning", "enableRowSelection", "enableSelectAll", "enableSorting", "enableStickyHeader", "enableTableFooter", "enableTableHead", "enableToolbarInternalActions", "enableTopToolbar", "filterFns", "icons", "localization", "positionActionsColumn", "positionExpandColumn", "positionGlobalFilter", "positionPagination", "positionToolbarAlertBanner", "positionToolbarDropZone", "rowNumberMode", "selectAllMode", "sortingFns"]);
2716
2716
  const _icons = useMemo(() => (Object.assign(Object.assign({}, MRT_Default_Icons), icons)), []);