@terraware/web-components 5.2.7-rc.2 → 5.2.7

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.
Files changed (44) hide show
  1. package/components/EditableTable/index.d.ts +3 -2
  2. package/components/EditableTable/index.d.ts.map +1 -1
  3. package/components/EditableTable/tableSettings.d.ts +5 -11
  4. package/components/EditableTable/tableSettings.d.ts.map +1 -1
  5. package/components/EditableTable/tableSettings.js +8 -41
  6. package/components/table/density.d.ts +1 -1
  7. package/index.d.ts +3 -7
  8. package/index.d.ts.map +1 -1
  9. package/index.js +1 -4
  10. package/license-report.html +1 -1
  11. package/package.json +1 -2
  12. package/strings/csv/en.csv +0 -37
  13. package/strings/csv/es.csv +0 -37
  14. package/strings/csv/fr.csv +0 -37
  15. package/strings/strings-en.d.ts +0 -37
  16. package/strings/strings-en.d.ts.map +1 -1
  17. package/strings/strings-en.js +1 -38
  18. package/strings/strings-es.d.ts +0 -37
  19. package/strings/strings-es.d.ts.map +1 -1
  20. package/strings/strings-es.js +1 -38
  21. package/strings/strings-fr.d.ts +0 -37
  22. package/strings/strings-fr.d.ts.map +1 -1
  23. package/strings/strings-fr.js +1 -38
  24. package/strings/strings-gx.d.ts +0 -37
  25. package/strings/strings-gx.d.ts.map +1 -1
  26. package/strings/strings-gx.js +1 -38
  27. package/components/EditableTableV2/ColumnDragging.d.ts +0 -23
  28. package/components/EditableTableV2/ColumnDragging.d.ts.map +0 -1
  29. package/components/EditableTableV2/ColumnDragging.js +0 -263
  30. package/components/EditableTableV2/EditableCellV2.d.ts +0 -10
  31. package/components/EditableTableV2/EditableCellV2.d.ts.map +0 -1
  32. package/components/EditableTableV2/EditableCellV2.js +0 -81
  33. package/components/EditableTableV2/ToolbarButtons.d.ts +0 -29
  34. package/components/EditableTableV2/ToolbarButtons.d.ts.map +0 -1
  35. package/components/EditableTableV2/ToolbarButtons.js +0 -84
  36. package/components/EditableTableV2/index.d.ts +0 -62
  37. package/components/EditableTableV2/index.d.ts.map +0 -1
  38. package/components/EditableTableV2/index.js +0 -1009
  39. package/components/EditableTableV2/pinning.d.ts +0 -8
  40. package/components/EditableTableV2/pinning.d.ts.map +0 -1
  41. package/components/EditableTableV2/pinning.js +0 -16
  42. package/components/EditableTableV2/types.d.ts +0 -89
  43. package/components/EditableTableV2/types.d.ts.map +0 -1
  44. package/components/EditableTableV2/types.js +0 -18
