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

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