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