@perses-dev/components 0.30.0 → 0.31.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.
- package/dist/Legend/CompactLegend.d.ts +6 -4
- package/dist/Legend/CompactLegend.d.ts.map +1 -1
- package/dist/Legend/CompactLegend.js +4 -1
- package/dist/Legend/CompactLegend.js.map +1 -1
- package/dist/Legend/Legend.d.ts +11 -9
- package/dist/Legend/Legend.d.ts.map +1 -1
- package/dist/Legend/Legend.js +45 -11
- package/dist/Legend/Legend.js.map +1 -1
- package/dist/Legend/ListLegend.d.ts +5 -8
- package/dist/Legend/ListLegend.d.ts.map +1 -1
- package/dist/Legend/ListLegend.js +34 -99
- package/dist/Legend/ListLegend.js.map +1 -1
- package/dist/Legend/ListLegendItem.d.ts +8 -8
- package/dist/Legend/ListLegendItem.d.ts.map +1 -1
- package/dist/Legend/ListLegendItem.js +9 -12
- package/dist/Legend/ListLegendItem.js.map +1 -1
- package/dist/LineChart/LineChart.d.ts +2 -1
- package/dist/LineChart/LineChart.d.ts.map +1 -1
- package/dist/LineChart/LineChart.js +31 -22
- package/dist/LineChart/LineChart.js.map +1 -1
- package/dist/Table/InnerTable.d.ts +9 -0
- package/dist/Table/InnerTable.d.ts.map +1 -0
- package/dist/Table/InnerTable.js +38 -0
- package/dist/Table/InnerTable.js.map +1 -0
- package/dist/Table/Table.d.ts +10 -0
- package/dist/Table/Table.d.ts.map +1 -0
- package/dist/Table/Table.js +101 -0
- package/dist/Table/Table.js.map +1 -0
- package/dist/Table/TableBody.d.ts +6 -0
- package/dist/Table/TableBody.d.ts.map +1 -0
- package/dist/Table/TableBody.js +23 -0
- package/dist/Table/TableBody.js.map +1 -0
- package/dist/Table/TableCell.d.ts +18 -0
- package/dist/Table/TableCell.d.ts.map +1 -0
- package/dist/Table/TableCell.js +91 -0
- package/dist/Table/TableCell.js.map +1 -0
- package/dist/Table/TableCheckbox.d.ts +9 -0
- package/dist/Table/TableCheckbox.d.ts.map +1 -0
- package/dist/Table/TableCheckbox.js +49 -0
- package/dist/Table/TableCheckbox.js.map +1 -0
- package/dist/Table/TableHead.d.ts +6 -0
- package/dist/Table/TableHead.d.ts.map +1 -0
- package/dist/Table/TableHead.js +23 -0
- package/dist/Table/TableHead.js.map +1 -0
- package/dist/Table/TableRow.d.ts +9 -0
- package/dist/Table/TableRow.d.ts.map +1 -0
- package/dist/Table/TableRow.js +29 -0
- package/dist/Table/TableRow.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +11 -0
- package/dist/Table/VirtualizedTable.d.ts.map +1 -0
- package/dist/Table/VirtualizedTable.js +152 -0
- package/dist/Table/VirtualizedTable.js.map +1 -0
- package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
- package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
- package/dist/Table/VirtualizedTableContainer.js +24 -0
- package/dist/Table/VirtualizedTableContainer.js.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
- package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
- package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
- package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
- package/dist/Table/index.d.ts +4 -0
- package/dist/Table/index.d.ts.map +1 -0
- package/dist/Table/index.js +16 -0
- package/dist/Table/index.js.map +1 -0
- package/dist/Table/model/table-model.d.ts +83 -0
- package/dist/Table/model/table-model.d.ts.map +1 -0
- package/dist/Table/model/table-model.js +73 -0
- package/dist/Table/model/table-model.js.map +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
- package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
- package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +2 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +60 -15
- package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
- package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TooltipContent.js +79 -42
- package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +1 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
- package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
- package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
- package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +8 -4
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +6 -2
- package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
- package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/utils.js +4 -3
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/Legend/CompactLegend.js +4 -1
- package/dist/cjs/Legend/Legend.js +45 -11
- package/dist/cjs/Legend/ListLegend.js +33 -98
- package/dist/cjs/Legend/ListLegendItem.js +8 -11
- package/dist/cjs/LineChart/LineChart.js +31 -22
- package/dist/cjs/Table/InnerTable.js +44 -0
- package/dist/cjs/Table/Table.js +102 -0
- package/dist/cjs/Table/TableBody.js +29 -0
- package/dist/cjs/Table/TableCell.js +97 -0
- package/dist/cjs/Table/TableCheckbox.js +55 -0
- package/dist/cjs/Table/TableHead.js +29 -0
- package/dist/cjs/Table/TableRow.js +35 -0
- package/dist/cjs/Table/VirtualizedTable.js +155 -0
- package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
- package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
- package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
- package/dist/cjs/Table/index.js +33 -0
- package/dist/cjs/Table/model/table-model.js +80 -0
- package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
- package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +57 -12
- package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +83 -41
- package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
- package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +11 -3
- package/dist/cjs/TimeSeriesTooltip/utils.js +3 -2
- package/dist/cjs/context/SnackbarProvider.js +66 -0
- package/dist/cjs/index.js +2 -0
- package/dist/cjs/model/legend.js +7 -1
- package/dist/cjs/theme/palette/grey.js +6 -2
- package/dist/context/SnackbarProvider.d.ts +23 -0
- package/dist/context/SnackbarProvider.d.ts.map +1 -0
- package/dist/context/SnackbarProvider.js +59 -0
- package/dist/context/SnackbarProvider.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/model/legend.d.ts +10 -2
- package/dist/model/legend.d.ts.map +1 -1
- package/dist/model/legend.js +5 -0
- package/dist/model/legend.js.map +1 -1
- package/dist/theme/palette/grey.d.ts.map +1 -1
- package/dist/theme/palette/grey.js +6 -2
- package/dist/theme/palette/grey.js.map +1 -1
- package/package.json +6 -6
- package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
- package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/focused-series.js +0 -110
- package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
- package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -116
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "Table", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>Table
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _reactTable = require("@tanstack/react-table");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _react = require("react");
|
|
25
|
+
const _virtualizedTable = require("./VirtualizedTable");
|
|
26
|
+
const _tableCheckbox = require("./TableCheckbox");
|
|
27
|
+
const _tableModel = require("./model/table-model");
|
|
28
|
+
const DEFAULT_GET_ROW_ID = (data, index)=>{
|
|
29
|
+
return `${index}`;
|
|
30
|
+
};
|
|
31
|
+
function Table({ data , columns , density ='standard' , checkboxSelection , onRowSelectionChange , getCheckboxColor , getRowId =DEFAULT_GET_ROW_ID , rowSelection ={} , ...otherProps }) {
|
|
32
|
+
const theme = (0, _material.useTheme)();
|
|
33
|
+
const handleRowSelectionChange = (rowSelectionUpdater)=>{
|
|
34
|
+
const newRowSelection = typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;
|
|
35
|
+
onRowSelectionChange === null || onRowSelectionChange === void 0 ? void 0 : onRowSelectionChange(newRowSelection);
|
|
36
|
+
};
|
|
37
|
+
const checkboxColumn = (0, _react.useMemo)(()=>{
|
|
38
|
+
return {
|
|
39
|
+
id: 'checkboxRowSelect',
|
|
40
|
+
size: 32,
|
|
41
|
+
header: ({ table })=>{
|
|
42
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCheckbox.TableCheckbox, {
|
|
43
|
+
checked: table.getIsAllRowsSelected(),
|
|
44
|
+
indeterminate: table.getIsSomeRowsSelected(),
|
|
45
|
+
onChange: table.getToggleAllRowsSelectedHandler(),
|
|
46
|
+
color: theme.palette.text.primary,
|
|
47
|
+
density: density
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
cell: ({ row })=>{
|
|
51
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCheckbox.TableCheckbox, {
|
|
52
|
+
checked: row.getIsSelected(),
|
|
53
|
+
indeterminate: row.getIsSomeSelected(),
|
|
54
|
+
onChange: (e)=>{
|
|
55
|
+
row.getToggleSelectedHandler()(e);
|
|
56
|
+
},
|
|
57
|
+
color: getCheckboxColor === null || getCheckboxColor === void 0 ? void 0 : getCheckboxColor(row.original),
|
|
58
|
+
density: density
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}, [
|
|
63
|
+
density,
|
|
64
|
+
getCheckboxColor,
|
|
65
|
+
theme.palette.text.primary
|
|
66
|
+
]);
|
|
67
|
+
const tableColumns = (0, _react.useMemo)(()=>{
|
|
68
|
+
const initTableColumns = (0, _tableModel.persesColumnsToTanstackColumns)(columns);
|
|
69
|
+
if (checkboxSelection) {
|
|
70
|
+
initTableColumns.unshift(checkboxColumn);
|
|
71
|
+
}
|
|
72
|
+
return initTableColumns;
|
|
73
|
+
}, [
|
|
74
|
+
checkboxColumn,
|
|
75
|
+
checkboxSelection,
|
|
76
|
+
columns
|
|
77
|
+
]);
|
|
78
|
+
const table = (0, _reactTable.useReactTable)({
|
|
79
|
+
data,
|
|
80
|
+
columns: tableColumns,
|
|
81
|
+
getRowId,
|
|
82
|
+
getCoreRowModel: (0, _reactTable.getCoreRowModel)(),
|
|
83
|
+
enableRowSelection: !!checkboxSelection,
|
|
84
|
+
onRowSelectionChange: handleRowSelectionChange,
|
|
85
|
+
state: {
|
|
86
|
+
rowSelection
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
const handleRowClick = (0, _react.useCallback)((rowId)=>{
|
|
90
|
+
table.getRow(rowId).toggleSelected();
|
|
91
|
+
}, [
|
|
92
|
+
table
|
|
93
|
+
]);
|
|
94
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_virtualizedTable.VirtualizedTable, {
|
|
95
|
+
...otherProps,
|
|
96
|
+
density: density,
|
|
97
|
+
onRowClick: handleRowClick,
|
|
98
|
+
rows: table.getRowModel().rows,
|
|
99
|
+
columns: table.getAllFlatColumns(),
|
|
100
|
+
headers: table.getHeaderGroups()
|
|
101
|
+
});
|
|
102
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TableBody", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TableBody
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
const TableBody = /*#__PURE__*/ (0, _react.forwardRef)(function TableBody(props, ref) {
|
|
25
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableBody, {
|
|
26
|
+
...props,
|
|
27
|
+
ref: ref
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TableCell", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TableCell
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
const _tableModel = require("./model/table-model");
|
|
25
|
+
const StyledMuiTableCell = (0, _material.styled)(_material.TableCell)(({ theme })=>({
|
|
26
|
+
padding: 0,
|
|
27
|
+
backgroundColor: 'inherit',
|
|
28
|
+
'&.MuiTableCell-head': {
|
|
29
|
+
// Important to avoid scrolling behind the header showing through.
|
|
30
|
+
backgroundColor: theme.palette.background.paper
|
|
31
|
+
},
|
|
32
|
+
'&:focus-visible': {
|
|
33
|
+
outline: `solid 1px ${theme.palette.primary.main}`,
|
|
34
|
+
// Move inward a little to avoid getting cut off when focusing on items
|
|
35
|
+
// at the edge of the table.
|
|
36
|
+
outlineOffset: '-1px',
|
|
37
|
+
borderRadius: 0
|
|
38
|
+
}
|
|
39
|
+
}));
|
|
40
|
+
function TableCell({ children , density , variant , width , focusState ='none' , onFocusTrigger , ...otherProps }) {
|
|
41
|
+
const theme = (0, _material.useTheme)();
|
|
42
|
+
const elRef = (0, _react.useRef)();
|
|
43
|
+
const isHeader = variant === 'head';
|
|
44
|
+
(0, _react.useEffect)(()=>{
|
|
45
|
+
if (focusState === 'trigger-focus' && elRef.current) {
|
|
46
|
+
elRef.current.focus();
|
|
47
|
+
}
|
|
48
|
+
}, [
|
|
49
|
+
focusState
|
|
50
|
+
]);
|
|
51
|
+
const handleFocus = (e)=>{
|
|
52
|
+
var ref;
|
|
53
|
+
// From https://zellwk.com/blog/keyboard-focusable-elements/
|
|
54
|
+
const nestedFocusTarget = (ref = e.currentTarget) === null || ref === void 0 ? void 0 : ref.querySelector('a[href], button, input, textarea, select, details');
|
|
55
|
+
if (nestedFocusTarget) {
|
|
56
|
+
// If the cell has a focusable child, focus it instead. Mostly used for
|
|
57
|
+
// checkbox cells, but could have other uses.
|
|
58
|
+
nestedFocusTarget.focus();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
const handleInteractionFocusTrigger = (e)=>{
|
|
62
|
+
// We use `onClick` and `onKeyUp` events instead of `onFocus` because of
|
|
63
|
+
// some ordering issues with when the browser calls events and how this
|
|
64
|
+
// plays with the triggering of focus with keyboard interactions.
|
|
65
|
+
// These report that a focus event happened, so we can adjust the current
|
|
66
|
+
// tabindex and focuses to the right cell.
|
|
67
|
+
onFocusTrigger === null || onFocusTrigger === void 0 ? void 0 : onFocusTrigger(e);
|
|
68
|
+
};
|
|
69
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledMuiTableCell, {
|
|
70
|
+
...otherProps,
|
|
71
|
+
// Modify the tab index based on the currently focused cell. It's important
|
|
72
|
+
// to avoid having tabindex 0 on everything because it essentially traps
|
|
73
|
+
// a keyboard user in the table until they hit "tab" for every single
|
|
74
|
+
// cell.
|
|
75
|
+
tabIndex: focusState !== 'none' ? 0 : -1,
|
|
76
|
+
onFocus: handleFocus,
|
|
77
|
+
onClick: handleInteractionFocusTrigger,
|
|
78
|
+
onKeyUp: handleInteractionFocusTrigger,
|
|
79
|
+
sx: {
|
|
80
|
+
width: width,
|
|
81
|
+
borderBottom: isHeader ? (theme)=>`solid 1px ${theme.palette.grey[100]}` : `solid 1px ${theme.palette.grey[50]}`
|
|
82
|
+
},
|
|
83
|
+
ref: elRef,
|
|
84
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
85
|
+
sx: {
|
|
86
|
+
...(0, _tableModel.getTableCellLayout)(theme, density),
|
|
87
|
+
position: 'relative',
|
|
88
|
+
// Text truncation. Currently enforced on all cells. We may control
|
|
89
|
+
// this with a prop on column config in the future.
|
|
90
|
+
whiteSpace: 'nowrap',
|
|
91
|
+
overflow: 'hidden',
|
|
92
|
+
textOverflow: 'ellipsis'
|
|
93
|
+
},
|
|
94
|
+
children: children
|
|
95
|
+
})
|
|
96
|
+
});
|
|
97
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TableCheckbox", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TableCheckbox
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
function TableCheckbox({ color , density , ...otherProps }) {
|
|
24
|
+
const isCompact = density === 'compact';
|
|
25
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Checkbox, {
|
|
26
|
+
size: isCompact ? 'small' : 'medium',
|
|
27
|
+
...otherProps,
|
|
28
|
+
// Disable ripple and set background color below because of some issues
|
|
29
|
+
// with re-rendering with the keyboard interactions that causes the ripple
|
|
30
|
+
// animation to stutter.
|
|
31
|
+
focusRipple: false,
|
|
32
|
+
// Tab index is handled by the overall keyboard interactions for the table
|
|
33
|
+
// to avoid trapping a keyboard user in a table by requiring them to tab
|
|
34
|
+
// through every single checkbox.
|
|
35
|
+
tabIndex: -1,
|
|
36
|
+
sx: {
|
|
37
|
+
color: color,
|
|
38
|
+
padding: (theme)=>theme.spacing(isCompact ? 0.25 : 0.5),
|
|
39
|
+
// Centering.
|
|
40
|
+
position: 'absolute',
|
|
41
|
+
top: '50%',
|
|
42
|
+
left: '50%',
|
|
43
|
+
transform: 'translate(-50%, -50%)',
|
|
44
|
+
'&.Mui-checked': {
|
|
45
|
+
color: color
|
|
46
|
+
},
|
|
47
|
+
'&.Mui-focusVisible': {
|
|
48
|
+
background: color ? (0, _material.alpha)(color, 0.5) : undefined
|
|
49
|
+
},
|
|
50
|
+
'& .MuiSvgIcon-root': {
|
|
51
|
+
fontSize: isCompact ? 14 : 16
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TableHead", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TableHead
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
const TableHead = /*#__PURE__*/ (0, _react.forwardRef)(function TableHead(props, ref) {
|
|
25
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableHead, {
|
|
26
|
+
...props,
|
|
27
|
+
ref: ref
|
|
28
|
+
});
|
|
29
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "TableRow", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>TableRow
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
const TableRow = /*#__PURE__*/ (0, _react.forwardRef)(function TableRow(props, ref) {
|
|
25
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableRow, {
|
|
26
|
+
...props,
|
|
27
|
+
ref: ref,
|
|
28
|
+
sx: {
|
|
29
|
+
backgroundColor: (theme)=>theme.palette.background.paper,
|
|
30
|
+
'&:hover': {
|
|
31
|
+
backgroundColor: (theme)=>theme.palette.primary.light
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
});
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "VirtualizedTable", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>VirtualizedTable
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _reactTable = require("@tanstack/react-table");
|
|
23
|
+
const _material = require("@mui/material");
|
|
24
|
+
const _reactVirtuoso = require("react-virtuoso");
|
|
25
|
+
const _react = require("react");
|
|
26
|
+
const _tableRow = require("./TableRow");
|
|
27
|
+
const _tableBody = require("./TableBody");
|
|
28
|
+
const _innerTable = require("./InnerTable");
|
|
29
|
+
const _tableHead = require("./TableHead");
|
|
30
|
+
const _tableCell = require("./TableCell");
|
|
31
|
+
const _virtualizedTableContainer = require("./VirtualizedTableContainer");
|
|
32
|
+
const _useVirtualizedTableKeyboardNav = require("./hooks/useVirtualizedTableKeyboardNav");
|
|
33
|
+
function VirtualizedTable({ width , height , density , onRowClick , rows , columns , headers }) {
|
|
34
|
+
const virtuosoRef = (0, _react.useRef)(null);
|
|
35
|
+
// Use a ref for these values because they are only needed for keyboard
|
|
36
|
+
// focus interactions and setting them on state will lead to a significant
|
|
37
|
+
// amount of unnecessary re-renders.
|
|
38
|
+
const visibleRange = (0, _react.useRef)({
|
|
39
|
+
startIndex: 0,
|
|
40
|
+
endIndex: 0
|
|
41
|
+
});
|
|
42
|
+
const setVisibleRange = (newVisibleRange)=>{
|
|
43
|
+
visibleRange.current = newVisibleRange;
|
|
44
|
+
};
|
|
45
|
+
const keyboardNav = (0, _useVirtualizedTableKeyboardNav.useVirtualizedTableKeyboardNav)({
|
|
46
|
+
visibleRange: visibleRange,
|
|
47
|
+
virtualTable: virtuosoRef,
|
|
48
|
+
// We add 1 here for the header.
|
|
49
|
+
maxRows: rows.length + 1,
|
|
50
|
+
maxColumns: columns.length
|
|
51
|
+
});
|
|
52
|
+
const getFocusState = (cellPosition)=>{
|
|
53
|
+
if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {
|
|
54
|
+
return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';
|
|
55
|
+
}
|
|
56
|
+
return 'none';
|
|
57
|
+
};
|
|
58
|
+
const VirtuosoTableComponents = (0, _react.useMemo)(()=>{
|
|
59
|
+
return {
|
|
60
|
+
Scroller: _virtualizedTableContainer.VirtualizedTableContainer,
|
|
61
|
+
Table: (props)=>{
|
|
62
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_innerTable.InnerTable, {
|
|
63
|
+
...props,
|
|
64
|
+
width: width,
|
|
65
|
+
density: density,
|
|
66
|
+
onKeyDown: keyboardNav.onTableKeyDown
|
|
67
|
+
});
|
|
68
|
+
},
|
|
69
|
+
TableHead: _tableHead.TableHead,
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
71
|
+
TableRow: ({ item , ...props })=>{
|
|
72
|
+
const index = props['data-index'];
|
|
73
|
+
const row = rows[index];
|
|
74
|
+
if (!row) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableRow.TableRow, {
|
|
78
|
+
...props,
|
|
79
|
+
onClick: ()=>onRowClick(row.id),
|
|
80
|
+
density: density
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
TableBody: _tableBody.TableBody
|
|
84
|
+
};
|
|
85
|
+
}, [
|
|
86
|
+
density,
|
|
87
|
+
keyboardNav.onTableKeyDown,
|
|
88
|
+
onRowClick,
|
|
89
|
+
rows,
|
|
90
|
+
width
|
|
91
|
+
]);
|
|
92
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
|
|
93
|
+
sx: {
|
|
94
|
+
width,
|
|
95
|
+
height
|
|
96
|
+
},
|
|
97
|
+
children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_reactVirtuoso.TableVirtuoso, {
|
|
98
|
+
ref: virtuosoRef,
|
|
99
|
+
totalCount: rows.length,
|
|
100
|
+
components: VirtuosoTableComponents,
|
|
101
|
+
// Note: this value is impacted by overscan. See this issue if overscan
|
|
102
|
+
// is added.
|
|
103
|
+
// https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138
|
|
104
|
+
rangeChanged: setVisibleRange,
|
|
105
|
+
fixedHeaderContent: ()=>{
|
|
106
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
107
|
+
children: headers.map((headerGroup)=>{
|
|
108
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableRow.TableRow, {
|
|
109
|
+
density: density,
|
|
110
|
+
children: headerGroup.headers.map((header, i)=>{
|
|
111
|
+
const column = header.column;
|
|
112
|
+
const position = {
|
|
113
|
+
row: 0,
|
|
114
|
+
column: i
|
|
115
|
+
};
|
|
116
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCell.TableCell, {
|
|
117
|
+
width: column.getSize() || 'auto',
|
|
118
|
+
variant: "head",
|
|
119
|
+
density: density,
|
|
120
|
+
focusState: getFocusState(position),
|
|
121
|
+
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
122
|
+
children: (0, _reactTable.flexRender)(column.columnDef.header, header.getContext())
|
|
123
|
+
}, header.id);
|
|
124
|
+
})
|
|
125
|
+
}, headerGroup.id);
|
|
126
|
+
})
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
itemContent: (index)=>{
|
|
130
|
+
const row = rows[index];
|
|
131
|
+
if (!row) {
|
|
132
|
+
return null;
|
|
133
|
+
}
|
|
134
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
|
|
135
|
+
children: row.getVisibleCells().map((cell, i)=>{
|
|
136
|
+
const position = {
|
|
137
|
+
// Add 1 to the row index because the header is row 0
|
|
138
|
+
row: index + 1,
|
|
139
|
+
column: i
|
|
140
|
+
};
|
|
141
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCell.TableCell, {
|
|
142
|
+
sx: {
|
|
143
|
+
width: cell.column.getSize() || 'auto'
|
|
144
|
+
},
|
|
145
|
+
density: density,
|
|
146
|
+
focusState: getFocusState(position),
|
|
147
|
+
onFocusTrigger: ()=>keyboardNav.onCellFocus(position),
|
|
148
|
+
children: (0, _reactTable.flexRender)(cell.column.columnDef.cell, cell.getContext())
|
|
149
|
+
}, cell.id);
|
|
150
|
+
})
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
})
|
|
154
|
+
});
|
|
155
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "VirtualizedTableContainer", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>VirtualizedTableContainer
|
|
20
|
+
});
|
|
21
|
+
const _jsxRuntime = require("react/jsx-runtime");
|
|
22
|
+
const _material = require("@mui/material");
|
|
23
|
+
const _react = require("react");
|
|
24
|
+
const VirtualizedTableContainer = /*#__PURE__*/ (0, _react.forwardRef)(function VirtualizedTableContainer(props, ref) {
|
|
25
|
+
return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableContainer, {
|
|
26
|
+
...props,
|
|
27
|
+
tabIndex: -1,
|
|
28
|
+
ref: ref
|
|
29
|
+
});
|
|
30
|
+
});
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// Copyright 2023 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
"use strict";
|
|
14
|
+
Object.defineProperty(exports, "__esModule", {
|
|
15
|
+
value: true
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(exports, "useTableKeyboardNav", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: ()=>useTableKeyboardNav
|
|
20
|
+
});
|
|
21
|
+
const _react = require("react");
|
|
22
|
+
const DEFAULT_ACTIVE_CELL = {
|
|
23
|
+
row: 0,
|
|
24
|
+
column: 0
|
|
25
|
+
};
|
|
26
|
+
const ARROW_KEYS = [
|
|
27
|
+
'ArrowRight',
|
|
28
|
+
'ArrowLeft',
|
|
29
|
+
'ArrowUp',
|
|
30
|
+
'ArrowDown'
|
|
31
|
+
];
|
|
32
|
+
function isArrowKey(key) {
|
|
33
|
+
return ARROW_KEYS.includes(key);
|
|
34
|
+
}
|
|
35
|
+
function useTableKeyboardNav({ maxRows , maxColumns , onActiveCellChange }) {
|
|
36
|
+
const [activeCell, setActiveCell] = (0, _react.useState)(DEFAULT_ACTIVE_CELL);
|
|
37
|
+
const [isActive, setIsActive] = (0, _react.useState)(false);
|
|
38
|
+
const handleCellFocus = (cellPosition)=>{
|
|
39
|
+
if (cellPosition.column === activeCell.column && cellPosition.row === activeCell.row && isActive) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
setIsActive(true);
|
|
43
|
+
setActiveCell(cellPosition);
|
|
44
|
+
};
|
|
45
|
+
const handleKeyDown = (0, _react.useCallback)((e)=>{
|
|
46
|
+
// Including some of the basic a11y keyboard interaction patterns from:
|
|
47
|
+
// https://www.w3.org/WAI/ARIA/apg/patterns/grid/
|
|
48
|
+
// TODO: add other keyboard combos.
|
|
49
|
+
const key = e.key;
|
|
50
|
+
if (isArrowKey(key) || key === 'Home' || key === 'End' || key === 'PageDown' || key === 'PageUp') {
|
|
51
|
+
setActiveCell((curActiveCell)=>{
|
|
52
|
+
let nextRow = curActiveCell.row;
|
|
53
|
+
let nextColumn = curActiveCell.column;
|
|
54
|
+
if (key === 'ArrowRight' && nextColumn < maxColumns - 1) {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
nextColumn += 1;
|
|
57
|
+
} else if (key === 'ArrowLeft' && nextColumn > 0) {
|
|
58
|
+
e.preventDefault();
|
|
59
|
+
nextColumn -= 1;
|
|
60
|
+
} else if (key === 'ArrowDown' && nextRow < maxRows - 1) {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
nextRow += 1;
|
|
63
|
+
} else if (key === 'ArrowUp' && nextRow > 0) {
|
|
64
|
+
e.preventDefault();
|
|
65
|
+
nextRow -= 1;
|
|
66
|
+
} else if (key === 'Home') {
|
|
67
|
+
e.preventDefault();
|
|
68
|
+
nextRow = 0;
|
|
69
|
+
nextColumn = 0;
|
|
70
|
+
} else if (key === 'End') {
|
|
71
|
+
e.preventDefault();
|
|
72
|
+
nextRow = maxRows - 1;
|
|
73
|
+
nextColumn = maxColumns - 1;
|
|
74
|
+
}
|
|
75
|
+
const defaultNewPosition = {
|
|
76
|
+
column: nextColumn,
|
|
77
|
+
row: nextRow
|
|
78
|
+
};
|
|
79
|
+
const newPosition = (onActiveCellChange === null || onActiveCellChange === void 0 ? void 0 : onActiveCellChange(e, curActiveCell, defaultNewPosition)) || defaultNewPosition;
|
|
80
|
+
if (newPosition.row === curActiveCell.row && newPosition.column === curActiveCell.column) {
|
|
81
|
+
// Return original to avoid creating a new object if nothing
|
|
82
|
+
// changed.
|
|
83
|
+
return curActiveCell;
|
|
84
|
+
}
|
|
85
|
+
return newPosition;
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}, [
|
|
89
|
+
maxColumns,
|
|
90
|
+
maxRows,
|
|
91
|
+
onActiveCellChange
|
|
92
|
+
]);
|
|
93
|
+
return {
|
|
94
|
+
activeCell,
|
|
95
|
+
isActive,
|
|
96
|
+
onTableKeyDown: handleKeyDown,
|
|
97
|
+
onCellFocus: handleCellFocus
|
|
98
|
+
};
|
|
99
|
+
}
|