@@ -1,1009 +0,0 @@
1
- import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
- import { createElement, useCallback, useEffect, useLayoutEffect, useMemo, useRef, useState } from "react";
3
- import { arrayMove } from "@dnd-kit/sortable";
4
- import { ArrowDownward, ArrowUpward, ClearAll, Close, FilterAlt, FilterList, FilterListOff, MoreVert, PushPin, Search, Sort, SyncAlt, ViewColumn, VisibilityOff } from "@mui/icons-material";
5
- import { Box, Button, Divider, FormControlLabel, IconButton, InputAdornment, ListItemIcon, MenuItem, Paper, Switch, Table, TableBody, TableCell, TableHead, TablePagination, TableRow, TableSortLabel, TextField, Toolbar, Tooltip } from "@mui/material";
6
- import { alpha, darken, lighten, useTheme } from "@mui/material/styles";
7
- import { functionalUpdate, useTable } from "@tanstack/react-table";
8
- import { MRT_FilterFns, MRT_SortingFns } from "material-react-table";
9
- import { useStrings } from "../../strings/index.js";
10
- import Button_Button from "../Button/Button.js";
11
- import { ColumnDragBodyCell, ColumnDragHandle, ColumnDragMenu, ColumnDragTableContainer, DraggableColumnHeader, DraggableColumnItem } from "./ColumnDragging.js";
12
- import EditableCellV2 from "./EditableCellV2.js";
13
- import { EditableTableShowHideColumnsButtonV2, EditableTableToggleDensePaddingButtonV2, EditableTableToggleFiltersButtonV2, EditableTableToggleFullScreenButtonV2, EditableTableToggleGlobalFilterButtonV2, EditableTableToolbarRoot } from "./ToolbarButtons.js";
14
- import { toInternalPinning, toPublicPinning } from "./pinning.js";
15
- import { editableTableFeatures } from "./types.js";
16
- const isActiveFilter = (filter)=>{
17
- const values = Array.isArray(filter.value) ? filter.value : [
18
- filter.value
19
- ];
20
- return values.some((value)=>null != value && '' !== value);
21
- };
22
- const readFilters = (storageKey)=>{
23
- try {
24
- const saved = storageKey ? JSON.parse(localStorage.getItem(`${storageKey}_columnFilters`) ?? '[]') : [];
25
- return Array.isArray(saved) ? saved.filter((filter)=>filter && 'string' == typeof filter.id && isActiveFilter(filter)) : [];
26
- } catch {
27
- return [];
28
- }
29
- };
30
- const pinnedStyles = (column, theme, offsets)=>{
31
- const position = column.getIsPinned();
32
- const background = theme.palette.background.default;
33
- const baseBackground = 'dark' === theme.palette.mode ? lighten(background, 0.05) : background;
34
- return {
35
- width: column.getSize(),
36
- minWidth: column.getSize(),
37
- ...position && {
38
- position: 'sticky',
39
- zIndex: 1,
40
- opacity: 0.97,
41
- '&::before': {
42
- content: '""',
43
- position: 'absolute',
44
- inset: 0,
45
- zIndex: -1,
46
- backgroundColor: alpha(darken(baseBackground, 'dark' === theme.palette.mode ? 0.05 : 0.01), 0.97),
47
- boxShadow: 'start' === position && column.getIsLastColumn('start') ? `-4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` : 'end' === position && column.getIsFirstColumn('end') ? `4px 0 4px -4px ${alpha(theme.palette.grey[700], 0.5)} inset` : void 0
48
- },
49
- ...'start' === position ? {
50
- insetInlineStart: offsets[column.id] ?? column.getStart('start')
51
- } : {
52
- insetInlineEnd: offsets[column.id] ?? column.getAfter('end')
53
- }
54
- }
55
- };
56
- };
57
- const UnsortedIcon = (props)=>/*#__PURE__*/ jsx(SyncAlt, {
58
- ...props,
59
- style: {
60
- ...props.style,
61
- transform: 'rotate(-90deg) scaleX(0.9) translateX(-1px)'
62
- }
63
- });
64
- const ColumnActionMenuItemV2 = ({ icon, children, ...props })=>/*#__PURE__*/ jsx(MenuItem, {
65
- sx: {
66
- minWidth: '120px',
67
- my: 0,
68
- py: '6px'
69
- },
70
- ...props,
71
- children: /*#__PURE__*/ jsxs(Box, {
72
- display: "flex",
73
- alignItems: "center",
74
- children: [
75
- /*#__PURE__*/ jsx(ListItemIcon, {
76
- children: icon
77
- }),
78
- children
79
- ]
80
- })
81
- });
82
- const ColumnFilter = ({ column, definition })=>{
83
- const strings = useStrings();
84
- const label = `${strings.TABLE_FILTER}: ${definition.header}`;
85
- const placeholder = strings.TABLE_FILTER_BY.replace('{column}', definition.header);
86
- const value = column.getFilterValue();
87
- if ('range' === definition.filterVariant || 'date-range' === definition.filterVariant) {
88
- const range = Array.isArray(value) ? value : [
89
- '',
90
- ''
91
- ];
92
- return /*#__PURE__*/ jsx(Box, {
93
- display: "flex",
94
- gap: 1,
95
- children: [
96
- 0,
97
- 1
98
- ].map((index)=>/*#__PURE__*/ jsx(TextField, {
99
- size: "small",
100
- variant: "standard",
101
- placeholder: 0 === index ? strings.TABLE_MIN : strings.TABLE_MAX,
102
- type: 'date-range' === definition.filterVariant ? 'date' : 'number',
103
- value: range[index] ?? '',
104
- slotProps: {
105
- htmlInput: {
106
- 'aria-label': `${label} ${0 === index ? strings.TABLE_MIN : strings.TABLE_MAX}`
107
- }
108
- },
109
- onChange: (event)=>{
110
- const next = [
111
- ...range
112
- ];
113
- next[index] = event.target.value;
114
- column.setFilterValue(next.some((entry)=>'' !== entry) ? next : void 0);
115
- }
116
- }, index))
117
- });
118
- }
119
- const multiple = 'multi-select' === definition.filterVariant;
120
- const select = multiple || 'select' === definition.filterVariant;
121
- return /*#__PURE__*/ jsxs(TextField, {
122
- fullWidth: true,
123
- variant: "standard",
124
- placeholder: placeholder,
125
- sx: {
126
- minWidth: 120,
127
- mx: '-2px',
128
- p: 0,
129
- width: 'calc(100% + 4px)'
130
- },
131
- select: select,
132
- value: value ?? (multiple ? [] : ''),
133
- onChange: (event)=>{
134
- const next = event.target.value;
135
- column.setFilterValue(Array.isArray(next) && !next.length ? void 0 : next || void 0);
136
- },
137
- slotProps: {
138
- htmlInput: {
139
- 'aria-label': label
140
- },
141
- input: {
142
- endAdornment: /*#__PURE__*/ jsx(InputAdornment, {
143
- position: "end",
144
- sx: {
145
- mr: select ? '20px' : void 0,
146
- visibility: isActiveFilter({
147
- value
148
- }) ? 'visible' : 'hidden'
149
- },
150
- children: /*#__PURE__*/ jsx(IconButton, {
151
- size: "small",
152
- "aria-label": `${strings.TABLE_CLEAR_FILTER}: ${definition.header}`,
153
- disabled: !isActiveFilter({
154
- value
155
- }),
156
- onClick: ()=>column.setFilterValue(void 0),
157
- sx: {
158
- height: '2rem',
159
- width: '2rem',
160
- transform: 'scale(0.9)'
161
- },
162
- children: /*#__PURE__*/ jsx(Close, {})
163
- })
164
- })
165
- },
166
- select: {
167
- multiple,
168
- displayEmpty: true,
169
- 'aria-label': label,
170
- renderValue: (selected)=>(Array.isArray(selected) ? selected.join(', ') : String(selected ?? '')) || /*#__PURE__*/ jsx(Box, {
171
- sx: {
172
- opacity: 0.5
173
- },
174
- children: placeholder
175
- })
176
- }
177
- },
178
- children: [
179
- select && !multiple && /*#__PURE__*/ jsx(MenuItem, {
180
- value: "",
181
- children: strings.TABLE_ALL
182
- }),
183
- select && definition.filterSelectOptions?.map((option)=>/*#__PURE__*/ jsx(MenuItem, {
184
- value: option,
185
- children: option
186
- }, option))
187
- ]
188
- });
189
- };
190
- const EditableTableV2 = ({ clearAllFiltersLabel, columns, data, enableClearAllFilters = true, enableEditing = false, enableColumnOrdering = false, enableColumnDragging = false, enableColumnActions = true, enableShowAllColumnsMenuItem = true, showColumnsButton = false, showGlobalFilterButton = false, showColumnFiltersButton = false, showDensityButton = false, showFullScreenButton = false, enableColumnPinning = false, enableHiding = true, enableSorting = true, enableGlobalFilter = false, positionGlobalFilter = 'left', enableColumnFilters = false, stickyFilters = false, storageKey, enablePagination = true, enableBottomToolbar = true, enableTopToolbar = true, initialSorting, onClearAllFilters, onRowClick, renderToolbarInternalActions, renderTopToolbarCustomActions, muiTableHeadCellProps, muiTableBodyCellProps, tableOptions, containerProps, sx })=>{
191
- const strings = useStrings();
192
- const theme = useTheme();
193
- const [editingCell, setEditingCell] = useState(null);
194
- const [globalFilterVisible, setGlobalFilterVisible] = useState(true);
195
- const [columnFiltersVisible, setColumnFiltersVisible] = useState(false);
196
- const [density, setDensity] = useState();
197
- const [fullScreen, setFullScreen] = useState(false);
198
- const [menuColumnId, setMenuColumnId] = useState(null);
199
- const [menuAnchor, setMenuAnchor] = useState(null);
200
- const [columnsButtonCount, setColumnsButtonCount] = useState(0);
201
- const registerColumnsButton = useCallback(()=>{
202
- setColumnsButtonCount((count)=>count + 1);
203
- return ()=>setColumnsButtonCount((count)=>count - 1);
204
- }, []);
205
- const [columnFilters, setColumnFilters] = useState(()=>readFilters(stickyFilters ? storageKey : void 0));
206
- useEffect(()=>{
207
- setColumnFilters(readFilters(stickyFilters ? storageKey : void 0));
208
- }, [
209
- stickyFilters,
210
- storageKey
211
- ]);
212
- const tableColumns = useMemo(()=>columns.map((column)=>({
213
- id: column.id,
214
- header: column.header,
215
- meta: {
216
- filterVariant: column.filterVariant,
217
- filterSelectOptions: column.filterSelectOptions
218
- },
219
- accessorFn: column.accessorFn ?? ((row)=>void 0 !== column.accessorKey ? row[column.accessorKey] : void 0),
220
- size: column.size,
221
- enableHiding: column.enableHiding ?? true,
222
- enableColumnFilter: !!column.filterVariant,
223
- ...void 0 !== column.enableSorting ? {
224
- enableSorting: column.enableSorting
225
- } : column.accessorFn || void 0 !== column.accessorKey || column.sortFn || 'sortingFn' in column && column.sortingFn ? {} : {
226
- enableSorting: false
227
- },
228
- ...column.sortFn || column.sortingFn ? {
229
- sortFn: column.sortFn ?? ('function' == typeof column.sortingFn ? column.sortingFn : column.sortingFn && 'auto' !== column.sortingFn ? MRT_SortingFns[column.sortingFn] : 'auto')
230
- } : {},
231
- filterFn: Object.assign((row, id, filterValue, addMeta)=>{
232
- if ('function' == typeof column.filterFn) return column.filterFn(row.original, id, filterValue);
233
- if (column.filterFn) {
234
- const filter = MRT_FilterFns[column.filterFn];
235
- return filter(row, id, filterValue, addMeta);
236
- }
237
- const value = row.getValue(id);
238
- if ('select' === column.filterVariant) return String(value ?? '') === String(filterValue);
239
- if ('multi-select' === column.filterVariant) return !Array.isArray(filterValue) || !filterValue.length || filterValue.some((selected)=>Array.isArray(value) ? value.includes(selected) : String(value ?? '') === String(selected));
240
- if ('range' === column.filterVariant || 'date-range' === column.filterVariant) {
241
- const [min, max] = Array.isArray(filterValue) ? filterValue : [];
242
- const normalize = (entry)=>'date-range' === column.filterVariant ? Date.parse(String(entry)) : Number(entry);
243
- const numeric = normalize(value);
244
- return null != value && '' !== value && Number.isFinite(numeric) && ('' === min || null == min || numeric >= normalize(min)) && ('' === max || null == max || ('date-range' === column.filterVariant && 'string' == typeof max && /^\d{4}-\d{2}-\d{2}$/.test(max) ? numeric < normalize(max) + 86400000 : numeric <= normalize(max)));
245
- }
246
- return String(value ?? '').toLocaleLowerCase().includes(String(filterValue).toLocaleLowerCase());
247
- }, {
248
- autoRemove: 'string' == typeof column.filterFn ? MRT_FilterFns[column.filterFn].autoRemove : void 0
249
- })
250
- })), [
251
- columns,
252
- tableOptions?.defaultColumn
253
- ]);
254
- const persistFilters = stickyFilters && !!storageKey && tableOptions?.state?.columnFilters === void 0;
255
- const { state, initialState, onColumnPinningChange, ...options } = tableOptions ?? {};
256
- const { columnPinning: controlledPinning, ...controlledState } = state ?? {};
257
- const { columnPinning: initialPinning, ...initialTableState } = initialState ?? {};
258
- const table = useTable({
259
- features: editableTableFeatures,
260
- columns: tableColumns,
261
- data,
262
- enableSorting,
263
- sortDescFirst: false,
264
- enableColumnPinning,
265
- enableHiding,
266
- enableColumnFilters,
267
- enableGlobalFilter,
268
- manualPagination: !enablePagination,
269
- ...options,
270
- initialState: {
271
- sorting: initialSorting ?? [],
272
- ...initialTableState,
273
- ...initialPinning && {
274
- columnPinning: toInternalPinning(initialPinning)
275
- }
276
- },
277
- state: {
278
- ...controlledState,
279
- ...controlledPinning && {
280
- columnPinning: toInternalPinning(controlledPinning)
281
- },
282
- ...persistFilters && {
283
- columnFilters
284
- }
285
- },
286
- ...onColumnPinningChange && {
287
- onColumnPinningChange: (updater)=>onColumnPinningChange((previous)=>{
288
- const next = functionalUpdate(updater, toInternalPinning(previous));
289
- return toPublicPinning(next);
290
- })
291
- },
292
- ...persistFilters && {
293
- onColumnFiltersChange: (updater)=>{
294
- setColumnFilters((previous)=>{
295
- const next = 'function' == typeof updater ? updater(previous) : updater;
296
- try {
297
- if (next.some(isActiveFilter)) localStorage.setItem(`${storageKey}_columnFilters`, JSON.stringify(next.filter(isActiveFilter)));
298
- else localStorage.removeItem(`${storageKey}_columnFilters`);
299
- } catch {}
300
- return next;
301
- });
302
- }
303
- }
304
- });
305
- const hasFilters = table.state.columnFilters.some(isActiveFilter) || !!table.state.globalFilter;
306
- const clearFilters = ()=>{
307
- table.setColumnFilters([]);
308
- table.setGlobalFilter('');
309
- onClearAllFilters?.();
310
- };
311
- const definitions = new Map(columns.map((column)=>[
312
- column.id,
313
- column
314
- ]));
315
- const visibleColumns = table.getVisibleLeafColumns();
316
- const allColumns = [
317
- ...table.getStartLeafColumns(),
318
- ...table.getCenterLeafColumns(),
319
- ...table.getEndLeafColumns()
320
- ];
321
- const orderedColumns = [
322
- ...table.getStartVisibleLeafColumns(),
323
- ...table.getCenterVisibleLeafColumns(),
324
- ...table.getEndVisibleLeafColumns()
325
- ];
326
- const rows = table.getRowModel().rows;
327
- const pageCountWithoutRowCount = table.options.manualPagination && void 0 !== table.options.pageCount && table.options.pageCount >= 0 && void 0 === table.options.rowCount;
328
- const nextPageButton = {
329
- disabled: !table.getCanNextPage()
330
- };
331
- const lastPageButton = {
332
- disabled: !table.getCanNextPage(),
333
- onClick: ()=>table.setPageIndex(Math.max(0, table.getPageCount() - 1))
334
- };
335
- const tableRef = useRef(null);
336
- const [renderedWidths, setRenderedWidths] = useState({});
337
- const visibleColumnIds = JSON.stringify(orderedColumns.map((column)=>column.id));
338
- const hasPinnedColumns = orderedColumns.some((column)=>column.getIsPinned());
339
- useLayoutEffect(()=>{
340
- if (!tableRef.current || !hasPinnedColumns) return;
341
- const headers = Array.from(tableRef.current.querySelectorAll('thead th[data-column-id]'));
342
- const measure = ()=>{
343
- const next = {};
344
- headers.forEach((header)=>{
345
- const width = header.getBoundingClientRect().width;
346
- if (header.dataset.columnId && width > 0) next[header.dataset.columnId] = width;
347
- });
348
- setRenderedWidths((current)=>Object.keys(current).length === Object.keys(next).length && Object.keys(next).every((id)=>current[id] === next[id]) ? current : next);
349
- };
350
- measure();
351
- if ("u" < typeof ResizeObserver) return;
352
- const observer = new ResizeObserver(measure);
353
- headers.forEach((header)=>observer.observe(header));
354
- return ()=>observer.disconnect();
355
- }, [
356
- visibleColumnIds,
357
- hasPinnedColumns
358
- ]);
359
- const pinnedOffsets = {};
360
- for (const group of [
361
- table.getStartVisibleLeafColumns(),
362
- [
363
- ...table.getEndVisibleLeafColumns()
364
- ].reverse()
365
- ]){
366
- let offset = 0;
367
- for (const column of group){
368
- pinnedOffsets[column.id] = offset;
369
- offset += renderedWidths[column.id] ?? column.getSize();
370
- }
371
- }
372
- const controlsEnabled = enableHiding || enableColumnOrdering || enableColumnPinning;
373
- const columnManagerReachable = columnsButtonCount > 0;
374
- const hideableColumns = table.getAllLeafColumns().filter((column)=>column.getCanHide());
375
- const filtersVisible = enableColumnFilters && columnFiltersVisible;
376
- useEffect(()=>{
377
- if (!fullScreen) return;
378
- const onKeyDown = (event)=>{
379
- if ('Escape' === event.key) setFullScreen(false);
380
- };
381
- const overflow = document.body.style.overflow;
382
- document.body.style.overflow = 'hidden';
383
- document.addEventListener('keydown', onKeyDown);
384
- return ()=>{
385
- document.body.style.overflow = overflow;
386
- document.removeEventListener('keydown', onKeyDown);
387
- };
388
- }, [
389
- fullScreen
390
- ]);
391
- const moveColumn = (id, offset)=>{
392
- const index = allColumns.findIndex((column)=>column.id === id);
393
- const column = allColumns[index];
394
- const target = allColumns[index + offset];
395
- if (!column || !target || column.getIsPinned() !== target.getIsPinned()) return;
396
- const swap = (order)=>{
397
- const from = order.indexOf(id);
398
- const to = order.indexOf(target.id);
399
- if (from < 0 || to < 0) return order;
400
- const next = [
401
- ...order
402
- ];
403
- [next[from], next[to]] = [
404
- next[to],
405
- next[from]
406
- ];
407
- return next;
408
- };
409
- const pinned = column.getIsPinned();
410
- if (pinned) table.setColumnPinning((current)=>({
411
- ...current,
412
- [pinned]: swap(current[pinned])
413
- }));
414
- else table.setColumnOrder(swap(table.getAllLeafColumns().map((column)=>column.id)));
415
- };
416
- const reorderColumns = ({ active, over })=>{
417
- if (!over || active.id === over.id) return;
418
- const source = table.getAllLeafColumns().find((column)=>column.id === active.id);
419
- const target = table.getAllLeafColumns().find((column)=>column.id === over.id);
420
- if (!source || !target || source.getIsPinned() !== target.getIsPinned()) return;
421
- const pin = source.getIsPinned();
422
- const order = table.getAllLeafColumns().map((column)=>column.id);
423
- table.setColumnOrder(arrayMove(order, order.indexOf(source.id), order.indexOf(target.id)));
424
- if (pin) table.setColumnPinning((previous)=>{
425
- const group = previous[pin] ?? [];
426
- return {
427
- ...previous,
428
- [pin]: arrayMove(group, group.indexOf(source.id), group.indexOf(target.id))
429
- };
430
- });
431
- };
432
- const searchField = enableGlobalFilter && globalFilterVisible && /*#__PURE__*/ jsx(TextField, {
433
- placeholder: strings.TABLE_SEARCH,
434
- size: "small",
435
- slotProps: {
436
- htmlInput: {
437
- 'aria-label': strings.TABLE_SEARCH
438
- },
439
- input: {
440
- startAdornment: /*#__PURE__*/ jsx(Search, {
441
- sx: {
442
- mr: '4px'
443
- }
444
- }),
445
- endAdornment: /*#__PURE__*/ jsx(InputAdornment, {
446
- position: "end",
447
- children: /*#__PURE__*/ jsx(IconButton, {
448
- size: "small",
449
- "aria-label": strings.TABLE_CLEAR_SEARCH,
450
- disabled: !table.state.globalFilter,
451
- onClick: ()=>table.setGlobalFilter(''),
452
- children: /*#__PURE__*/ jsx(Close, {})
453
- })
454
- })
455
- }
456
- },
457
- value: table.state.globalFilter ?? '',
458
- onChange: (event)=>table.setGlobalFilter(event.target.value)
459
- });
460
- return /*#__PURE__*/ jsx(EditableTableToolbarRoot, {
461
- value: {
462
- table,
463
- globalFilterVisible,
464
- columnFiltersVisible,
465
- density: density ?? 1,
466
- fullScreen,
467
- registerColumnsButton,
468
- toggleGlobalFilter: ()=>setGlobalFilterVisible((visible)=>!visible),
469
- toggleColumnFilters: ()=>setColumnFiltersVisible((visible)=>!visible),
470
- toggleDensity: ()=>setDensity((value)=>((value ?? 1) + 2) % 3),
471
- toggleFullScreen: ()=>setFullScreen((value)=>!value),
472
- openColumns: (anchor)=>{
473
- setMenuColumnId(null);
474
- setMenuAnchor(anchor);
475
- }
476
- },
477
- minHeight: "160px",
478
- padding: 2,
479
- sx: [
480
- ...Array.isArray(sx) ? sx : [
481
- sx
482
- ],
483
- ...showDensityButton || void 0 !== density ? [
484
- {
485
- '& td': {
486
- py: 0 === density ? '4px' : 2 === density ? '24px' : '16px'
487
- }
488
- }
489
- ] : [],
490
- ...fullScreen ? [
491
- {
492
- position: 'fixed',
493
- inset: 0,
494
- m: 0,
495
- p: 0,
496
- zIndex: 1200,
497
- bgcolor: 'background.paper',
498
- overflow: 'auto'
499
- }
500
- ] : []
501
- ],
502
- children: /*#__PURE__*/ jsxs(Paper, {
503
- elevation: 0,
504
- children: [
505
- enableTopToolbar && /*#__PURE__*/ jsxs(Toolbar, {
506
- disableGutters: true,
507
- sx: {
508
- gap: 1,
509
- flexWrap: 'wrap',
510
- alignItems: 'flex-start',
511
- p: 1,
512
- minHeight: '56px !important',
513
- boxSizing: 'border-box'
514
- },
515
- children: [
516
- 'left' === positionGlobalFilter && searchField,
517
- renderTopToolbarCustomActions?.({
518
- table
519
- }),
520
- /*#__PURE__*/ jsx(Box, {
521
- flexGrow: 1
522
- }),
523
- 'right' === positionGlobalFilter && searchField,
524
- enableClearAllFilters && hasFilters && /*#__PURE__*/ jsx(Button_Button, {
525
- label: clearAllFiltersLabel,
526
- priority: "ghost",
527
- size: "small",
528
- onClick: clearFilters
529
- }),
530
- /*#__PURE__*/ jsx(Box, {
531
- display: "flex",
532
- alignItems: "center",
533
- children: renderToolbarInternalActions ? renderToolbarInternalActions({
534
- table
535
- }) : /*#__PURE__*/ jsxs(Fragment, {
536
- children: [
537
- showGlobalFilterButton && enableGlobalFilter && /*#__PURE__*/ jsx(EditableTableToggleGlobalFilterButtonV2, {
538
- table: table
539
- }),
540
- showColumnFiltersButton && enableColumnFilters && /*#__PURE__*/ jsx(EditableTableToggleFiltersButtonV2, {
541
- table: table
542
- }),
543
- showColumnsButton && controlsEnabled && /*#__PURE__*/ jsx(EditableTableShowHideColumnsButtonV2, {
544
- table: table
545
- }),
546
- showDensityButton && /*#__PURE__*/ jsx(EditableTableToggleDensePaddingButtonV2, {
547
- table: table
548
- }),
549
- showFullScreenButton && /*#__PURE__*/ jsx(EditableTableToggleFullScreenButtonV2, {
550
- table: table
551
- })
552
- ]
553
- })
554
- })
555
- ]
556
- }),
557
- /*#__PURE__*/ jsxs(ColumnDragMenu, {
558
- ids: allColumns.map((column)=>column.id),
559
- onDragEnd: reorderColumns,
560
- anchorEl: menuAnchor,
561
- open: !!menuAnchor,
562
- onClose: ()=>setMenuAnchor(null),
563
- children: [
564
- menuColumnId && table.getColumn(menuColumnId)?.getCanSort() && [
565
- {
566
- label: strings.TABLE_CLEAR_SORTING,
567
- icon: /*#__PURE__*/ jsx(ClearAll, {}),
568
- disabled: !table.getColumn(menuColumnId)?.getIsSorted(),
569
- action: ()=>table.getColumn(menuColumnId)?.clearSorting()
570
- },
571
- {
572
- label: strings.TABLE_SORT_ASCENDING.replace('{column}', definitions.get(menuColumnId).header),
573
- icon: /*#__PURE__*/ jsx(Sort, {
574
- sx: {
575
- transform: 'rotate(180deg) scaleX(-1)'
576
- }
577
- }),
578
- disabled: table.getColumn(menuColumnId)?.getIsSorted() === 'asc',
579
- action: ()=>table.getColumn(menuColumnId)?.toggleSorting(false)
580
- },
581
- {
582
- label: strings.TABLE_SORT_DESCENDING.replace('{column}', definitions.get(menuColumnId).header),
583
- icon: /*#__PURE__*/ jsx(Sort, {}),
584
- disabled: table.getColumn(menuColumnId)?.getIsSorted() === 'desc',
585
- divider: table.getColumn(menuColumnId)?.getCanFilter() || enableHiding || enableColumnPinning,
586
- action: ()=>table.getColumn(menuColumnId)?.toggleSorting(true)
587
- }
588
- ].map(({ label, icon, disabled, divider, action })=>/*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
589
- icon: icon,
590
- disabled: disabled,
591
- divider: divider,
592
- onClick: ()=>{
593
- action();
594
- setMenuAnchor(null);
595
- },
596
- children: label
597
- }, label)),
598
- menuColumnId && table.getColumn(menuColumnId)?.getCanFilter() && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
599
- icon: /*#__PURE__*/ jsx(FilterListOff, {}),
600
- disabled: !table.getColumn(menuColumnId)?.getIsFiltered(),
601
- onClick: ()=>{
602
- table.getColumn(menuColumnId)?.setFilterValue(void 0);
603
- setMenuAnchor(null);
604
- },
605
- children: strings.TABLE_CLEAR_FILTER
606
- }),
607
- menuColumnId && table.getColumn(menuColumnId)?.getCanFilter() && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
608
- icon: /*#__PURE__*/ jsx(FilterList, {}),
609
- disabled: true,
610
- divider: enableHiding || enableColumnPinning,
611
- children: strings.TABLE_FILTER_BY.replace('{column}', definitions.get(menuColumnId).header)
612
- }),
613
- menuColumnId && enableColumnPinning && [
614
- {
615
- label: strings.TABLE_PIN_LEFT,
616
- direction: 'start',
617
- rotation: '90deg'
618
- },
619
- {
620
- label: strings.TABLE_PIN_RIGHT,
621
- direction: 'end',
622
- rotation: '-90deg'
623
- },
624
- {
625
- label: strings.TABLE_UNPIN,
626
- direction: false,
627
- rotation: '0deg'
628
- }
629
- ].map(({ label, direction, rotation })=>/*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
630
- icon: /*#__PURE__*/ jsx(PushPin, {
631
- sx: {
632
- transform: `rotate(${rotation})`
633
- }
634
- }),
635
- disabled: !table.getColumn(menuColumnId)?.getCanPin() || table.getColumn(menuColumnId)?.getIsPinned() === direction,
636
- divider: false === direction && enableHiding,
637
- onClick: ()=>{
638
- table.getColumn(menuColumnId)?.pin(direction);
639
- setMenuAnchor(null);
640
- },
641
- children: label
642
- }, label)),
643
- menuColumnId && enableHiding && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
644
- icon: /*#__PURE__*/ jsx(VisibilityOff, {}),
645
- disabled: !table.getColumn(menuColumnId)?.getCanHide() || !columnManagerReachable && 1 === orderedColumns.length,
646
- onClick: ()=>{
647
- table.getColumn(menuColumnId)?.toggleVisibility(false);
648
- setMenuAnchor(null);
649
- },
650
- children: strings.TABLE_HIDE_COLUMN.replace('{column}', definitions.get(menuColumnId).header)
651
- }),
652
- menuColumnId && enableHiding && enableShowAllColumnsMenuItem && /*#__PURE__*/ jsx(ColumnActionMenuItemV2, {
653
- icon: /*#__PURE__*/ jsx(ViewColumn, {}),
654
- disabled: table.getAllLeafColumns().every((column)=>column.getIsVisible() || !column.getCanHide()),
655
- onClick: ()=>{
656
- table.getAllLeafColumns().filter((column)=>column.getCanHide()).forEach((column)=>column.toggleVisibility(true));
657
- setMenuAnchor(null);
658
- },
659
- children: strings.TABLE_SHOW_ALL_COLUMNS
660
- }),
661
- !menuColumnId && enableHiding && /*#__PURE__*/ jsxs(Box, {
662
- display: "flex",
663
- justifyContent: "space-between",
664
- px: 1,
665
- pb: 1,
666
- children: [
667
- /*#__PURE__*/ jsx(Button, {
668
- disabled: !hideableColumns.some((column)=>column.getIsVisible()) || !columnManagerReachable && orderedColumns.every((column)=>column.getCanHide()),
669
- onClick: ()=>hideableColumns.forEach((column)=>column.toggleVisibility(false)),
670
- children: strings.TABLE_HIDE_ALL
671
- }),
672
- /*#__PURE__*/ jsx(Button, {
673
- disabled: hideableColumns.every((column)=>column.getIsVisible()),
674
- onClick: ()=>hideableColumns.forEach((column)=>column.toggleVisibility(true)),
675
- children: strings.TABLE_SHOW_ALL
676
- })
677
- ]
678
- }),
679
- !menuColumnId && controlsEnabled && /*#__PURE__*/ jsx(Divider, {}),
680
- allColumns.map((column, index)=>!menuColumnId && controlsEnabled && /*#__PURE__*/ jsxs(DraggableColumnItem, {
681
- id: column.id,
682
- label: definitions.get(column.id).header,
683
- enabled: enableColumnOrdering,
684
- disableRipple: true,
685
- sx: {
686
- my: 0,
687
- py: '6px',
688
- pl: '16px'
689
- },
690
- children: [
691
- /*#__PURE__*/ jsx(ColumnDragHandle, {}),
692
- /*#__PURE__*/ jsx(FormControlLabel, {
693
- label: definitions.get(column.id)?.header,
694
- slotProps: {
695
- typography: {
696
- sx: {
697
- mb: 0
698
- }
699
- }
700
- },
701
- control: /*#__PURE__*/ jsx(Switch, {
702
- checked: column.getIsVisible(),
703
- disabled: !enableHiding || !column.getCanHide() || !columnManagerReachable && column.getIsVisible() && 1 === orderedColumns.length,
704
- onChange: column.getToggleVisibilityHandler()
705
- })
706
- }),
707
- enableColumnOrdering && /*#__PURE__*/ jsxs(Fragment, {
708
- children: [
709
- /*#__PURE__*/ jsx(IconButton, {
710
- "aria-label": `${strings.TABLE_MOVE_BACK}: ${definitions.get(column.id)?.header}`,
711
- disabled: allColumns[index - 1]?.getIsPinned() !== column.getIsPinned(),
712
- onClick: ()=>moveColumn(column.id, -1),
713
- children: /*#__PURE__*/ jsx(ArrowUpward, {})
714
- }),
715
- /*#__PURE__*/ jsx(IconButton, {
716
- "aria-label": `${strings.TABLE_MOVE_FORWARD}: ${definitions.get(column.id)?.header}`,
717
- disabled: allColumns[index + 1]?.getIsPinned() !== column.getIsPinned(),
718
- onClick: ()=>moveColumn(column.id, 1),
719
- children: /*#__PURE__*/ jsx(ArrowDownward, {})
720
- })
721
- ]
722
- }),
723
- enableColumnPinning && /*#__PURE__*/ jsxs(TextField, {
724
- select: true,
725
- size: "small",
726
- label: strings.TABLE_PIN,
727
- disabled: !column.getCanPin(),
728
- value: 'start' === column.getIsPinned() ? 'left' : 'end' === column.getIsPinned() ? 'right' : '',
729
- onChange: (event)=>column.pin('left' === event.target.value ? 'start' : 'right' === event.target.value ? 'end' : false),
730
- children: [
731
- /*#__PURE__*/ jsx(MenuItem, {
732
- value: "",
733
- children: strings.TABLE_UNPIN
734
- }),
735
- /*#__PURE__*/ jsx(MenuItem, {
736
- value: "left",
737
- children: strings.TABLE_PIN_LEFT
738
- }),
739
- /*#__PURE__*/ jsx(MenuItem, {
740
- value: "right",
741
- children: strings.TABLE_PIN_RIGHT
742
- })
743
- ]
744
- })
745
- ]
746
- }, column.id))
747
- ]
748
- }),
749
- /*#__PURE__*/ jsx(ColumnDragTableContainer, {
750
- ...containerProps,
751
- ids: orderedColumns.map((column)=>column.id),
752
- onDragEnd: reorderColumns,
753
- children: /*#__PURE__*/ jsxs(Table, {
754
- ref: tableRef,
755
- sx: {
756
- minWidth: table.getTotalSize()
757
- },
758
- children: [
759
- /*#__PURE__*/ jsx(TableHead, {
760
- children: /*#__PURE__*/ jsx(TableRow, {
761
- children: orderedColumns.map((column)=>{
762
- const headCellProps = 'function' == typeof muiTableHeadCellProps ? muiTableHeadCellProps({
763
- column,
764
- table
765
- }) : muiTableHeadCellProps;
766
- const header = /*#__PURE__*/ jsxs(Fragment, {
767
- children: [
768
- /*#__PURE__*/ jsx("span", {
769
- className: "Mui-TableHeadCell-Content-Wrapper",
770
- children: definitions.get(column.id)?.header
771
- }),
772
- column.getIsFiltered() && /*#__PURE__*/ jsx(Tooltip, {
773
- title: `${strings.TABLE_FILTERED}: ${definitions.get(column.id)?.header}`,
774
- children: /*#__PURE__*/ jsx(FilterAlt, {
775
- sx: {
776
- color: 'action.active',
777
- ml: '4px',
778
- width: '18px',
779
- height: '18px'
780
- },
781
- role: "img",
782
- "aria-label": `${strings.TABLE_FILTERED}: ${definitions.get(column.id)?.header}`,
783
- onClick: (event)=>event.stopPropagation()
784
- })
785
- })
786
- ]
787
- });
788
- return /*#__PURE__*/ createElement(DraggableColumnHeader, {
789
- ...headCellProps,
790
- key: column.id,
791
- "data-column-id": column.id,
792
- "data-pinned": column.getIsPinned() ? 'true' : void 0,
793
- id: column.id,
794
- label: definitions.get(column.id).header,
795
- enabled: enableColumnDragging || enableColumnOrdering,
796
- sortDirection: column.getIsSorted() || false,
797
- sx: [
798
- (theme)=>({
799
- ...pinnedStyles(column, theme, pinnedOffsets),
800
- bgcolor: 'background.paper',
801
- fontWeight: 'bold',
802
- p: 2,
803
- pt: '12px',
804
- pb: filtersVisible ? '6.4px' : '9.6px',
805
- verticalAlign: 'top',
806
- '&:hover .MuiIconButton-root': {
807
- opacity: 1
808
- }
809
- }),
810
- ...Array.isArray(headCellProps?.sx) ? headCellProps.sx : [
811
- headCellProps?.sx
812
- ]
813
- ],
814
- children: [
815
- /*#__PURE__*/ jsxs(Box, {
816
- display: "flex",
817
- alignItems: "center",
818
- sx: {
819
- minHeight: '24px'
820
- },
821
- children: [
822
- column.getCanSort() ? /*#__PURE__*/ jsx(TableSortLabel, {
823
- active: !!column.getIsSorted(),
824
- direction: column.getIsSorted() || 'asc',
825
- IconComponent: column.getIsSorted() ? ArrowDownward : UnsortedIcon,
826
- sx: (theme)=>({
827
- fontWeight: 'inherit',
828
- whiteSpace: definitions.get(column.id).header.length < 20 ? 'nowrap' : 'normal',
829
- '& .MuiTableSortLabel-icon': {
830
- color: `${'dark' === theme.palette.mode ? theme.palette.text.primary : theme.palette.text.secondary} !important`,
831
- opacity: column.getIsSorted() ? 1 : 0.3,
832
- width: '3ch',
833
- m: 0
834
- }
835
- }),
836
- onClick: column.getToggleSortingHandler(),
837
- children: header
838
- }) : header,
839
- /*#__PURE__*/ jsx(ColumnDragHandle, {}),
840
- enableColumnActions && (column.getCanSort() || column.getCanFilter() || controlsEnabled) && /*#__PURE__*/ jsx(IconButton, {
841
- size: "small",
842
- sx: {
843
- height: '2rem',
844
- width: '2rem',
845
- m: '-8px -4px',
846
- opacity: 0.3,
847
- transition: 'all 150ms'
848
- },
849
- "aria-label": `${strings.TABLE_COLUMN_ACTIONS}: ${definitions.get(column.id)?.header}`,
850
- "aria-haspopup": "menu",
851
- "aria-expanded": !!menuAnchor && menuColumnId === column.id,
852
- onClick: (event)=>{
853
- setMenuColumnId(column.id);
854
- setMenuAnchor(event.currentTarget);
855
- },
856
- children: /*#__PURE__*/ jsx(MoreVert, {
857
- sx: {
858
- transform: 'scale(0.9)'
859
- }
860
- })
861
- })
862
- ]
863
- }, "content"),
864
- filtersVisible && column.getCanFilter() && /*#__PURE__*/ jsx(ColumnFilter, {
865
- column: column,
866
- definition: definitions.get(column.id)
867
- }, "filter")
868
- ]
869
- });
870
- })
871
- })
872
- }),
873
- /*#__PURE__*/ jsxs(TableBody, {
874
- children: [
875
- rows.map((row, rowIndex)=>/*#__PURE__*/ jsx(TableRow, {
876
- onClick: onRowClick ? ()=>onRowClick(row.original) : void 0,
877
- sx: (theme)=>{
878
- const background = theme.palette.background.default;
879
- const hoverColor = alpha('dark' === theme.palette.mode ? lighten(background, 0.3) : darken(background, 0.3), 0.3);
880
- return {
881
- cursor: onRowClick ? 'pointer' : 'default',
882
- '&:hover > td': {
883
- backgroundImage: `linear-gradient(${hoverColor}, ${hoverColor})`
884
- }
885
- };
886
- },
887
- children: [
888
- ...row.getStartVisibleCells(),
889
- ...row.getCenterVisibleCells(),
890
- ...row.getEndVisibleCells()
891
- ].map((cell)=>{
892
- const column = cell.column;
893
- const definition = definitions.get(column.id);
894
- const editConfig = definition.editConfig;
895
- const canEdit = ('function' == typeof definition.enableEditing ? definition.enableEditing(row) : definition.enableEditing ?? enableEditing) && enableEditing && (!!editConfig?.onSave || editConfig?.editVariant === 'custom' && !!editConfig.customEditComponent);
896
- const value = cell.getValue();
897
- const bodyCellProps = 'function' == typeof muiTableBodyCellProps ? muiTableBodyCellProps({
898
- cell,
899
- column,
900
- row,
901
- table
902
- }) : muiTableBodyCellProps;
903
- return /*#__PURE__*/ createElement(ColumnDragBodyCell, {
904
- ...bodyCellProps,
905
- key: cell.id,
906
- columnId: column.id,
907
- lastRow: rowIndex === rows.length - 1,
908
- "data-pinned": column.getIsPinned() ? 'true' : void 0,
909
- tabIndex: bodyCellProps?.tabIndex ?? (canEdit ? 0 : void 0),
910
- onClick: (event)=>{
911
- if (canEdit) event.stopPropagation();
912
- bodyCellProps?.onClick?.(event);
913
- },
914
- onDoubleClick: (event)=>{
915
- if (canEdit) setEditingCell({
916
- id: cell.id
917
- });
918
- bodyCellProps?.onDoubleClick?.(event);
919
- },
920
- onKeyDown: (event)=>{
921
- if (canEdit && event.target === event.currentTarget) {
922
- if ('Enter' === event.key || 'F2' === event.key) {
923
- event.preventDefault();
924
- setEditingCell({
925
- id: cell.id
926
- });
927
- }
928
- }
929
- bodyCellProps?.onKeyDown?.(event);
930
- },
931
- sx: [
932
- (theme)=>({
933
- ...pinnedStyles(column, theme, pinnedOffsets),
934
- borderBottom: 'none',
935
- bgcolor: rowIndex % 2 === 0 ? 'TwClrBaseGray025' : 'background.paper',
936
- cursor: canEdit ? 'pointer' : 'inherit',
937
- outlineOffset: '-1px',
938
- '&:hover': {
939
- outline: canEdit ? '1px solid' : void 0,
940
- outlineColor: 'grey.500'
941
- }
942
- }),
943
- ...Array.isArray(bodyCellProps?.sx) ? bodyCellProps.sx : [
944
- bodyCellProps?.sx
945
- ]
946
- ]
947
- }, editingCell?.id === cell.id ? /*#__PURE__*/ jsx(EditableCellV2, {
948
- cell: cell,
949
- column: definition,
950
- onClose: ()=>setEditingCell((current)=>current === editingCell ? null : current)
951
- }, cell.id) : definition.Cell ? /*#__PURE__*/ jsx(definition.Cell, {
952
- ...cell.getContext()
953
- }) : String(value ?? ''));
954
- })
955
- }, row.id)),
956
- !rows.length && /*#__PURE__*/ jsx(TableRow, {
957
- children: /*#__PURE__*/ jsx(TableCell, {
958
- colSpan: Math.max(1, visibleColumns.length),
959
- children: strings.TABLE_NO_ROWS
960
- })
961
- })
962
- ]
963
- })
964
- ]
965
- })
966
- }),
967
- enablePagination && enableBottomToolbar && /*#__PURE__*/ jsx(TablePagination, {
968
- component: "div",
969
- sx: (theme)=>({
970
- boxShadow: `0 1px 2px -1px ${alpha(theme.palette.grey[700], 0.5)} inset`
971
- }),
972
- showFirstButton: true,
973
- showLastButton: true,
974
- count: pageCountWithoutRowCount ? -1 : table.getRowCount(),
975
- slotProps: pageCountWithoutRowCount ? {
976
- actions: 'rtl' === theme.direction ? {
977
- previousButton: nextPageButton,
978
- firstButton: lastPageButton
979
- } : {
980
- nextButton: nextPageButton,
981
- lastButton: lastPageButton
982
- }
983
- } : void 0,
984
- page: table.state.pagination.pageIndex,
985
- rowsPerPage: table.state.pagination.pageSize,
986
- rowsPerPageOptions: Array.from(new Set([
987
- table.state.pagination.pageSize,
988
- 10,
989
- 25,
990
- 50,
991
- 100
992
- ])).sort((a, b)=>a - b),
993
- labelRowsPerPage: strings.TABLE_ROWS_PER_PAGE,
994
- labelDisplayedRows: ({ from, to, count })=>pageCountWithoutRowCount ? `${rows.length ? from : 0}–${rows.length ? from + rows.length - 1 : 0}` : `${from}–${to} / ${count}`,
995
- getItemAriaLabel: (type)=>({
996
- first: strings.TABLE_FIRST_PAGE,
997
- last: strings.TABLE_LAST_PAGE,
998
- next: strings.TABLE_NEXT_PAGE,
999
- previous: strings.TABLE_PREVIOUS_PAGE
1000
- })[type],
1001
- onPageChange: (_, page)=>table.setPageIndex(page),
1002
- onRowsPerPageChange: (event)=>table.setPageSize(Number(event.target.value))
1003
- })
1004
- ]
1005
- })
1006
- });
1007
- };
1008
- const components_EditableTableV2 = EditableTableV2;
1009
- export default components_EditableTableV2;