@perses-dev/components 0.51.0-beta.1 → 0.51.0-rc.1
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/README.md +1 -8
- package/dist/EChart/EChart.d.ts +3 -2
- package/dist/EChart/EChart.d.ts.map +1 -1
- package/dist/EChart/EChart.js +19 -7
- package/dist/EChart/EChart.js.map +1 -1
- package/dist/JSONEditor.d.ts.map +1 -1
- package/dist/JSONEditor.js +5 -6
- package/dist/JSONEditor.js.map +1 -1
- package/dist/Table/Table.d.ts +1 -1
- package/dist/Table/Table.d.ts.map +1 -1
- package/dist/Table/Table.js +14 -4
- package/dist/Table/Table.js.map +1 -1
- package/dist/Table/TableFoot.d.ts +4 -0
- package/dist/Table/TableFoot.d.ts.map +1 -0
- package/dist/{BarChart/index.js → Table/TableFoot.js} +11 -3
- package/dist/Table/TableFoot.js.map +1 -0
- package/dist/Table/VirtualizedTable.d.ts +3 -2
- package/dist/Table/VirtualizedTable.d.ts.map +1 -1
- package/dist/Table/VirtualizedTable.js +31 -2
- package/dist/Table/VirtualizedTable.js.map +1 -1
- package/dist/Table/model/table-model.d.ts +10 -1
- package/dist/Table/model/table-model.d.ts.map +1 -1
- package/dist/Table/model/table-model.js.map +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.d.ts +1 -1
- package/dist/TimeRangeSelector/TimeRangeSelector.js.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js +2 -5
- package/dist/TimeSeriesTooltip/TimeChartTooltip.js.map +1 -1
- package/dist/TimeSeriesTooltip/index.d.ts +0 -1
- package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/index.js +0 -1
- package/dist/TimeSeriesTooltip/index.js.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts +1 -8
- package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
- package/dist/TimeSeriesTooltip/tooltip-model.js +6 -16
- 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 +27 -23
- package/dist/TimeSeriesTooltip/utils.js.map +1 -1
- package/dist/cjs/EChart/EChart.js +17 -5
- package/dist/cjs/JSONEditor.js +4 -5
- package/dist/cjs/Table/Table.js +13 -3
- package/dist/cjs/{StatChart/utils/formatStatChartValue.js → Table/TableFoot.js} +12 -15
- package/dist/cjs/Table/VirtualizedTable.js +30 -1
- package/dist/cjs/TimeSeriesTooltip/TimeChartTooltip.js +1 -4
- package/dist/cjs/TimeSeriesTooltip/index.js +0 -1
- package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +6 -25
- package/dist/cjs/TimeSeriesTooltip/utils.js +26 -22
- package/dist/cjs/context/ChartsProvider.js +3 -1
- package/dist/cjs/index.js +0 -7
- package/dist/cjs/test-utils/theme.js +1 -0
- package/dist/cjs/utils/axis.js +3 -18
- package/dist/cjs/utils/format.js +0 -21
- package/dist/context/ChartsProvider.d.ts +2 -0
- package/dist/context/ChartsProvider.d.ts.map +1 -1
- package/dist/context/ChartsProvider.js +3 -1
- package/dist/context/ChartsProvider.js.map +1 -1
- package/dist/index.d.ts +0 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -7
- package/dist/index.js.map +1 -1
- package/dist/model/graph.d.ts +0 -1
- package/dist/model/graph.d.ts.map +1 -1
- package/dist/model/graph.js.map +1 -1
- package/dist/test-utils/theme.d.ts.map +1 -1
- package/dist/test-utils/theme.js +1 -0
- package/dist/test-utils/theme.js.map +1 -1
- package/dist/utils/axis.d.ts +0 -4
- package/dist/utils/axis.d.ts.map +1 -1
- package/dist/utils/axis.js +0 -9
- package/dist/utils/axis.js.map +1 -1
- package/dist/utils/chart-actions.d.ts +0 -2
- package/dist/utils/chart-actions.d.ts.map +1 -1
- package/dist/utils/chart-actions.js.map +1 -1
- package/dist/utils/format.d.ts +0 -1
- package/dist/utils/format.d.ts.map +1 -1
- package/dist/utils/format.js +0 -20
- package/dist/utils/format.js.map +1 -1
- package/package.json +2 -7
- package/dist/BarChart/BarChart.d.ts +0 -16
- package/dist/BarChart/BarChart.d.ts.map +0 -1
- package/dist/BarChart/BarChart.js +0 -134
- package/dist/BarChart/BarChart.js.map +0 -1
- package/dist/BarChart/index.d.ts +0 -2
- package/dist/BarChart/index.d.ts.map +0 -1
- package/dist/BarChart/index.js.map +0 -1
- package/dist/GaugeChart/GaugeChart.d.ts +0 -23
- package/dist/GaugeChart/GaugeChart.d.ts.map +0 -1
- package/dist/GaugeChart/GaugeChart.js +0 -214
- package/dist/GaugeChart/GaugeChart.js.map +0 -1
- package/dist/GaugeChart/index.d.ts +0 -2
- package/dist/GaugeChart/index.d.ts.map +0 -1
- package/dist/GaugeChart/index.js +0 -15
- package/dist/GaugeChart/index.js.map +0 -1
- package/dist/LineChart/LineChart.d.ts +0 -22
- package/dist/LineChart/LineChart.d.ts.map +0 -1
- package/dist/LineChart/LineChart.js +0 -266
- package/dist/LineChart/LineChart.js.map +0 -1
- package/dist/LineChart/index.d.ts +0 -2
- package/dist/LineChart/index.d.ts.map +0 -1
- package/dist/LineChart/index.js +0 -15
- package/dist/LineChart/index.js.map +0 -1
- package/dist/PieChart/PieChart.d.ts +0 -14
- package/dist/PieChart/PieChart.d.ts.map +0 -1
- package/dist/PieChart/PieChart.js +0 -92
- package/dist/PieChart/PieChart.js.map +0 -1
- package/dist/PieChart/index.d.ts +0 -2
- package/dist/PieChart/index.d.ts.map +0 -1
- package/dist/PieChart/index.js +0 -15
- package/dist/PieChart/index.js.map +0 -1
- package/dist/StatChart/StatChart.d.ts +0 -21
- package/dist/StatChart/StatChart.d.ts.map +0 -1
- package/dist/StatChart/StatChart.js +0 -185
- package/dist/StatChart/StatChart.js.map +0 -1
- package/dist/StatChart/calculateFontSize.d.ts +0 -16
- package/dist/StatChart/calculateFontSize.d.ts.map +0 -1
- package/dist/StatChart/calculateFontSize.js +0 -49
- package/dist/StatChart/calculateFontSize.js.map +0 -1
- package/dist/StatChart/index.d.ts +0 -2
- package/dist/StatChart/index.d.ts.map +0 -1
- package/dist/StatChart/index.js +0 -15
- package/dist/StatChart/index.js.map +0 -1
- package/dist/StatChart/utils/formatStatChartValue.d.ts +0 -3
- package/dist/StatChart/utils/formatStatChartValue.d.ts.map +0 -1
- package/dist/StatChart/utils/formatStatChartValue.js +0 -26
- package/dist/StatChart/utils/formatStatChartValue.js.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryChart.d.ts +0 -27
- package/dist/StatusHistoryChart/StatusHistoryChart.d.ts.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryChart.js +0 -132
- package/dist/StatusHistoryChart/StatusHistoryChart.js.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts +0 -13
- package/dist/StatusHistoryChart/StatusHistoryTooltip.d.ts.map +0 -1
- package/dist/StatusHistoryChart/StatusHistoryTooltip.js +0 -47
- package/dist/StatusHistoryChart/StatusHistoryTooltip.js.map +0 -1
- package/dist/StatusHistoryChart/get-formatted-axis-label.d.ts +0 -2
- package/dist/StatusHistoryChart/get-formatted-axis-label.d.ts.map +0 -1
- package/dist/StatusHistoryChart/get-formatted-axis-label.js +0 -41
- package/dist/StatusHistoryChart/get-formatted-axis-label.js.map +0 -1
- package/dist/StatusHistoryChart/index.d.ts +0 -3
- package/dist/StatusHistoryChart/index.d.ts.map +0 -1
- package/dist/StatusHistoryChart/index.js +0 -16
- package/dist/StatusHistoryChart/index.js.map +0 -1
- package/dist/StatusHistoryChart/utils/get-color.d.ts +0 -6
- package/dist/StatusHistoryChart/utils/get-color.d.ts.map +0 -1
- package/dist/StatusHistoryChart/utils/get-color.js +0 -100
- package/dist/StatusHistoryChart/utils/get-color.js.map +0 -1
- package/dist/StatusHistoryChart/utils/get-tooltip-position.d.ts +0 -3
- package/dist/StatusHistoryChart/utils/get-tooltip-position.d.ts.map +0 -1
- package/dist/StatusHistoryChart/utils/get-tooltip-position.js +0 -27
- package/dist/StatusHistoryChart/utils/get-tooltip-position.js.map +0 -1
- package/dist/TimeChart/TimeChart.d.ts +0 -24
- package/dist/TimeChart/TimeChart.d.ts.map +0 -1
- package/dist/TimeChart/TimeChart.js +0 -394
- package/dist/TimeChart/TimeChart.js.map +0 -1
- package/dist/TimeChart/index.d.ts +0 -2
- package/dist/TimeChart/index.d.ts.map +0 -1
- package/dist/TimeChart/index.js +0 -15
- package/dist/TimeChart/index.js.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts +0 -21
- package/dist/TimeSeriesTooltip/LineChartTooltip.d.ts.map +0 -1
- package/dist/TimeSeriesTooltip/LineChartTooltip.js +0 -104
- package/dist/TimeSeriesTooltip/LineChartTooltip.js.map +0 -1
- package/dist/cjs/BarChart/BarChart.js +0 -142
- package/dist/cjs/BarChart/index.js +0 -30
- package/dist/cjs/GaugeChart/GaugeChart.js +0 -227
- package/dist/cjs/GaugeChart/index.js +0 -30
- package/dist/cjs/LineChart/LineChart.js +0 -274
- package/dist/cjs/LineChart/index.js +0 -30
- package/dist/cjs/PieChart/PieChart.js +0 -100
- package/dist/cjs/PieChart/index.js +0 -30
- package/dist/cjs/StatChart/StatChart.js +0 -198
- package/dist/cjs/StatChart/calculateFontSize.js +0 -55
- package/dist/cjs/StatChart/index.js +0 -30
- package/dist/cjs/StatusHistoryChart/StatusHistoryChart.js +0 -140
- package/dist/cjs/StatusHistoryChart/StatusHistoryTooltip.js +0 -55
- package/dist/cjs/StatusHistoryChart/get-formatted-axis-label.js +0 -48
- package/dist/cjs/StatusHistoryChart/index.js +0 -31
- package/dist/cjs/StatusHistoryChart/utils/get-color.js +0 -125
- package/dist/cjs/StatusHistoryChart/utils/get-tooltip-position.js +0 -35
- package/dist/cjs/TimeChart/TimeChart.js +0 -407
- package/dist/cjs/TimeChart/index.js +0 -30
- package/dist/cjs/TimeSeriesTooltip/LineChartTooltip.js +0 -117
package/README.md
CHANGED
|
@@ -7,12 +7,5 @@ This [package](https://www.npmjs.com/package/@perses-dev/components) includes in
|
|
|
7
7
|
To import components from the components package use the syntax below:
|
|
8
8
|
|
|
9
9
|
```typescript
|
|
10
|
-
import {
|
|
10
|
+
import { ContentWithLegend } from "@perses-dev/components";
|
|
11
11
|
```
|
|
12
|
-
|
|
13
|
-
For detailed examples of how to use certain components, see individual docs for:
|
|
14
|
-
|
|
15
|
-
- [LineChart.md](./src/LineChart/LineChart.md)
|
|
16
|
-
- [GaugeChart.md](./src/GaugeChart/GaugeChart.md)
|
|
17
|
-
- [StatChart.md](./src/StatChart/StatChart.md)
|
|
18
|
-
- [BarChart.md](./src/BarChart/BarChart.md)
|
package/dist/EChart/EChart.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { CSSProperties } from 'react';
|
|
2
2
|
import { ECharts, EChartsCoreOption } from 'echarts/core';
|
|
3
3
|
import { SxProps, Theme } from '@mui/material';
|
|
4
4
|
import { EChartsTheme } from '../model';
|
|
@@ -52,11 +52,12 @@ export interface EChartsProps<T> {
|
|
|
52
52
|
theme?: string | EChartsTheme;
|
|
53
53
|
renderer?: 'canvas' | 'svg';
|
|
54
54
|
sx?: SxProps<Theme>;
|
|
55
|
+
style?: CSSProperties;
|
|
55
56
|
onEvents?: OnEventsType<T>;
|
|
56
57
|
_instance?: React.MutableRefObject<ECharts | undefined>;
|
|
57
58
|
syncGroup?: string;
|
|
58
59
|
onChartInitialized?: (instance: ECharts) => void;
|
|
59
60
|
}
|
|
60
|
-
export declare const EChart: import("react").MemoExoticComponent<(<T>({ option, theme, renderer, sx, onEvents, _instance, syncGroup, onChartInitialized, }: EChartsProps<T>) => import("react/jsx-runtime").JSX.Element)>;
|
|
61
|
+
export declare const EChart: import("react").MemoExoticComponent<(<T>({ option, theme, renderer, sx, style, onEvents, _instance, syncGroup, onChartInitialized, }: EChartsProps<T>) => import("react/jsx-runtime").JSX.Element)>;
|
|
61
62
|
export {};
|
|
62
63
|
//# sourceMappingURL=EChart.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../../src/EChart/EChart.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"EChart.d.ts","sourceRoot":"","sources":["../../src/EChart/EChart.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,aAAa,EAA4C,MAAM,OAAO,CAAC;AAChF,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAsB,MAAM,cAAc,CAAC;AAC9E,OAAO,EAAO,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AA0BpD,OAAO,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA0BxC,MAAM,WAAW,qBAAqB,CAAC,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC/B;AAED,KAAK,eAAe,CAAC,CAAC,IAAI,CACxB,MAAM,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAEhC,QAAQ,CAAC,EAAE,OAAO,KACf,IAAI,CAAC;AAEV,QAAA,MAAM,WAAW,0HAUP,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,WAAW,CAAC,CAAC,MAAM,CAAC,C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;IACpB,KAAK,CAAC,EAAE,aAAa,CAAC;IACtB,QAAQ,CAAC,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,OAAO,GAAG,SAAS,CAAC,CAAC;IACxD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAClD;AAED,eAAO,MAAM,MAAM,wIAUhB,aAAa,CAAC,CAAC,8CAsFhB,CAAC"}
|
package/dist/EChart/EChart.js
CHANGED
|
@@ -16,20 +16,30 @@ import { init, connect, use } from 'echarts/core';
|
|
|
16
16
|
import { Box } from '@mui/material';
|
|
17
17
|
import isEqual from 'lodash/isEqual';
|
|
18
18
|
import debounce from 'lodash/debounce';
|
|
19
|
-
import { ScatterChart as EChartsScatterChart } from 'echarts/charts';
|
|
20
|
-
import { DatasetComponent, DataZoomComponent, LegendComponent, GridComponent, TitleComponent, TooltipComponent } from 'echarts/components';
|
|
19
|
+
import { LineChart as EChartsLineChart, GaugeChart as EChartsGaugeChart, PieChart as EChartsPieChart, ScatterChart as EChartsScatterChart, CustomChart as EChartsCustomChart, HeatmapChart as EChartsHeatmapChart } from 'echarts/charts';
|
|
20
|
+
import { DatasetComponent, DataZoomComponent, LegendComponent, GridComponent, TitleComponent, TooltipComponent, VisualMapComponent, ToolboxComponent, MarkPointComponent, MarkAreaComponent, MarkLineComponent } from 'echarts/components';
|
|
21
21
|
import { CanvasRenderer } from 'echarts/renderers';
|
|
22
|
-
// Loading the ECharts extensions should happen in the respective
|
|
22
|
+
// Loading the ECharts extensions should happen in the respective plugins.
|
|
23
23
|
// This is a workaround for https://github.com/perses/plugins/issues/83.
|
|
24
24
|
use([
|
|
25
25
|
DatasetComponent,
|
|
26
26
|
DataZoomComponent,
|
|
27
27
|
LegendComponent,
|
|
28
|
+
EChartsLineChart,
|
|
29
|
+
EChartsGaugeChart,
|
|
30
|
+
EChartsPieChart,
|
|
28
31
|
EChartsScatterChart,
|
|
32
|
+
EChartsCustomChart,
|
|
33
|
+
EChartsHeatmapChart,
|
|
29
34
|
GridComponent,
|
|
30
35
|
TitleComponent,
|
|
36
|
+
ToolboxComponent,
|
|
31
37
|
TooltipComponent,
|
|
32
|
-
CanvasRenderer
|
|
38
|
+
CanvasRenderer,
|
|
39
|
+
VisualMapComponent,
|
|
40
|
+
MarkAreaComponent,
|
|
41
|
+
MarkLineComponent,
|
|
42
|
+
MarkPointComponent
|
|
33
43
|
]);
|
|
34
44
|
const mouseEvents = [
|
|
35
45
|
'click',
|
|
@@ -47,7 +57,7 @@ const batchEvents = [
|
|
|
47
57
|
'downplay',
|
|
48
58
|
'highlight'
|
|
49
59
|
];
|
|
50
|
-
export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, renderer, sx, onEvents, _instance, syncGroup, onChartInitialized }) {
|
|
60
|
+
export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, renderer, sx, style, onEvents, _instance, syncGroup, onChartInitialized }) {
|
|
51
61
|
const initialOption = useRef(option);
|
|
52
62
|
const prevOption = useRef(option);
|
|
53
63
|
const containerRef = useRef(null);
|
|
@@ -137,11 +147,13 @@ export const EChart = /*#__PURE__*/ memo(function EChart({ option, theme, render
|
|
|
137
147
|
});
|
|
138
148
|
updateSize();
|
|
139
149
|
}, [
|
|
140
|
-
sx
|
|
150
|
+
sx,
|
|
151
|
+
style
|
|
141
152
|
]);
|
|
142
153
|
return /*#__PURE__*/ _jsx(Box, {
|
|
143
154
|
ref: containerRef,
|
|
144
|
-
sx: sx
|
|
155
|
+
sx: sx,
|
|
156
|
+
style: style
|
|
145
157
|
});
|
|
146
158
|
});
|
|
147
159
|
// Validate event config and bind custom events
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/EChart/EChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { memo, useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init, connect, use } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport isEqual from 'lodash/isEqual';\nimport debounce from 'lodash/debounce';\n\nimport { ScatterChart as EChartsScatterChart } from 'echarts/charts';\nimport {\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChartsTheme } from '../model';\n\n// Loading the ECharts extensions should happen in the respective plugin (in this case, the scatterplot plugin).\n// This is a workaround for https://github.com/perses/plugins/issues/83.\nuse([\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n EChartsScatterChart,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n CanvasRenderer,\n]);\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n onEvents,\n _instance,\n syncGroup,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return (): void => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return (): void => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n // TODO: re-evaluate how this is triggered. It's technically working right\n // now because the sx prop is an object that gets re-created, but that also\n // means it runs unnecessarily some of the time and theoretically might\n // not run in some other cases. Maybe it should use a resize observer?\n useEffect(() => {\n // TODO: fix this debouncing. This likely isn't working as intended because\n // the debounced function is re-created every time this useEffect is called.\n const updateSize = debounce(\n () => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n },\n 200,\n {\n leading: true,\n }\n );\n updateSize();\n }, [sx]);\n\n return <Box ref={containerRef} sx={sx}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["memo","useEffect","useLayoutEffect","useRef","init","connect","use","Box","isEqual","debounce","ScatterChart","EChartsScatterChart","DatasetComponent","DataZoomComponent","LegendComponent","GridComponent","TitleComponent","TooltipComponent","CanvasRenderer","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","leading","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,IAAI,EAAEC,SAAS,EAAEC,eAAe,EAAEC,MAAM,QAAQ,QAAQ;AACjE,SAAqCC,IAAI,EAAEC,OAAO,EAAEC,GAAG,QAAQ,eAAe;AAC9E,SAASC,GAAG,QAAwB,gBAAgB;A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;YAC3BD,aAAaC,OAAO,CAACM,MAAM;QAC7B,GACA,KACA;YACES,SAAS;QACX;QAEFV;IACF,GAAG;QAACd;KAAG;IAEP,qBAAO,KAAClB;QAAI2C,KAAKlB;QAAcP,IAAIA;;AACrC,GAAG;AAEH,+CAA+C;AAC/C,SAASoB,WAAcM,QAAiB,EAAEC,MAAwB;IAChE,IAAIA,WAAWjB,WAAW;IAE1B,SAASkB,UAAUC,SAAoB,EAAEC,eAAwB;QAC/D,IAAI,OAAOA,oBAAoB,YAAY;YACzC,IAAIC,aAAaF,YAAY;gBAC3BH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG,QAAQP;YAC7D,OAAO,IAAIQ,aAAaL,YAAY;gBAClCH,SAASM,EAAE,CAACH,WAAW,CAACI,SAAWH,gBAAgBG;YACrD,OAAO;gBACLP,SAASM,EAAE,CAACH,WAAW,IAAMC,gBAAgB,MAAMJ;YACrD;QACF;IACF;IAEA,IAAK,MAAMG,aAAaF,OAAQ;QAC9B,IAAIQ,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,QAAQE,YAAY;YAC3D,MAAMU,cAAcZ,MAAM,CAACE,UAAuB,IAAI;YACtD,IAAIU,aAAa;gBACfX,UAAUC,WAAwBU;YACpC;QACF;IACF;AACF;AAEA,SAASR,aAAaF,SAAoB;IACxC,OAAO,AAACnC,YAAkC8C,QAAQ,CAACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAAClC,YAAkC6C,QAAQ,CAACX;AACrD"}
|
|
1
|
+
{"version":3,"sources":["../../src/EChart/EChart.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { CSSProperties, memo, useEffect, useLayoutEffect, useRef } from 'react';\nimport { ECharts, EChartsCoreOption, init, connect, use } from 'echarts/core';\nimport { Box, SxProps, Theme } from '@mui/material';\nimport isEqual from 'lodash/isEqual';\nimport debounce from 'lodash/debounce';\n\nimport {\n LineChart as EChartsLineChart,\n GaugeChart as EChartsGaugeChart,\n PieChart as EChartsPieChart,\n ScatterChart as EChartsScatterChart,\n CustomChart as EChartsCustomChart,\n HeatmapChart as EChartsHeatmapChart,\n} from 'echarts/charts';\nimport {\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n GridComponent,\n TitleComponent,\n TooltipComponent,\n VisualMapComponent,\n ToolboxComponent,\n MarkPointComponent,\n MarkAreaComponent,\n MarkLineComponent,\n} from 'echarts/components';\nimport { CanvasRenderer } from 'echarts/renderers';\nimport { EChartsTheme } from '../model';\n\n// Loading the ECharts extensions should happen in the respective plugins.\n// This is a workaround for https://github.com/perses/plugins/issues/83.\nuse([\n DatasetComponent,\n DataZoomComponent,\n LegendComponent,\n EChartsLineChart,\n EChartsGaugeChart,\n EChartsPieChart,\n EChartsScatterChart,\n EChartsCustomChart,\n EChartsHeatmapChart,\n GridComponent,\n TitleComponent,\n ToolboxComponent,\n TooltipComponent,\n CanvasRenderer,\n VisualMapComponent,\n MarkAreaComponent,\n MarkLineComponent,\n MarkPointComponent,\n]);\n\n// see docs for info about each property: https://echarts.apache.org/en/api.html#events\nexport interface MouseEventsParameters<T> {\n componentType: string;\n seriesType: string;\n seriesIndex: number;\n seriesName: string;\n name: string;\n dataIndex: number;\n data: Record<string, unknown> & T;\n dataType: string;\n value: number | number[];\n color: string;\n info: Record<string, unknown>;\n}\n\ntype OnEventFunction<T> = (\n params: MouseEventsParameters<T>,\n // This is potentially undefined for testing purposes\n instance?: ECharts\n) => void;\n\nconst mouseEvents = [\n 'click',\n 'dblclick',\n 'mousedown',\n 'mousemove',\n 'mouseup',\n 'mouseover',\n 'mouseout',\n 'globalout',\n 'contextmenu',\n] as const;\n\nexport type MouseEventName = (typeof mouseEvents)[number];\n\n// batch event types\nexport interface DataZoomPayloadBatchItem {\n dataZoomId: string;\n // start and end not returned unless dataZoom is based on percentProp,\n // which is for cases when a dataZoom component controls multiple axes\n start?: number;\n end?: number;\n // startValue and endValue return data index for 'category' axes,\n // for axis types 'value' and 'time', actual values are returned\n startValue?: number;\n endValue?: number;\n}\n\nexport interface HighlightPayloadBatchItem {\n dataIndex: number;\n dataIndexInside: number;\n seriesIndex: number;\n // highlight action can effect multiple connected charts\n escapeConnect?: boolean;\n // whether blur state was triggered\n notBlur?: boolean;\n}\n\nexport interface BatchEventsParameters {\n type: BatchEventName;\n batch: DataZoomPayloadBatchItem[] & HighlightPayloadBatchItem[];\n}\n\ntype OnBatchEventFunction = (params: BatchEventsParameters) => void;\n\nconst batchEvents = ['datazoom', 'downplay', 'highlight'] as const;\n\nexport type BatchEventName = (typeof batchEvents)[number];\n\ntype ChartEventName = 'finished';\n\ntype EventName = MouseEventName | ChartEventName | BatchEventName;\n\nexport type OnEventsType<T> = {\n [mouseEventName in MouseEventName]?: OnEventFunction<T>;\n} & {\n [batchEventName in BatchEventName]?: OnBatchEventFunction;\n} & {\n [eventName in ChartEventName]?: () => void;\n};\n\nexport interface EChartsProps<T> {\n option: EChartsCoreOption;\n theme?: string | EChartsTheme;\n renderer?: 'canvas' | 'svg';\n sx?: SxProps<Theme>;\n style?: CSSProperties;\n onEvents?: OnEventsType<T>;\n _instance?: React.MutableRefObject<ECharts | undefined>;\n syncGroup?: string;\n onChartInitialized?: (instance: ECharts) => void;\n}\n\nexport const EChart = memo(function EChart<T>({\n option,\n theme,\n renderer,\n sx,\n style,\n onEvents,\n _instance,\n syncGroup,\n onChartInitialized,\n}: EChartsProps<T>) {\n const initialOption = useRef<EChartsCoreOption>(option);\n const prevOption = useRef<EChartsCoreOption>(option);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const chartElement = useRef<ECharts | null>(null);\n\n // Initialize chart, dispose on unmount\n useLayoutEffect(() => {\n if (containerRef.current === null || chartElement.current !== null) return;\n chartElement.current = init(containerRef.current, theme, { renderer: renderer ?? 'canvas' });\n if (chartElement.current === undefined) return;\n chartElement.current.setOption(initialOption.current, true);\n onChartInitialized?.(chartElement.current);\n if (_instance !== undefined) {\n _instance.current = chartElement.current;\n }\n return (): void => {\n if (chartElement.current === null) return;\n chartElement.current.dispose();\n chartElement.current = null;\n };\n }, [_instance, onChartInitialized, theme, renderer]);\n\n // When syncGroup is explicitly set, charts within same group share interactions such as crosshair\n useEffect(() => {\n if (!chartElement.current || !syncGroup) return;\n chartElement.current.group = syncGroup;\n connect([chartElement.current]); // more info: https://echarts.apache.org/en/api.html#echarts.connect\n }, [syncGroup, chartElement]);\n\n // Update chart data when option changes\n useEffect(() => {\n if (prevOption.current === undefined || isEqual(prevOption.current, option)) return;\n if (!chartElement.current) return;\n chartElement.current.setOption(option, true);\n prevOption.current = option;\n }, [option]);\n\n // Resize chart, cleanup listener on unmount\n useLayoutEffect(() => {\n const updateSize = debounce(() => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n }, 200);\n window.addEventListener('resize', updateSize);\n updateSize();\n return (): void => {\n window.removeEventListener('resize', updateSize);\n };\n }, []);\n\n // Bind and unbind chart events passed as prop\n useEffect(() => {\n const chart = chartElement.current;\n if (!chart || onEvents === undefined) return;\n bindEvents(chart, onEvents);\n return (): void => {\n if (chart === undefined) return;\n if (chart.isDisposed() === true) return;\n for (const event in onEvents) {\n chart.off(event);\n }\n };\n }, [onEvents]);\n\n // TODO: re-evaluate how this is triggered. It's technically working right\n // now because the sx prop is an object that gets re-created, but that also\n // means it runs unnecessarily some of the time and theoretically might\n // not run in some other cases. Maybe it should use a resize observer?\n useEffect(() => {\n // TODO: fix this debouncing. This likely isn't working as intended because\n // the debounced function is re-created every time this useEffect is called.\n const updateSize = debounce(\n () => {\n if (!chartElement.current) return;\n chartElement.current.resize();\n },\n 200,\n {\n leading: true,\n }\n );\n updateSize();\n }, [sx, style]);\n\n return <Box ref={containerRef} sx={sx} style={style}></Box>;\n});\n\n// Validate event config and bind custom events\nfunction bindEvents<T>(instance: ECharts, events?: OnEventsType<T>): void {\n if (events === undefined) return;\n\n function bindEvent(eventName: EventName, OnEventFunction: unknown): void {\n if (typeof OnEventFunction === 'function') {\n if (isMouseEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params, instance));\n } else if (isBatchEvent(eventName)) {\n instance.on(eventName, (params) => OnEventFunction(params));\n } else {\n instance.on(eventName, () => OnEventFunction(null, instance));\n }\n }\n }\n\n for (const eventName in events) {\n if (Object.prototype.hasOwnProperty.call(events, eventName)) {\n const customEvent = events[eventName as EventName] ?? null;\n if (customEvent) {\n bindEvent(eventName as EventName, customEvent);\n }\n }\n }\n}\n\nfunction isMouseEvent(eventName: EventName): eventName is MouseEventName {\n return (mouseEvents as readonly string[]).includes(eventName);\n}\n\nfunction isBatchEvent(eventName: EventName): eventName is BatchEventName {\n return (batchEvents as readonly string[]).includes(eventName);\n}\n"],"names":["memo","useEffect","useLayoutEffect","useRef","init","connect","use","Box","isEqual","debounce","LineChart","EChartsLineChart","GaugeChart","EChartsGaugeChart","PieChart","EChartsPieChart","ScatterChart","EChartsScatterChart","CustomChart","EChartsCustomChart","HeatmapChart","EChartsHeatmapChart","DatasetComponent","DataZoomComponent","LegendComponent","GridComponent","TitleComponent","TooltipComponent","VisualMapComponent","ToolboxComponent","MarkPointComponent","MarkAreaComponent","MarkLineComponent","CanvasRenderer","mouseEvents","batchEvents","EChart","option","theme","renderer","sx","style","onEvents","_instance","syncGroup","onChartInitialized","initialOption","prevOption","containerRef","chartElement","current","undefined","setOption","dispose","group","updateSize","resize","window","addEventListener","removeEventListener","chart","bindEvents","isDisposed","event","off","leading","ref","instance","events","bindEvent","eventName","OnEventFunction","isMouseEvent","on","params","isBatchEvent","Object","prototype","hasOwnProperty","call","customEvent","includes"],"mappings":"A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AK,MAAMG,aAAaF,OAAQ;QAC9B,IAAIQ,OAAOC,SAAS,CAACC,cAAc,CAACC,IAAI,CAACX,QAAQE,YAAY;YAC3D,MAAMU,cAAcZ,MAAM,CAACE,UAAuB,IAAI;YACtD,IAAIU,aAAa;gBACfX,UAAUC,WAAwBU;YACpC;QACF;IACF;AACF;AAEA,SAASR,aAAaF,SAAoB;IACxC,OAAO,AAACpC,YAAkC+C,QAAQ,CAACX;AACrD;AAEA,SAASK,aAAaL,SAAoB;IACxC,OAAO,AAACnC,YAAkC8C,QAAQ,CAACX;AACrD"}
|
package/dist/JSONEditor.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JSONEditor.d.ts","sourceRoot":"","sources":["../src/JSONEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"JSONEditor.d.ts","sourceRoot":"","sources":["../src/JSONEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,YAAY,EAAY,MAAM,OAAO,CAAC;AAK/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAEjE,KAAK,eAAe,CAAC,CAAC,IAAI,IAAI,CAAC,oBAAoB,EAAE,QAAQ,GAAG,OAAO,GAAG,YAAY,GAAG,UAAU,GAAG,OAAO,CAAC,GAAG;IAC/G,KAAK,EAAE,CAAC,CAAC;IACT,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC,CAAC;AAEF,wBAAgB,UAAU,CAAC,CAAC,EAAE,KAAK,EAAE,eAAe,CAAC,CAAC,CAAC,GAAG,YAAY,CAiCrE"}
|
package/dist/JSONEditor.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import {
|
|
14
|
+
import { useState } from 'react';
|
|
15
15
|
import CodeMirror from '@uiw/react-codemirror';
|
|
16
16
|
import { json, jsonParseLinter } from '@codemirror/lang-json';
|
|
17
17
|
import { linter, lintGutter } from '@codemirror/lint';
|
|
@@ -21,11 +21,6 @@ export function JSONEditor(props) {
|
|
|
21
21
|
const isDarkMode = theme.palette.mode === 'dark';
|
|
22
22
|
const [value, setValue] = useState(()=>JSON.stringify(props.value, null, 2));
|
|
23
23
|
const [lastProcessedValue, setLastProcessedValue] = useState(value);
|
|
24
|
-
useEffect(()=>{
|
|
25
|
-
setValue(JSON.stringify(props.value, null, 2));
|
|
26
|
-
}, [
|
|
27
|
-
props.value
|
|
28
|
-
]);
|
|
29
24
|
return /*#__PURE__*/ _jsx(CodeMirror, {
|
|
30
25
|
...props,
|
|
31
26
|
style: {
|
|
@@ -40,6 +35,10 @@ export function JSONEditor(props) {
|
|
|
40
35
|
value: value,
|
|
41
36
|
onChange: (newValue)=>{
|
|
42
37
|
setValue(newValue);
|
|
38
|
+
// Trigger the provided onChange callback in real-time
|
|
39
|
+
if (props.onChange) {
|
|
40
|
+
props.onChange(newValue);
|
|
41
|
+
}
|
|
43
42
|
},
|
|
44
43
|
onBlur: ()=>{
|
|
45
44
|
// Don't trigger the provided onChange if the last processed value is equal to the current value.
|
package/dist/JSONEditor.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/JSONEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement,
|
|
1
|
+
{"version":3,"sources":["../src/JSONEditor.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ReactElement, useState } from 'react';\nimport CodeMirror from '@uiw/react-codemirror';\nimport { json, jsonParseLinter } from '@codemirror/lang-json';\nimport { linter, lintGutter } from '@codemirror/lint';\nimport { useTheme } from '@mui/material';\nimport { ReactCodeMirrorProps } from '@uiw/react-codemirror/src';\n\ntype JSONEditorProps<T> = Omit<ReactCodeMirrorProps, 'onBlur' | 'theme' | 'extensions' | 'onChange' | 'value'> & {\n value: T;\n placeholder?: string;\n onChange?: (next: string) => void;\n};\n\nexport function JSONEditor<T>(props: JSONEditorProps<T>): ReactElement {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const [value, setValue] = useState(() => JSON.stringify(props.value, null, 2));\n const [lastProcessedValue, setLastProcessedValue] = useState<string>(value);\n\n return (\n <CodeMirror\n {...props}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n extensions={[json(), linter(jsonParseLinter()), lintGutter()]}\n value={value}\n onChange={(newValue) => {\n setValue(newValue);\n // Trigger the provided onChange callback in real-time\n if (props.onChange) {\n props.onChange(newValue);\n }\n }}\n onBlur={() => {\n // Don't trigger the provided onChange if the last processed value is equal to the current value.\n // This prevents e.g CTRL+F to trigger value refresh downstream, which would cause the embedded\n // find & replace interface to close immediately.\n if (lastProcessedValue !== value && props.onChange !== undefined) {\n props.onChange(value);\n setLastProcessedValue(value);\n }\n }}\n placeholder={props.placeholder}\n />\n );\n}\n"],"names":["useState","CodeMirror","json","jsonParseLinter","linter","lintGutter","useTheme","JSONEditor","props","theme","isDarkMode","palette","mode","value","setValue","JSON","stringify","lastProcessedValue","setLastProcessedValue","style","border","divider","extensions","onChange","newValue","onBlur","undefined","placeholder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAuBA,QAAQ,QAAQ,QAAQ;AAC/C,OAAOC,gBAAgB,wBAAwB;AAC/C,SAASC,IAAI,EAAEC,eAAe,QAAQ,wBAAwB;AAC9D,SAASC,MAAM,EAAEC,UAAU,QAAQ,mBAAmB;AACtD,SAASC,QAAQ,QAAQ,gBAAgB;AASzC,OAAO,SAASC,WAAcC,KAAyB;IACrD,MAAMC,QAAQH;IACd,MAAMI,aAAaD,MAAME,OAAO,CAACC,IAAI,KAAK;IAE1C,MAAM,CAACC,OAAOC,SAAS,GAAGd,SAAS,IAAMe,KAAKC,SAAS,CAACR,MAAMK,KAAK,EAAE,MAAM;IAC3E,MAAM,CAACI,oBAAoBC,sBAAsB,GAAGlB,SAAiBa;IAErE,qBACE,KAACZ;QACE,GAAGO,KAAK;QACTW,OAAO;YAAEC,QAAQ,CAAC,UAAU,EAAEX,MAAME,OAAO,CAACU,OAAO,EAAE;QAAC;QACtDZ,OAAOC,aAAa,SAAS;QAC7BY,YAAY;YAACpB;YAAQE,OAAOD;YAAoBE;SAAa;QAC7DQ,OAAOA;QACPU,UAAU,CAACC;YACTV,SAASU;YACT,sDAAsD;YACtD,IAAIhB,MAAMe,QAAQ,EAAE;gBAClBf,MAAMe,QAAQ,CAACC;YACjB;QACF;QACAC,QAAQ;YACN,iGAAiG;YACjG,+FAA+F;YAC/F,iDAAiD;YACjD,IAAIR,uBAAuBJ,SAASL,MAAMe,QAAQ,KAAKG,WAAW;gBAChElB,MAAMe,QAAQ,CAACV;gBACfK,sBAAsBL;YACxB;QACF;QACAc,aAAanB,MAAMmB,WAAW;;AAGpC"}
|
package/dist/Table/Table.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ import { TableProps } from './model/table-model';
|
|
|
6
6
|
*
|
|
7
7
|
* **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
|
|
8
8
|
*/
|
|
9
|
-
export declare function Table<TableData>({ data, columns, cellConfigs, density, defaultColumnWidth, defaultColumnHeight, checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId, rowSelection, sorting, rowSelectionVariant, ...otherProps }: TableProps<TableData>): ReactElement;
|
|
9
|
+
export declare function Table<TableData>({ data, columns, cellConfigs, density, defaultColumnWidth, defaultColumnHeight, checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId, rowSelection, sorting, pagination, onPaginationChange, rowSelectionVariant, ...otherProps }: TableProps<TableData>): ReactElement;
|
|
10
10
|
//# sourceMappingURL=Table.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Table.d.ts","sourceRoot":"","sources":["../../src/Table/Table.tsx"],"names":[],"mappings":"AA0BA,OAAO,EAAE,YAAY,EAAwB,MAAM,OAAO,CAAC;AAG3D,OAAO,EAAE,UAAU,EAAwD,MAAM,qBAAqB,CAAC;AAYvG;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,SAAS,EAAE,EAC/B,IAAI,EACJ,OAAO,EACP,WAAW,EACX,OAAoB,EACpB,kBAAyC,EACzC,mBAA4B,EAC5B,iBAAiB,EACjB,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,QAA6B,EAC7B,YAAoC,EACpC,OAAyB,EACzB,UAAU,EACV,kBAAkB,EAClB,mBAAgC,EAChC,GAAG,UAAU,EACd,EAAE,UAAU,CAAC,SAAS,CAAC,GAAG,YAAY,CA0ItC"}
|
package/dist/Table/Table.js
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
-
import { useReactTable, getCoreRowModel, getSortedRowModel } from '@tanstack/react-table';
|
|
14
|
+
import { useReactTable, getCoreRowModel, getSortedRowModel, getPaginationRowModel } from '@tanstack/react-table';
|
|
15
15
|
import { useTheme } from '@mui/material';
|
|
16
16
|
import { useCallback, useMemo } from 'react';
|
|
17
17
|
import { VirtualizedTable } from './VirtualizedTable';
|
|
@@ -30,7 +30,7 @@ const DEFAULT_SORTING = [];
|
|
|
30
30
|
* **not** intended to be a general use data table for use cases unrelated to Perses.
|
|
31
31
|
*
|
|
32
32
|
* **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**
|
|
33
|
-
*/ export function Table({ data, columns, cellConfigs, density = 'standard', defaultColumnWidth = DEFAULT_COLUMN_WIDTH, defaultColumnHeight = 'auto', checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId = DEFAULT_GET_ROW_ID, rowSelection = DEFAULT_ROW_SELECTION, sorting = DEFAULT_SORTING, rowSelectionVariant = 'standard', ...otherProps }) {
|
|
33
|
+
*/ export function Table({ data, columns, cellConfigs, density = 'standard', defaultColumnWidth = DEFAULT_COLUMN_WIDTH, defaultColumnHeight = 'auto', checkboxSelection, onRowSelectionChange, onSortingChange, getCheckboxColor, getRowId = DEFAULT_GET_ROW_ID, rowSelection = DEFAULT_ROW_SELECTION, sorting = DEFAULT_SORTING, pagination, onPaginationChange, rowSelectionVariant = 'standard', ...otherProps }) {
|
|
34
34
|
const theme = useTheme();
|
|
35
35
|
const handleRowSelectionChange = (rowSelectionUpdater)=>{
|
|
36
36
|
const newRowSelection = typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;
|
|
@@ -117,6 +117,10 @@ const DEFAULT_SORTING = [];
|
|
|
117
117
|
getRowId,
|
|
118
118
|
getCoreRowModel: getCoreRowModel(),
|
|
119
119
|
getSortedRowModel: getSortedRowModel(),
|
|
120
|
+
getPaginationRowModel: pagination ? getPaginationRowModel() : undefined,
|
|
121
|
+
// without this setting, the getPaginationRowModel setting persists and it is not possible to switch from paginated to unpaginated
|
|
122
|
+
// can be removed once https://github.com/TanStack/table/pull/5974 is merged
|
|
123
|
+
manualPagination: !pagination,
|
|
120
124
|
enableRowSelection: !!checkboxSelection,
|
|
121
125
|
onRowSelectionChange: handleRowSelectionChange,
|
|
122
126
|
onSortingChange: handleSortingChange,
|
|
@@ -125,7 +129,10 @@ const DEFAULT_SORTING = [];
|
|
|
125
129
|
sortDescFirst: true,
|
|
126
130
|
state: {
|
|
127
131
|
rowSelection,
|
|
128
|
-
sorting
|
|
132
|
+
sorting,
|
|
133
|
+
...pagination ? {
|
|
134
|
+
pagination
|
|
135
|
+
} : {}
|
|
129
136
|
}
|
|
130
137
|
});
|
|
131
138
|
const handleRowClick = useCallback((e, rowId)=>{
|
|
@@ -145,7 +152,10 @@ const DEFAULT_SORTING = [];
|
|
|
145
152
|
rows: table.getRowModel().rows,
|
|
146
153
|
columns: table.getAllFlatColumns(),
|
|
147
154
|
headers: table.getHeaderGroups(),
|
|
148
|
-
cellConfigs: cellConfigs
|
|
155
|
+
cellConfigs: cellConfigs,
|
|
156
|
+
pagination: pagination,
|
|
157
|
+
onPaginationChange: onPaginationChange,
|
|
158
|
+
rowCount: table.getRowCount()
|
|
149
159
|
});
|
|
150
160
|
}
|
|
151
161
|
|
package/dist/Table/Table.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/Table.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useReactTable,\n getCoreRowModel,\n ColumnDef,\n RowSelectionState,\n OnChangeFn,\n Row,\n Table as TanstackTable,\n SortingState,\n getSortedRowModel,\n} from '@tanstack/react-table';\nimport { useTheme } from '@mui/material';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport { VirtualizedTable } from './VirtualizedTable';\nimport { TableCheckbox } from './TableCheckbox';\nimport { TableProps, persesColumnsToTanstackColumns, DEFAULT_COLUMN_WIDTH } from './model/table-model';\n\nconst DEFAULT_GET_ROW_ID = (data: unknown, index: number): string => {\n return `${index}`;\n};\n\n// Setting these defaults one enables them to be consistent across renders instead\n// of being recreated every time, which can be important for perf because react\n// does not do deep equality checking for objects and arrays.\nconst DEFAULT_ROW_SELECTION: NonNullable<TableProps<unknown>['rowSelection']> = {};\nconst DEFAULT_SORTING: NonNullable<TableProps<unknown>['sorting']> = [];\n\n/**\n * Component used to render tabular data in Perses use cases. This component is\n * **not** intended to be a general use data table for use cases unrelated to Perses.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function Table<TableData>({\n data,\n columns,\n cellConfigs,\n density = 'standard',\n defaultColumnWidth = DEFAULT_COLUMN_WIDTH,\n defaultColumnHeight = 'auto',\n checkboxSelection,\n onRowSelectionChange,\n onSortingChange,\n getCheckboxColor,\n getRowId = DEFAULT_GET_ROW_ID,\n rowSelection = DEFAULT_ROW_SELECTION,\n sorting = DEFAULT_SORTING,\n rowSelectionVariant = 'standard',\n ...otherProps\n}: TableProps<TableData>): ReactElement {\n const theme = useTheme();\n\n const handleRowSelectionChange: OnChangeFn<RowSelectionState> = (rowSelectionUpdater) => {\n const newRowSelection =\n typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;\n onRowSelectionChange?.(newRowSelection);\n };\n\n const handleRowSelectionEvent = useCallback(\n (table: TanstackTable<TableData>, row: Row<TableData>, isModified: boolean) => {\n if (rowSelectionVariant === 'standard' || isModified) {\n row.toggleSelected();\n } else {\n // Legend variant (when action not modified with shift/meta key).\n // Note that this behavior needs to be kept in sync with behavior in\n // the Legend component for list-based legends.\n if (row.getIsSelected() && !table.getIsAllRowsSelected()) {\n // Row was already selected. Revert to select all.\n table.toggleAllRowsSelected();\n } else {\n // Focus the selected row.\n onRowSelectionChange?.({\n [row.id]: true,\n });\n }\n }\n },\n [onRowSelectionChange, rowSelectionVariant]\n );\n\n const handleCheckboxChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, table: TanstackTable<TableData>, row: Row<TableData>) => {\n const nativePointerEvent =\n e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent)\n ? (e.nativeEvent as PointerEvent)\n : undefined;\n const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;\n handleRowSelectionEvent(table, row, isModifed);\n },\n [handleRowSelectionEvent]\n );\n\n const handleSortingChange: OnChangeFn<SortingState> = (sortingUpdater) => {\n const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;\n onSortingChange?.(newSorting);\n };\n\n const checkboxColumn: ColumnDef<TableData> = useMemo(() => {\n return {\n id: 'checkboxRowSelect',\n size: 28,\n header: ({ table }): ReactElement => {\n return (\n <TableCheckbox\n checked={table.getIsAllRowsSelected()}\n indeterminate={table.getIsSomeRowsSelected()}\n onChange={table.getToggleAllRowsSelectedHandler()}\n color={theme.palette.text.primary}\n density={density}\n />\n );\n },\n cell: ({ row, table }): ReactElement => {\n return (\n <TableCheckbox\n checked={row.getIsSelected()}\n indeterminate={row.getIsSomeSelected()}\n onChange={(e) => {\n handleCheckboxChange(e, table, row);\n }}\n color={getCheckboxColor?.(row.original)}\n density={density}\n />\n );\n },\n enableSorting: false,\n };\n }, [theme.palette.text.primary, density, getCheckboxColor, handleCheckboxChange]);\n\n const tableColumns: Array<ColumnDef<TableData>> = useMemo(() => {\n const initTableColumns = persesColumnsToTanstackColumns(columns);\n\n if (checkboxSelection) {\n initTableColumns.unshift(checkboxColumn);\n }\n\n return initTableColumns;\n }, [checkboxColumn, checkboxSelection, columns]);\n\n const table = useReactTable({\n data,\n columns: tableColumns,\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n enableRowSelection: !!checkboxSelection,\n onRowSelectionChange: handleRowSelectionChange,\n onSortingChange: handleSortingChange,\n // For now, defaulting to sort by descending first. We can expose the ability\n // to customize it if/when we have use cases for it.\n sortDescFirst: true,\n state: {\n rowSelection,\n sorting,\n },\n });\n\n const handleRowClick = useCallback(\n (e: React.MouseEvent<HTMLDivElement, MouseEvent>, rowId: string) => {\n const row = table.getRow(rowId);\n const isModifiedClick = e.metaKey || e.shiftKey;\n handleRowSelectionEvent(table, row, isModifiedClick);\n },\n [handleRowSelectionEvent, table]\n );\n\n return (\n <VirtualizedTable\n {...otherProps}\n density={density}\n defaultColumnWidth={defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n onRowClick={handleRowClick}\n rows={table.getRowModel().rows}\n columns={table.getAllFlatColumns()}\n headers={table.getHeaderGroups()}\n cellConfigs={cellConfigs}\n />\n );\n}\n"],"names":["useReactTable","getCoreRowModel","getSortedRowModel","useTheme","useCallback","useMemo","VirtualizedTable","TableCheckbox","persesColumnsToTanstackColumns","DEFAULT_COLUMN_WIDTH","DEFAULT_GET_ROW_ID","data","index","DEFAULT_ROW_SELECTION","DEFAULT_SORTING","Table","columns","cellConfigs","density","defaultColumnWidth","defaultColumnHeight","checkboxSelection","onRowSelectionChange","onSortingChange","getCheckboxColor","getRowId","rowSelection","sorting","rowSelectionVariant","otherProps","theme","handleRowSelectionChange","rowSelectionUpdater","newRowSelection","handleRowSelectionEvent","table","row","isModified","toggleSelected","getIsSelected","getIsAllRowsSelected","toggleAllRowsSelected","id","handleCheckboxChange","e","nativePointerEvent","nativeEvent","MouseEvent","KeyboardEvent","undefined","isModifed","metaKey","shiftKey","handleSortingChange","sortingUpdater","newSorting","checkboxColumn","size","header","checked","indeterminate","getIsSomeRowsSelected","onChange","getToggleAllRowsSelectedHandler","color","palette","text","primary","cell","getIsSomeSelected","original","enableSorting","tableColumns","initTableColumns","unshift","enableRowSelection","sortDescFirst","state","handleRowClick","rowId","getRow","isModifiedClick","onRowClick","rows","getRowModel","getAllFlatColumns","headers","getHeaderGroups"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SACEA,aAAa,EACbC,eAAe,EAOfC,iBAAiB,QACZ,wBAAwB;AAC/B,SAASC,QAAQ,QAAQ,gBAAgB;AACzC,SAAuBC,WAAW,EAAEC,OAAO,QAAQ,QAAQ;AAC3D,SAASC,gBAAgB,QAAQ,qBAAqB;AACtD,SAASC,aAAa,QAAQ,kBAAkB;AAChD,SAAqBC,8BAA8B,EAAEC,oBAAoB,QAAQ,sBAAsB;AAEvG,MAAMC,qBAAqB,CAACC,MAAeC;IACzC,OAAO,GAAGA,OAAO;AACnB;AAEA,kFAAkF;AAClF,+EAA+E;AAC/E,6DAA6D;AAC7D,MAAMC,wBAA0E,CAAC;AACjF,MAAMC,kBAA+D,EAAE;AAEvE;;;;;CAKC,GACD,OAAO,SAASC,MAAiB,EAC/BJ,IAAI,EACJK,OAAO,EACPC,WAAW,EACXC,UAAU,UAAU,EACpBC,qBAAqBV,oBAAoB,EACzCW,sBAAsB,MAAM,EAC5BC,iBAAiB,EACjBC,oBAAoB,EACpBC,eAAe,EACfC,gBAAgB,EAChBC,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BAAqBA;QACrB8D,YAAYJ;QACZK,MAAMhD,MAAMiD,WAAW,GAAGD,IAAI;QAC9BnE,SAASmB,MAAMkD,iBAAiB;QAChCC,SAASnD,MAAMoD,eAAe;QAC9BtE,aAAaA;;AAGnB"}
|
|
1
|
+
{"version":3,"sources":["../../src/Table/Table.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n useReactTable,\n getCoreRowModel,\n ColumnDef,\n RowSelectionState,\n OnChangeFn,\n Row,\n Table as TanstackTable,\n SortingState,\n getSortedRowModel,\n getPaginationRowModel,\n} from '@tanstack/react-table';\nimport { useTheme } from '@mui/material';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport { VirtualizedTable } from './VirtualizedTable';\nimport { TableCheckbox } from './TableCheckbox';\nimport { TableProps, persesColumnsToTanstackColumns, DEFAULT_COLUMN_WIDTH } from './model/table-model';\n\nconst DEFAULT_GET_ROW_ID = (data: unknown, index: number): string => {\n return `${index}`;\n};\n\n// Setting these defaults one enables them to be consistent across renders instead\n// of being recreated every time, which can be important for perf because react\n// does not do deep equality checking for objects and arrays.\nconst DEFAULT_ROW_SELECTION: NonNullable<TableProps<unknown>['rowSelection']> = {};\nconst DEFAULT_SORTING: NonNullable<TableProps<unknown>['sorting']> = [];\n\n/**\n * Component used to render tabular data in Perses use cases. This component is\n * **not** intended to be a general use data table for use cases unrelated to Perses.\n *\n * **Note: This component is currently experimental and is likely to have significant breaking changes in the near future. Use with caution outside of the core Perses codebase.**\n */\nexport function Table<TableData>({\n data,\n columns,\n cellConfigs,\n density = 'standard',\n defaultColumnWidth = DEFAULT_COLUMN_WIDTH,\n defaultColumnHeight = 'auto',\n checkboxSelection,\n onRowSelectionChange,\n onSortingChange,\n getCheckboxColor,\n getRowId = DEFAULT_GET_ROW_ID,\n rowSelection = DEFAULT_ROW_SELECTION,\n sorting = DEFAULT_SORTING,\n pagination,\n onPaginationChange,\n rowSelectionVariant = 'standard',\n ...otherProps\n}: TableProps<TableData>): ReactElement {\n const theme = useTheme();\n\n const handleRowSelectionChange: OnChangeFn<RowSelectionState> = (rowSelectionUpdater) => {\n const newRowSelection =\n typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;\n onRowSelectionChange?.(newRowSelection);\n };\n\n const handleRowSelectionEvent = useCallback(\n (table: TanstackTable<TableData>, row: Row<TableData>, isModified: boolean) => {\n if (rowSelectionVariant === 'standard' || isModified) {\n row.toggleSelected();\n } else {\n // Legend variant (when action not modified with shift/meta key).\n // Note that this behavior needs to be kept in sync with behavior in\n // the Legend component for list-based legends.\n if (row.getIsSelected() && !table.getIsAllRowsSelected()) {\n // Row was already selected. Revert to select all.\n table.toggleAllRowsSelected();\n } else {\n // Focus the selected row.\n onRowSelectionChange?.({\n [row.id]: true,\n });\n }\n }\n },\n [onRowSelectionChange, rowSelectionVariant]\n );\n\n const handleCheckboxChange = useCallback(\n (e: React.ChangeEvent<HTMLInputElement>, table: TanstackTable<TableData>, row: Row<TableData>) => {\n const nativePointerEvent =\n e.nativeEvent && (e.nativeEvent instanceof MouseEvent || e.nativeEvent instanceof KeyboardEvent)\n ? (e.nativeEvent as PointerEvent)\n : undefined;\n const isModifed = !!nativePointerEvent?.metaKey || !!nativePointerEvent?.shiftKey;\n handleRowSelectionEvent(table, row, isModifed);\n },\n [handleRowSelectionEvent]\n );\n\n const handleSortingChange: OnChangeFn<SortingState> = (sortingUpdater) => {\n const newSorting = typeof sortingUpdater === 'function' ? sortingUpdater(sorting) : sortingUpdater;\n onSortingChange?.(newSorting);\n };\n\n const checkboxColumn: ColumnDef<TableData> = useMemo(() => {\n return {\n id: 'checkboxRowSelect',\n size: 28,\n header: ({ table }): ReactElement => {\n return (\n <TableCheckbox\n checked={table.getIsAllRowsSelected()}\n indeterminate={table.getIsSomeRowsSelected()}\n onChange={table.getToggleAllRowsSelectedHandler()}\n color={theme.palette.text.primary}\n density={density}\n />\n );\n },\n cell: ({ row, table }): ReactElement => {\n return (\n <TableCheckbox\n checked={row.getIsSelected()}\n indeterminate={row.getIsSomeSelected()}\n onChange={(e) => {\n handleCheckboxChange(e, table, row);\n }}\n color={getCheckboxColor?.(row.original)}\n density={density}\n />\n );\n },\n enableSorting: false,\n };\n }, [theme.palette.text.primary, density, getCheckboxColor, handleCheckboxChange]);\n\n const tableColumns: Array<ColumnDef<TableData>> = useMemo(() => {\n const initTableColumns = persesColumnsToTanstackColumns(columns);\n\n if (checkboxSelection) {\n initTableColumns.unshift(checkboxColumn);\n }\n\n return initTableColumns;\n }, [checkboxColumn, checkboxSelection, columns]);\n\n const table = useReactTable({\n data,\n columns: tableColumns,\n getRowId,\n getCoreRowModel: getCoreRowModel(),\n getSortedRowModel: getSortedRowModel(),\n getPaginationRowModel: pagination ? getPaginationRowModel() : undefined,\n // without this setting, the getPaginationRowModel setting persists and it is not possible to switch from paginated to unpaginated\n // can be removed once https://github.com/TanStack/table/pull/5974 is merged\n manualPagination: !pagination,\n enableRowSelection: !!checkboxSelection,\n onRowSelectionChange: handleRowSelectionChange,\n onSortingChange: handleSortingChange,\n // For now, defaulting to sort by descending first. We can expose the ability\n // to customize it if/when we have use cases for it.\n sortDescFirst: true,\n state: {\n rowSelection,\n sorting,\n ...(pagination ? { pagination } : {}),\n },\n });\n\n const handleRowClick = useCallback(\n (e: React.MouseEvent<HTMLDivElement, MouseEvent>, rowId: string) => {\n const row = table.getRow(rowId);\n const isModifiedClick = e.metaKey || e.shiftKey;\n handleRowSelectionEvent(table, row, isModifiedClick);\n },\n [handleRowSelectionEvent, table]\n );\n\n return (\n <VirtualizedTable\n {...otherProps}\n density={density}\n defaultColumnWidth={defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n onRowClick={handleRowClick}\n rows={table.getRowModel().rows}\n columns={table.getAllFlatColumns()}\n headers={table.getHeaderGroups()}\n cellConfigs={cellConfigs}\n pagination={pagination}\n onPaginationChange={onPaginationChange}\n rowCount={table.getRowCount()}\n />\n );\n}\n"],"names":["useReactTable","getCoreRowModel","getSortedRowModel","getPaginationRowModel","useTheme","useCallback","useMemo","VirtualizedTable","TableCheckbox","persesColumnsToTanstackColumns","DEFAULT_COLUMN_WIDTH","DEFAULT_GET_ROW_ID","data","index","DEFAULT_ROW_SELECTION","DEFAULT_SORTING","Table","columns","cellConfigs","density","defaultColumnWidth","defaultColumnHeight","checkboxSelection","onRowSelectionChange","onSortingChange","getCheckboxColor","getRowId","rowSelection","sorting","pagination","onPaginationChange","rowSelectionVariant","otherProps","theme","handleRowSelectionChange","rowSelectionUpdater","newRowSelection","handleRowSelectionEvent","table","row","isModified","toggleSelected","getIsSelected","getIsAllRowsSelected","toggleAllRowsSelected","id","handleCheckboxChange","e","nativePointerEvent","nativeEvent","MouseEvent","KeyboardEvent","undefined","isModifed","metaKey","shiftKey","handleSortingChange","sortingUpdater","newSorting","checkboxColumn","size","header","checked","indeterminate","getIsSomeRowsSelected","onChange","getToggleAllRowsSelectedHandler","color","palette","text","primary","cell","getIsSomeSelected","original","enableSorting","tableColumns","initTableColumns","unshift","manualPagination","enableRowSelection","sortDescFirst","state","handleRowClick","rowId","getRow","isModifiedClick","onRowClick","rows","getRowModel","getAllFlatColumns","headers","getHeaderGroups","rowCount","getRowCount"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SACEA,aAAa,EACbC,eAAe,EAOfC,iBAAiB,E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BQ;QAExD,IAAIK,mBAAmB;YACrBsD,iBAAiBC,OAAO,CAAClB;QAC3B;QAEA,OAAOiB;IACT,GAAG;QAACjB;QAAgBrC;QAAmBL;KAAQ;IAE/C,MAAMqB,QAAQtC,cAAc;QAC1BY;QACAK,SAAS0D;QACTjD;QACAzB,iBAAiBA;QACjBC,mBAAmBA;QACnBC,uBAAuB0B,aAAa1B,0BAA0BiD;QAC9D,kIAAkI;QAClI,4EAA4E;QAC5E0B,kBAAkB,CAACjD;QACnBkD,oBAAoB,CAAC,CAACzD;QACtBC,sBAAsBW;QACtBV,iBAAiBgC;QACjB,6EAA6E;QAC7E,oDAAoD;QACpDwB,eAAe;QACfC,OAAO;YACLtD;YACAC;YACA,GAAIC,aAAa;gBAAEA;YAAW,IAAI,CAAC,CAAC;QACtC;IACF;IAEA,MAAMqD,iBAAiB7E,YACrB,CAAC0C,GAAiDoC;QAChD,MAAM5C,MAAMD,MAAM8C,MAAM,CAACD;QACzB,MAAME,kBAAkBtC,EAAEO,OAAO,IAAIP,EAAEQ,QAAQ;QAC/ClB,wBAAwBC,OAAOC,KAAK8C;IACtC,GACA;QAAChD;QAAyBC;KAAM;IAGlC,qBACE,KAAC/B;QACE,GAAGyB,UAAU;QACdb,SAASA;QACTC,oBAAoBA;QACpBC,qBAAqBA;QACrBiE,YAAYJ;QACZK,MAAMjD,MAAMkD,WAAW,GAAGD,IAAI;QAC9BtE,SAASqB,MAAMmD,iBAAiB;QAChCC,SAASpD,MAAMqD,eAAe;QAC9BzE,aAAaA;QACbW,YAAYA;QACZC,oBAAoBA;QACpB8D,UAAUtD,MAAMuD,WAAW;;AAGjC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { TableFooterProps as MuiTableFooterProps } from '@mui/material';
|
|
3
|
+
export declare const TableFoot: import("react").ForwardRefExoticComponent<Omit<MuiTableFooterProps, "ref"> & import("react").RefAttributes<HTMLTableSectionElement>>;
|
|
4
|
+
//# sourceMappingURL=TableFoot.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableFoot.d.ts","sourceRoot":"","sources":["../../src/Table/TableFoot.tsx"],"names":[],"mappings":";AAaA,OAAO,EAAiC,gBAAgB,IAAI,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAGvG,eAAO,MAAM,SAAS,sIAEpB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// Copyright
|
|
1
|
+
// Copyright 2025 The Perses Authors
|
|
2
2
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
3
|
// you may not use this file except in compliance with the License.
|
|
4
4
|
// You may obtain a copy of the License at
|
|
@@ -10,6 +10,14 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
import { TableFooter as MuiTableFooter } from '@mui/material';
|
|
15
|
+
import { forwardRef } from 'react';
|
|
16
|
+
export const TableFoot = /*#__PURE__*/ forwardRef(function TableFoot(props, ref) {
|
|
17
|
+
return /*#__PURE__*/ _jsx(MuiTableFooter, {
|
|
18
|
+
...props,
|
|
19
|
+
ref: ref
|
|
20
|
+
});
|
|
21
|
+
});
|
|
14
22
|
|
|
15
|
-
//# sourceMappingURL=
|
|
23
|
+
//# sourceMappingURL=TableFoot.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/Table/TableFoot.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TableFooter as MuiTableFooter, TableFooterProps as MuiTableFooterProps } from '@mui/material';\nimport { forwardRef } from 'react';\n\nexport const TableFoot = forwardRef<HTMLTableSectionElement, MuiTableFooterProps>(function TableFoot(props, ref) {\n return <MuiTableFooter {...props} ref={ref} />;\n});\n"],"names":["TableFooter","MuiTableFooter","forwardRef","TableFoot","props","ref"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,eAAeC,cAAc,QAAiD,gBAAgB;AACvG,SAASC,UAAU,QAAQ,QAAQ;AAEnC,OAAO,MAAMC,0BAAYD,WAAyD,SAASC,UAAUC,KAAK,EAAEC,GAAG;IAC7G,qBAAO,KAACJ;QAAgB,GAAGG,KAAK;QAAEC,KAAKA;;AACzC,GAAG"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Column, HeaderGroup, Row } from '@tanstack/react-table';
|
|
2
2
|
import { ReactElement } from 'react';
|
|
3
3
|
import { TableCellConfigs, TableProps } from './model/table-model';
|
|
4
|
-
export type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>> & Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut'> & {
|
|
4
|
+
export type VirtualizedTableProps<TableData> = Required<Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>> & Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {
|
|
5
5
|
onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;
|
|
6
6
|
rows: Array<Row<TableData>>;
|
|
7
7
|
columns: Array<Column<TableData, unknown>>;
|
|
8
8
|
headers: Array<HeaderGroup<TableData>>;
|
|
9
9
|
cellConfigs?: TableCellConfigs;
|
|
10
|
+
rowCount: number;
|
|
10
11
|
};
|
|
11
|
-
export declare function VirtualizedTable<TableData>({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, }: VirtualizedTableProps<TableData>): ReactElement;
|
|
12
|
+
export declare function VirtualizedTable<TableData>({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount, }: VirtualizedTableProps<TableData>): ReactElement;
|
|
12
13
|
//# sourceMappingURL=VirtualizedTable.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VirtualizedTable.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAc,MAAM,uBAAuB,CAAC;AAG7E,OAAO,EAAmB,YAAY,EAAE,MAAM,OAAO,CAAC;AAQtD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"VirtualizedTable.d.ts","sourceRoot":"","sources":["../../src/Table/VirtualizedTable.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAc,MAAM,uBAAuB,CAAC;AAG7E,OAAO,EAAmB,YAAY,EAAE,MAAM,OAAO,CAAC;AAQtD,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAqB,MAAM,qBAAqB,CAAC;AAStF,MAAM,MAAM,qBAAqB,CAAC,SAAS,IAAI,QAAQ,CACrD,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,SAAS,GAAG,oBAAoB,GAAG,qBAAqB,CAAC,CAC3G,GACC,IAAI,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,gBAAgB,GAAG,eAAe,GAAG,YAAY,GAAG,oBAAoB,CAAC,GAAG;IACtG,UAAU,EAAE,CAAC,CAAC,EAAE,KAAK,CAAC,UAAU,CAAC,cAAc,EAAE,UAAU,CAAC,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAClF,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC;IAC5B,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC;IAC3C,OAAO,EAAE,KAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC,CAAC;IACvC,WAAW,CAAC,EAAE,gBAAgB,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAKJ,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,EAC1C,KAAK,EACL,MAAM,EACN,OAAO,EACP,kBAAkB,EAClB,mBAAmB,EACnB,UAAU,EACV,cAAc,EACd,aAAa,EACb,IAAI,EACJ,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,kBAAkB,EAClB,QAAQ,GACT,EAAE,qBAAqB,CAAC,SAAS,CAAC,GAAG,YAAY,CA+MjD"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { flexRender } from '@tanstack/react-table';
|
|
15
|
-
import { Box } from '@mui/material';
|
|
15
|
+
import { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';
|
|
16
16
|
import { TableVirtuoso } from 'react-virtuoso';
|
|
17
17
|
import { useRef, useMemo } from 'react';
|
|
18
18
|
import { TableRow } from './TableRow';
|
|
@@ -23,10 +23,11 @@ import { TableHeaderCell } from './TableHeaderCell';
|
|
|
23
23
|
import { TableCell } from './TableCell';
|
|
24
24
|
import { VirtualizedTableContainer } from './VirtualizedTableContainer';
|
|
25
25
|
import { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';
|
|
26
|
+
import { TableFoot } from './TableFoot';
|
|
26
27
|
// Separating out the virtualized table because we may want a paginated table
|
|
27
28
|
// in the future that does not need virtualization, and we'd likely lay them
|
|
28
29
|
// out differently.
|
|
29
|
-
export function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs }) {
|
|
30
|
+
export function VirtualizedTable({ width, height, density, defaultColumnWidth, defaultColumnHeight, onRowClick, onRowMouseOver, onRowMouseOut, rows, columns, headers, cellConfigs, pagination, onPaginationChange, rowCount }) {
|
|
30
31
|
const virtuosoRef = useRef(null);
|
|
31
32
|
// Use a ref for these values because they are only needed for keyboard
|
|
32
33
|
// focus interactions and setting them on state will lead to a significant
|
|
@@ -63,6 +64,7 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, d
|
|
|
63
64
|
});
|
|
64
65
|
},
|
|
65
66
|
TableHead,
|
|
67
|
+
TableFoot,
|
|
66
68
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
67
69
|
TableRow: ({ item, ...props })=>{
|
|
68
70
|
const index = props['data-index'];
|
|
@@ -97,6 +99,20 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, d
|
|
|
97
99
|
rows,
|
|
98
100
|
width
|
|
99
101
|
]);
|
|
102
|
+
const handleChangePage = (_event, newPage)=>{
|
|
103
|
+
if (!pagination || !onPaginationChange) return;
|
|
104
|
+
onPaginationChange({
|
|
105
|
+
...pagination,
|
|
106
|
+
pageIndex: newPage
|
|
107
|
+
});
|
|
108
|
+
};
|
|
109
|
+
const handleChangeRowsPerPage = (event)=>{
|
|
110
|
+
if (!pagination || !onPaginationChange) return;
|
|
111
|
+
onPaginationChange({
|
|
112
|
+
pageIndex: 0,
|
|
113
|
+
pageSize: parseInt(event.target.value, 10)
|
|
114
|
+
});
|
|
115
|
+
};
|
|
100
116
|
return /*#__PURE__*/ _jsx(Box, {
|
|
101
117
|
style: {
|
|
102
118
|
width,
|
|
@@ -144,6 +160,19 @@ export function VirtualizedTable({ width, height, density, defaultColumnWidth, d
|
|
|
144
160
|
})
|
|
145
161
|
});
|
|
146
162
|
},
|
|
163
|
+
fixedFooterContent: pagination ? ()=>/*#__PURE__*/ _jsx(MuiTableRow, {
|
|
164
|
+
sx: {
|
|
165
|
+
backgroundColor: (theme)=>theme.palette.background.default
|
|
166
|
+
},
|
|
167
|
+
children: /*#__PURE__*/ _jsx(TablePagination, {
|
|
168
|
+
colSpan: columns.length,
|
|
169
|
+
count: rowCount,
|
|
170
|
+
page: pagination.pageIndex,
|
|
171
|
+
rowsPerPage: pagination.pageSize,
|
|
172
|
+
onPageChange: handleChangePage,
|
|
173
|
+
onRowsPerPageChange: handleChangeRowsPerPage
|
|
174
|
+
})
|
|
175
|
+
}) : undefined,
|
|
147
176
|
itemContent: (index)=>{
|
|
148
177
|
const row = rows[index];
|
|
149
178
|
if (!row) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Column, HeaderGroup, Row, flexRender } from '@tanstack/react-table';\nimport { Box } from '@mui/material';\nimport { TableVirtuoso, TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { useRef, useMemo, ReactElement } from 'react';\nimport { TableRow } from './TableRow';\nimport { TableBody } from './TableBody';\nimport { InnerTable } from './InnerTable';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableCell, TableCellProps } from './TableCell';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\nimport { TableCellConfigs, TableProps, TableRowEventOpts } from './model/table-model';\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nexport type VirtualizedTableProps<TableData> = Required<\n Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>\n> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n cellConfigs?: TableCellConfigs;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n defaultColumnWidth,\n defaultColumnHeight,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n rows,\n columns,\n headers,\n cellConfigs,\n}: VirtualizedTableProps<TableData>): ReactElement {\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const VirtuosoTableComponents: TableComponents<TableData> = useMemo(() => {\n return {\n Scroller: VirtualizedTableContainer,\n Table: (props): ReactElement => {\n return <InnerTable {...props} width={width} density={density} onKeyDown={keyboardNav.onTableKeyDown} />;\n },\n TableHead,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n TableRow: ({ item, ...props }): ReactElement | null => {\n const index = props['data-index'];\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: row.id, index: row.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => onRowClick(e, row.id)}\n density={density}\n onMouseOver={(e) => {\n onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody,\n };\n }, [density, keyboardNav.onTableKeyDown, onRowClick, onRowMouseOut, onRowMouseOver, rows, width]);\n\n return (\n <Box style={{ width, height }}>\n <TableVirtuoso\n ref={virtuosoRef}\n totalCount={rows.length}\n components={VirtuosoTableComponents}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n // Add 1 to the row index because the header is row 0\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellConfig = cellConfigs?.[cellContext.cell.id];\n\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n return (\n <TableCell\n key={cell.id}\n data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\n width={cell.column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n >\n {cellConfig?.text || cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["flexRender","Box","TableVirtuoso","useRef","useMemo","TableRow","TableBody","InnerTable","TableHead","TableHeaderCell","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","VirtualizedTable","width","height","density","defaultColumnWidth","defaultColumnHeight","onRowClick","onRowMouseOver","onRowMouseOut","rows","columns","headers","cellConfigs","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","VirtuosoTableComponents","Scroller","Table","props","onKeyDown","onTableKeyDown","item","index","rowEventOpts","id","onClick","e","onMouseOver","onMouseOut","style","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","headerGroup","header","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","getSize","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","getContext","itemContent","getVisibleCells","cell","cells","cellContext","cellConfig","cellRenderFn","cellContent","cellDescriptionDef","cellDescription","data-testid","title","text","color","textColor","backgroundColor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAmCA,UAAU,QAAQ,wBAAwB;AAC7E,SAASC,GAAG,QAAQ,gBAAgB;AACpC,SAASC,aAAa,QAAkE,iBAAiB;AACzG,SAASC,MAAM,EAAEC,OAAO,QAAsB,QAAQ;AACtD,SAASC,QAAQ,QAAQ,aAAa;AACtC,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAwB,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F,eAAaR,KAAKzC,EAAE;4BACpBkD,OAAOnB,eAAea,YAAYO,QAAQL;4BAC1CrF,OAAOgF,KAAKpD,MAAM,CAACqC,OAAO,MAAM9D;4BAChCC,qBAAqBA;4BACrB8D,OAAOc,KAAKpD,MAAM,CAACuC,SAAS,CAACC,IAAI,EAAEF;4BACnChE,SAASA;4BACTsE,YAAYhD,cAAc8B;4BAC1BmB,gBAAgB,IAAMtD,YAAYuD,WAAW,CAACpB;4BAC9CqB,eAAetB,MAAM;4BACrBuB,cAAcvB,MAAM4B,MAAM3D,MAAM,GAAG;4BACnCgD,aAAaA;4BACbqB,OAAOR,YAAYS,aAAa9B;4BAChC+B,iBAAiBV,YAAYU,mBAAmB/B;sCAE/CqB,YAAYO,QAAQL;2BAfhBL,KAAKzC,EAAE;oBAkBlB;;YAGN;;;AAIR"}
|
|
1
|
+
{"version":3,"sources":["../../src/Table/VirtualizedTable.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Column, HeaderGroup, Row, flexRender } from '@tanstack/react-table';\nimport { Box, TablePagination, TableRow as MuiTableRow } from '@mui/material';\nimport { TableVirtuoso, TableComponents, TableVirtuosoHandle, TableVirtuosoProps } from 'react-virtuoso';\nimport { useRef, useMemo, ReactElement } from 'react';\nimport { TableRow } from './TableRow';\nimport { TableBody } from './TableBody';\nimport { InnerTable } from './InnerTable';\nimport { TableHead } from './TableHead';\nimport { TableHeaderCell } from './TableHeaderCell';\nimport { TableCell, TableCellProps } from './TableCell';\nimport { VirtualizedTableContainer } from './VirtualizedTableContainer';\nimport { TableCellConfigs, TableProps, TableRowEventOpts } from './model/table-model';\nimport { useVirtualizedTableKeyboardNav } from './hooks/useVirtualizedTableKeyboardNav';\nimport { TableFoot } from './TableFoot';\n\ntype TableCellPosition = {\n row: number;\n column: number;\n};\n\nexport type VirtualizedTableProps<TableData> = Required<\n Pick<TableProps<TableData>, 'height' | 'width' | 'density' | 'defaultColumnWidth' | 'defaultColumnHeight'>\n> &\n Pick<TableProps<TableData>, 'onRowMouseOver' | 'onRowMouseOut' | 'pagination' | 'onPaginationChange'> & {\n onRowClick: (e: React.MouseEvent<HTMLDivElement, MouseEvent>, id: string) => void;\n rows: Array<Row<TableData>>;\n columns: Array<Column<TableData, unknown>>;\n headers: Array<HeaderGroup<TableData>>;\n cellConfigs?: TableCellConfigs;\n rowCount: number;\n };\n\n// Separating out the virtualized table because we may want a paginated table\n// in the future that does not need virtualization, and we'd likely lay them\n// out differently.\nexport function VirtualizedTable<TableData>({\n width,\n height,\n density,\n defaultColumnWidth,\n defaultColumnHeight,\n onRowClick,\n onRowMouseOver,\n onRowMouseOut,\n rows,\n columns,\n headers,\n cellConfigs,\n pagination,\n onPaginationChange,\n rowCount,\n}: VirtualizedTableProps<TableData>): ReactElement {\n const virtuosoRef = useRef<TableVirtuosoHandle>(null);\n\n // Use a ref for these values because they are only needed for keyboard\n // focus interactions and setting them on state will lead to a significant\n // amount of unnecessary re-renders.\n const visibleRange = useRef({\n startIndex: 0,\n endIndex: 0,\n });\n const setVisibleRange: TableVirtuosoProps<TableData, unknown>['rangeChanged'] = (newVisibleRange) => {\n visibleRange.current = newVisibleRange;\n };\n\n const keyboardNav = useVirtualizedTableKeyboardNav({\n visibleRange: visibleRange,\n virtualTable: virtuosoRef,\n\n // We add 1 here for the header.\n maxRows: rows.length + 1,\n maxColumns: columns.length,\n });\n\n const getFocusState = (cellPosition: TableCellPosition): TableCellProps['focusState'] => {\n if (cellPosition.row === keyboardNav.activeCell.row && cellPosition.column === keyboardNav.activeCell.column) {\n return keyboardNav.isActive ? 'trigger-focus' : 'focus-next';\n }\n\n return 'none';\n };\n\n const VirtuosoTableComponents: TableComponents<TableData> = useMemo(() => {\n return {\n Scroller: VirtualizedTableContainer,\n Table: (props): ReactElement => {\n return <InnerTable {...props} width={width} density={density} onKeyDown={keyboardNav.onTableKeyDown} />;\n },\n TableHead,\n TableFoot,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n TableRow: ({ item, ...props }): ReactElement | null => {\n const index = props['data-index'];\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n const rowEventOpts: TableRowEventOpts = { id: row.id, index: row.index };\n\n return (\n <TableRow\n {...props}\n onClick={(e) => onRowClick(e, row.id)}\n density={density}\n onMouseOver={(e) => {\n onRowMouseOver?.(e, rowEventOpts);\n }}\n onMouseOut={(e) => {\n onRowMouseOut?.(e, rowEventOpts);\n }}\n />\n );\n },\n TableBody,\n };\n }, [density, keyboardNav.onTableKeyDown, onRowClick, onRowMouseOut, onRowMouseOver, rows, width]);\n\n const handleChangePage = (_event: React.MouseEvent<HTMLButtonElement> | null, newPage: number): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ ...pagination, pageIndex: newPage });\n };\n\n const handleChangeRowsPerPage = (event: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>): void => {\n if (!pagination || !onPaginationChange) return;\n onPaginationChange({ pageIndex: 0, pageSize: parseInt(event.target.value, 10) });\n };\n\n return (\n <Box style={{ width, height }}>\n <TableVirtuoso\n ref={virtuosoRef}\n totalCount={rows.length}\n components={VirtuosoTableComponents}\n // Note: this value is impacted by overscan. See this issue if overscan\n // is added.\n // https://github.com/petyosi/react-virtuoso/issues/118#issuecomment-642156138\n rangeChanged={setVisibleRange}\n fixedHeaderContent={() => {\n return (\n <>\n {headers.map((headerGroup) => {\n return (\n <TableRow key={headerGroup.id} density={density}>\n {headerGroup.headers.map((header, i, headers) => {\n const column = header.column;\n const position: TableCellPosition = {\n row: 0,\n column: i,\n };\n\n const isSorted = column.getIsSorted();\n const nextSorting = column.getNextSortingOrder();\n\n return (\n <TableHeaderCell\n key={header.id}\n onSort={column.getCanSort() ? column.getToggleSortingHandler() : undefined}\n sortDirection={typeof isSorted === 'string' ? isSorted : undefined}\n nextSortDirection={typeof nextSorting === 'string' ? nextSorting : undefined}\n width={column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={column.columnDef.meta?.align}\n variant=\"head\"\n density={density}\n description={column.columnDef.meta?.headerDescription}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === headers.length - 1}\n >\n {flexRender(column.columnDef.header, header.getContext())}\n </TableHeaderCell>\n );\n })}\n </TableRow>\n );\n })}\n </>\n );\n }}\n fixedFooterContent={\n pagination\n ? (): ReactElement => (\n <MuiTableRow sx={{ backgroundColor: (theme) => theme.palette.background.default }}>\n <TablePagination\n colSpan={columns.length}\n count={rowCount}\n page={pagination.pageIndex}\n rowsPerPage={pagination.pageSize}\n onPageChange={handleChangePage}\n onRowsPerPageChange={handleChangeRowsPerPage}\n />\n </MuiTableRow>\n )\n : undefined\n }\n itemContent={(index) => {\n const row = rows[index];\n if (!row) {\n return null;\n }\n\n return (\n <>\n {row.getVisibleCells().map((cell, i, cells) => {\n const position: TableCellPosition = {\n // Add 1 to the row index because the header is row 0\n row: index + 1,\n column: i,\n };\n\n const cellContext = cell.getContext();\n const cellConfig = cellConfigs?.[cellContext.cell.id];\n\n const cellRenderFn = cell.column.columnDef.cell;\n const cellContent = typeof cellRenderFn === 'function' ? cellRenderFn(cellContext) : null;\n\n const cellDescriptionDef = cell.column.columnDef.meta?.cellDescription;\n let description: string | undefined = undefined;\n if (typeof cellDescriptionDef === 'function') {\n // If the cell description is a function, set the value using\n // the function.\n description = cellDescriptionDef(cellContext);\n } else if (cellDescriptionDef && typeof cellContent === 'string') {\n // If the cell description is `true` AND the cell content is\n // a string (and thus viable as a `title` attribute), use the\n // cell content.\n description = cellContent;\n }\n\n return (\n <TableCell\n key={cell.id}\n data-testid={cell.id}\n title={description || cellConfig?.text || cellContent}\n width={cell.column.getSize() || defaultColumnWidth}\n defaultColumnHeight={defaultColumnHeight}\n align={cell.column.columnDef.meta?.align}\n density={density}\n focusState={getFocusState(position)}\n onFocusTrigger={() => keyboardNav.onCellFocus(position)}\n isFirstColumn={i === 0}\n isLastColumn={i === cells.length - 1}\n description={description}\n color={cellConfig?.textColor ?? undefined}\n backgroundColor={cellConfig?.backgroundColor ?? undefined}\n >\n {cellConfig?.text || cellContent}\n </TableCell>\n );\n })}\n </>\n );\n }}\n />\n </Box>\n );\n}\n"],"names":["flexRender","Box","TablePagination","TableRow","MuiTableRow","TableVirtuoso","useRef","useMemo","TableBody","InnerTable","TableHead","TableHeaderCell","TableCell","VirtualizedTableContainer","useVirtualizedTableKeyboardNav","TableFoot","VirtualizedTable","width","height","density","defaultColumnWidth","defaultColumnHeight","onRowClick","onRowMouseOver","onRowMouseOut","rows","columns","headers","cellConfigs","pagination","onPaginationChange","rowCount","virtuosoRef","visibleRange","startIndex","endIndex","setVisibleRange","newVisibleRange","current","keyboardNav","virtualTable","maxRows","length","maxColumns","getFocusState","cellPosition","row","activeCell","column","isActive","VirtuosoTableComponents","Scroller","Table","props","onKeyDown","onTableKeyDown","item","index","rowEventOpts","id","onClick","e","onMouseOver","onMouseOut","handleChangePage","_event","newPage","pageIndex","handleChangeRowsPerPage","event","pageSize","parseInt","target","value","style","ref","totalCount","components","rangeChanged","fixedHeaderContent","map","headerGroup","header","i","position","isSorted","getIsSorted","nextSorting","getNextSortingOrder","onSort","getCanSort","getToggleSortingHandler","undefined","sortDirection","nextSortDirection","getSize","align","columnDef","meta","variant","description","headerDescription","focusState","onFocusTrigger","onCellFocus","isFirstColumn","isLastColumn","getContext","fixedFooterContent","sx","backgroundColor","theme","palette","background","default","colSpan","count","page","rowsPerPage","onPageChange","onRowsPerPageChange","itemContent","getVisibleCells","cell","cells","cellContext","cellConfig","cellRenderFn","cellContent","cellDescriptionDef","cellDescription","data-testid","title","text","color","textColor"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAAmCA,UAAU,QAAQ,wBAAwB;AAC7E,SAASC,GAAG,EAAEC,eAAe,EAAEC,YAAYC,WAAW,QAAQ,gBAAgB;AAC9E,SAASC,aAAa,QAAkE,iBAAiB;AACzG,SAASC,MAAM,EAAEC,OAAO,QAAsB,QAAQ;AACtD,SAASJ,QAAQ,QAAQ,aAAa;AACtC,SAASK,SAAS,QAAQ,cAAc;AACxC,SAASC,UAAU,QAAQ,eAAe;AAC1C,SAASC,SAAS,QAAQ,cAAc;AACxC,SAASC,eAAe,QAAQ,oBAAoB;AACpD,SAASC,SAAS,QAAwB,cAAc;AACxD,SAASC,yBAAyB,QAAQ,8BAA8B;AAExE,SAASC,8BAA8B,QAAQ,yCAAyC;AACxF,SAASC,SAAS,QAAQ,cAAc;AAmBxC,6EAA6E;AAC7E,4EAA4E;AAC5E,mBAAmB;AACnB,OAAO,SAASC,iBAA4B,EAC1CC,KAAK,EACLC,MAAM,EACNC,OAAO,EACPC,kBAAkB,EAClBC,mBAAmB,EACnBC,UAAU,EACVC,cAAc,EACdC,aAAa,EACbC,IAAI,EACJC,OAAO,EACPC,OAAO,EACPC,WAAW,EACXC,UAAU,EACVC,kBAAkB,EAClBC,QAAQ,EACyB;IACjC,MAAMC,cAAc1B,OAA4B;IAEhD,uEAAuE;IACvE,0EAA0E;IAC1E,oCAAoC;IACpC,MAAM2B,eAAe3B,OAAO;QAC1B4B,YAAY;QACZC,UAAU;IACZ;IACA,MAAMC,kBAA0E,CAACC;QAC/EJ,aAAaK,OAAO,GAAGD;IACzB;IAEA,MAAME,cAAczB,+BAA+B;QACjDmB,cAAcA;QACdO,cAAcR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