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