@perses-dev/components 0.29.1 → 0.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (198) hide show
  1. package/dist/DateTimeRangePicker/TimeRangeSelector.d.ts.map +1 -1
  2. package/dist/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  3. package/dist/DateTimeRangePicker/TimeRangeSelector.js.map +1 -1
  4. package/dist/EChart/EChart.d.ts.map +1 -1
  5. package/dist/EChart/EChart.js +1 -7
  6. package/dist/EChart/EChart.js.map +1 -1
  7. package/dist/Legend/CompactLegend.d.ts +6 -4
  8. package/dist/Legend/CompactLegend.d.ts.map +1 -1
  9. package/dist/Legend/CompactLegend.js +4 -1
  10. package/dist/Legend/CompactLegend.js.map +1 -1
  11. package/dist/Legend/Legend.d.ts +11 -9
  12. package/dist/Legend/Legend.d.ts.map +1 -1
  13. package/dist/Legend/Legend.js +45 -11
  14. package/dist/Legend/Legend.js.map +1 -1
  15. package/dist/Legend/ListLegend.d.ts +5 -8
  16. package/dist/Legend/ListLegend.d.ts.map +1 -1
  17. package/dist/Legend/ListLegend.js +34 -99
  18. package/dist/Legend/ListLegend.js.map +1 -1
  19. package/dist/Legend/ListLegendItem.d.ts +8 -8
  20. package/dist/Legend/ListLegendItem.d.ts.map +1 -1
  21. package/dist/Legend/ListLegendItem.js +9 -12
  22. package/dist/Legend/ListLegendItem.js.map +1 -1
  23. package/dist/LineChart/LineChart.d.ts +2 -1
  24. package/dist/LineChart/LineChart.d.ts.map +1 -1
  25. package/dist/LineChart/LineChart.js +35 -22
  26. package/dist/LineChart/LineChart.js.map +1 -1
  27. package/dist/StatChart/StatChart.d.ts.map +1 -1
  28. package/dist/StatChart/StatChart.js +5 -1
  29. package/dist/StatChart/StatChart.js.map +1 -1
  30. package/dist/Table/InnerTable.d.ts +9 -0
  31. package/dist/Table/InnerTable.d.ts.map +1 -0
  32. package/dist/Table/InnerTable.js +38 -0
  33. package/dist/Table/InnerTable.js.map +1 -0
  34. package/dist/Table/Table.d.ts +10 -0
  35. package/dist/Table/Table.d.ts.map +1 -0
  36. package/dist/Table/Table.js +101 -0
  37. package/dist/Table/Table.js.map +1 -0
  38. package/dist/Table/TableBody.d.ts +6 -0
  39. package/dist/Table/TableBody.d.ts.map +1 -0
  40. package/dist/Table/TableBody.js +23 -0
  41. package/dist/Table/TableBody.js.map +1 -0
  42. package/dist/Table/TableCell.d.ts +18 -0
  43. package/dist/Table/TableCell.d.ts.map +1 -0
  44. package/dist/Table/TableCell.js +91 -0
  45. package/dist/Table/TableCell.js.map +1 -0
  46. package/dist/Table/TableCheckbox.d.ts +9 -0
  47. package/dist/Table/TableCheckbox.d.ts.map +1 -0
  48. package/dist/Table/TableCheckbox.js +49 -0
  49. package/dist/Table/TableCheckbox.js.map +1 -0
  50. package/dist/Table/TableHead.d.ts +6 -0
  51. package/dist/Table/TableHead.d.ts.map +1 -0
  52. package/dist/Table/TableHead.js +23 -0
  53. package/dist/Table/TableHead.js.map +1 -0
  54. package/dist/Table/TableRow.d.ts +9 -0
  55. package/dist/Table/TableRow.d.ts.map +1 -0
  56. package/dist/Table/TableRow.js +29 -0
  57. package/dist/Table/TableRow.js.map +1 -0
  58. package/dist/Table/VirtualizedTable.d.ts +11 -0
  59. package/dist/Table/VirtualizedTable.d.ts.map +1 -0
  60. package/dist/Table/VirtualizedTable.js +152 -0
  61. package/dist/Table/VirtualizedTable.js.map +1 -0
  62. package/dist/Table/VirtualizedTableContainer.d.ts +6 -0
  63. package/dist/Table/VirtualizedTableContainer.d.ts.map +1 -0
  64. package/dist/Table/VirtualizedTableContainer.js +24 -0
  65. package/dist/Table/VirtualizedTableContainer.js.map +1 -0
  66. package/dist/Table/hooks/useTableKeyboardNav.d.ts +32 -0
  67. package/dist/Table/hooks/useTableKeyboardNav.d.ts.map +1 -0
  68. package/dist/Table/hooks/useTableKeyboardNav.js +98 -0
  69. package/dist/Table/hooks/useTableKeyboardNav.js.map +1 -0
  70. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts +29 -0
  71. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.d.ts.map +1 -0
  72. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js +89 -0
  73. package/dist/Table/hooks/useVirtualizedTableKeyboardNav.js.map +1 -0
  74. package/dist/Table/index.d.ts +4 -0
  75. package/dist/Table/index.d.ts.map +1 -0
  76. package/dist/Table/index.js +16 -0
  77. package/dist/Table/index.js.map +1 -0
  78. package/dist/Table/model/table-model.d.ts +83 -0
  79. package/dist/Table/model/table-model.d.ts.map +1 -0
  80. package/dist/Table/model/table-model.js +73 -0
  81. package/dist/Table/model/table-model.js.map +1 -0
  82. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts +1 -0
  83. package/dist/TimeSeriesTooltip/SeriesInfo.d.ts.map +1 -1
  84. package/dist/TimeSeriesTooltip/SeriesInfo.js +11 -9
  85. package/dist/TimeSeriesTooltip/SeriesInfo.js.map +1 -1
  86. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts +3 -2
  87. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.d.ts.map +1 -1
  88. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js +63 -17
  89. package/dist/TimeSeriesTooltip/TimeSeriesTooltip.js.map +1 -1
  90. package/dist/TimeSeriesTooltip/TooltipContent.d.ts +5 -3
  91. package/dist/TimeSeriesTooltip/TooltipContent.d.ts.map +1 -1
  92. package/dist/TimeSeriesTooltip/TooltipContent.js +81 -44
  93. package/dist/TimeSeriesTooltip/TooltipContent.js.map +1 -1
  94. package/dist/TimeSeriesTooltip/index.d.ts +1 -1
  95. package/dist/TimeSeriesTooltip/index.d.ts.map +1 -1
  96. package/dist/TimeSeriesTooltip/index.js +1 -1
  97. package/dist/TimeSeriesTooltip/index.js.map +1 -1
  98. package/dist/TimeSeriesTooltip/nearby-series.d.ts +46 -0
  99. package/dist/TimeSeriesTooltip/nearby-series.d.ts.map +1 -0
  100. package/dist/TimeSeriesTooltip/nearby-series.js +200 -0
  101. package/dist/TimeSeriesTooltip/nearby-series.js.map +1 -0
  102. package/dist/TimeSeriesTooltip/tooltip-model.d.ts +12 -4
  103. package/dist/TimeSeriesTooltip/tooltip-model.d.ts.map +1 -1
  104. package/dist/TimeSeriesTooltip/tooltip-model.js +10 -2
  105. package/dist/TimeSeriesTooltip/tooltip-model.js.map +1 -1
  106. package/dist/TimeSeriesTooltip/utils.d.ts +1 -1
  107. package/dist/TimeSeriesTooltip/utils.d.ts.map +1 -1
  108. package/dist/TimeSeriesTooltip/utils.js +7 -15
  109. package/dist/TimeSeriesTooltip/utils.js.map +1 -1
  110. package/dist/UnitSelector/UnitSelector.d.ts.map +1 -1
  111. package/dist/UnitSelector/UnitSelector.js +40 -17
  112. package/dist/UnitSelector/UnitSelector.js.map +1 -1
  113. package/dist/cjs/DateTimeRangePicker/TimeRangeSelector.js +7 -1
  114. package/dist/cjs/EChart/EChart.js +1 -7
  115. package/dist/cjs/Legend/CompactLegend.js +4 -1
  116. package/dist/cjs/Legend/Legend.js +45 -11
  117. package/dist/cjs/Legend/ListLegend.js +33 -98
  118. package/dist/cjs/Legend/ListLegendItem.js +8 -11
  119. package/dist/cjs/LineChart/LineChart.js +35 -22
  120. package/dist/cjs/StatChart/StatChart.js +5 -1
  121. package/dist/cjs/Table/InnerTable.js +44 -0
  122. package/dist/cjs/Table/Table.js +102 -0
  123. package/dist/cjs/Table/TableBody.js +29 -0
  124. package/dist/cjs/Table/TableCell.js +97 -0
  125. package/dist/cjs/Table/TableCheckbox.js +55 -0
  126. package/dist/cjs/Table/TableHead.js +29 -0
  127. package/dist/cjs/Table/TableRow.js +35 -0
  128. package/dist/cjs/Table/VirtualizedTable.js +155 -0
  129. package/dist/cjs/Table/VirtualizedTableContainer.js +30 -0
  130. package/dist/cjs/Table/hooks/useTableKeyboardNav.js +99 -0
  131. package/dist/cjs/Table/hooks/useVirtualizedTableKeyboardNav.js +93 -0
  132. package/dist/cjs/Table/index.js +33 -0
  133. package/dist/cjs/Table/model/table-model.js +80 -0
  134. package/dist/cjs/TimeSeriesTooltip/SeriesInfo.js +10 -8
  135. package/dist/cjs/TimeSeriesTooltip/TimeSeriesTooltip.js +67 -16
  136. package/dist/cjs/TimeSeriesTooltip/TooltipContent.js +85 -43
  137. package/dist/cjs/TimeSeriesTooltip/index.js +1 -1
  138. package/dist/cjs/TimeSeriesTooltip/nearby-series.js +206 -0
  139. package/dist/cjs/TimeSeriesTooltip/tooltip-model.js +15 -3
  140. package/dist/cjs/TimeSeriesTooltip/utils.js +6 -14
  141. package/dist/cjs/UnitSelector/UnitSelector.js +39 -16
  142. package/dist/cjs/context/SnackbarProvider.js +66 -0
  143. package/dist/cjs/index.js +2 -0
  144. package/dist/cjs/model/legend.js +7 -1
  145. package/dist/cjs/model/units/bytes.js +25 -21
  146. package/dist/cjs/model/units/constants.js +3 -3
  147. package/dist/cjs/model/units/decimal.js +22 -19
  148. package/dist/cjs/model/units/percent.js +15 -22
  149. package/dist/cjs/model/units/time.js +24 -20
  150. package/dist/cjs/model/units/units.js +2 -2
  151. package/dist/cjs/model/units/utils.js +42 -0
  152. package/dist/cjs/theme/palette/grey.js +6 -2
  153. package/dist/context/SnackbarProvider.d.ts +23 -0
  154. package/dist/context/SnackbarProvider.d.ts.map +1 -0
  155. package/dist/context/SnackbarProvider.js +59 -0
  156. package/dist/context/SnackbarProvider.js.map +1 -0
  157. package/dist/index.d.ts +2 -0
  158. package/dist/index.d.ts.map +1 -1
  159. package/dist/index.js +2 -0
  160. package/dist/index.js.map +1 -1
  161. package/dist/model/legend.d.ts +10 -2
  162. package/dist/model/legend.d.ts.map +1 -1
  163. package/dist/model/legend.js +5 -0
  164. package/dist/model/legend.js.map +1 -1
  165. package/dist/model/units/bytes.d.ts +1 -1
  166. package/dist/model/units/bytes.d.ts.map +1 -1
  167. package/dist/model/units/bytes.js +26 -22
  168. package/dist/model/units/bytes.js.map +1 -1
  169. package/dist/model/units/constants.d.ts +1 -1
  170. package/dist/model/units/constants.js +1 -1
  171. package/dist/model/units/constants.js.map +1 -1
  172. package/dist/model/units/decimal.d.ts +2 -2
  173. package/dist/model/units/decimal.d.ts.map +1 -1
  174. package/dist/model/units/decimal.js +22 -19
  175. package/dist/model/units/decimal.js.map +1 -1
  176. package/dist/model/units/percent.d.ts +1 -1
  177. package/dist/model/units/percent.d.ts.map +1 -1
  178. package/dist/model/units/percent.js +14 -21
  179. package/dist/model/units/percent.js.map +1 -1
  180. package/dist/model/units/time.d.ts +1 -1
  181. package/dist/model/units/time.d.ts.map +1 -1
  182. package/dist/model/units/time.js +24 -20
  183. package/dist/model/units/time.js.map +1 -1
  184. package/dist/model/units/units.js +2 -2
  185. package/dist/model/units/units.js.map +1 -1
  186. package/dist/model/units/utils.d.ts +4 -0
  187. package/dist/model/units/utils.d.ts.map +1 -0
  188. package/dist/model/units/utils.js +32 -0
  189. package/dist/model/units/utils.js.map +1 -0
  190. package/dist/theme/palette/grey.d.ts.map +1 -1
  191. package/dist/theme/palette/grey.js +6 -2
  192. package/dist/theme/palette/grey.js.map +1 -1
  193. package/package.json +6 -6
  194. package/dist/TimeSeriesTooltip/focused-series.d.ts +0 -25
  195. package/dist/TimeSeriesTooltip/focused-series.d.ts.map +0 -1
  196. package/dist/TimeSeriesTooltip/focused-series.js +0 -111
  197. package/dist/TimeSeriesTooltip/focused-series.js.map +0 -1
  198. package/dist/cjs/TimeSeriesTooltip/focused-series.js +0 -117
@@ -26,7 +26,6 @@ const _charts = require("echarts/charts");
26
26
  const _components = require("echarts/components");
27
27
  const _renderers = require("echarts/renderers");
28
28
  const _echart = require("../EChart");
29
- const _graph = require("../model/graph");
30
29
  const _chartsThemeProvider = require("../context/ChartsThemeProvider");
31
30
  const _timeSeriesTooltip = require("../TimeSeriesTooltip");
32
31
  const _timeZoneProvider = require("../context/TimeZoneProvider");
@@ -85,12 +84,12 @@ function _interopRequireWildcard(obj, nodeInterop) {
85
84
  ]);
86
85
  function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfig ={
87
86
  wrapLabels: true
88
- } , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
87
+ } , noDataVariant ='message' , onDataZoom , onDoubleClick , __experimentalEChartsOptionsOverride }) {
89
88
  var ref;
90
89
  const chartsTheme = (0, _chartsThemeProvider.useChartsTheme)();
91
90
  const chartRef = (0, _react.useRef)();
92
91
  const [showTooltip, setShowTooltip] = (0, _react.useState)(true);
93
- const [pinTooltip, setPinTooltip] = (0, _react.useState)(false);
92
+ const [isTooltipPinned, setIsTooltipPinned] = (0, _react.useState)(false);
94
93
  const { timeZone } = (0, _timeZoneProvider.useTimeZone)();
95
94
  const handleEvents = (0, _react.useMemo)(()=>{
96
95
  return {
@@ -98,7 +97,7 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
98
97
  if (onDataZoom === undefined) {
99
98
  setTimeout(()=>{
100
99
  // workaround so unpin happens after click event
101
- setPinTooltip(false);
100
+ setIsTooltipPinned(false);
102
101
  }, 10);
103
102
  }
104
103
  if (onDataZoom === undefined || params.batch[0] === undefined) return;
@@ -122,13 +121,13 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
122
121
  }, [
123
122
  data,
124
123
  onDataZoom,
125
- setPinTooltip
124
+ setIsTooltipPinned
126
125
  ]);
127
126
  if (chartRef.current !== undefined) {
128
127
  (0, _utils.enableDataZoom)(chartRef.current);
129
128
  }
130
129
  const handleOnDoubleClick = (e)=>{
131
- setPinTooltip(false);
130
+ setIsTooltipPinned(false);
132
131
  // either dispatch ECharts restore action to return to orig state or allow consumer to define behavior
133
132
  if (onDoubleClick === undefined) {
134
133
  if (chartRef.current !== undefined) {
@@ -141,9 +140,9 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
141
140
  const { noDataOption } = chartsTheme;
142
141
  const option = (0, _react.useMemo)(()=>{
143
142
  if (data.timeSeries === undefined) return {};
144
- if (data.timeSeries === null || data.timeSeries.length === 0) return noDataOption;
145
- // show symbols and axisPointer dashed line on hover
146
- const isOptimizedMode = data.timeSeries.length > _graph.OPTIMIZED_MODE_SERIES_LIMIT;
143
+ // The "chart" `noDataVariant` is only used when the `timeSeries` is an
144
+ // empty array because a `null` value will throw an error.
145
+ if (data.timeSeries === null || data.timeSeries.length === 0 && noDataVariant === 'message') return noDataOption;
147
146
  var _rangeMs;
148
147
  const rangeMs = (_rangeMs = data.rangeMs) !== null && _rangeMs !== void 0 ? _rangeMs : (0, _utils.getDateRange)(data.xAxis);
149
148
  const option = {
@@ -161,13 +160,17 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
161
160
  yAxis: (0, _utils.getYAxes)(yAxis, unit),
162
161
  animation: false,
163
162
  tooltip: {
164
- show: !isOptimizedMode,
163
+ show: true,
165
164
  trigger: 'axis',
166
- showContent: false,
167
- axisPointer: {
168
- type: isOptimizedMode ? 'none' : 'line',
169
- z: 0
170
- }
165
+ showContent: false
166
+ },
167
+ // https://echarts.apache.org/en/option.html#axisPointer
168
+ axisPointer: {
169
+ type: 'line',
170
+ z: 0,
171
+ triggerEmphasis: false,
172
+ triggerTooltip: false,
173
+ snap: true
171
174
  },
172
175
  toolbox: {
173
176
  feature: {
@@ -192,17 +195,21 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
192
195
  legend,
193
196
  noDataOption,
194
197
  timeZone,
195
- __experimentalEChartsOptionsOverride
198
+ __experimentalEChartsOptionsOverride,
199
+ noDataVariant
196
200
  ]);
197
201
  return /*#__PURE__*/ (0, _jsxRuntime.jsxs)(_material.Box, {
198
202
  sx: {
199
203
  height
200
204
  },
201
- onClick: ()=>{
202
- setPinTooltip((current)=>!current);
205
+ onClick: (e)=>{
206
+ // Pin and unpin when clicking on chart canvas but not tooltip text.
207
+ if (e.target instanceof HTMLCanvasElement) {
208
+ setIsTooltipPinned((current)=>!current);
209
+ }
203
210
  },
204
211
  onMouseDown: (e)=>{
205
- // hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels
212
+ // Hide tooltip when user drags to zoom, but allow clicking inside tooltip to copy labels.
206
213
  if (e.target instanceof HTMLCanvasElement) {
207
214
  setShowTooltip(false);
208
215
  }
@@ -212,7 +219,6 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
212
219
  },
213
220
  onMouseLeave: ()=>{
214
221
  setShowTooltip(false);
215
- setPinTooltip(false);
216
222
  },
217
223
  onMouseEnter: ()=>{
218
224
  setShowTooltip(true);
@@ -226,10 +232,17 @@ function LineChart({ height , data , yAxis , unit , grid , legend , tooltipConfi
226
232
  chartRef: chartRef,
227
233
  chartData: data,
228
234
  wrapLabels: tooltipConfig.wrapLabels,
229
- pinTooltip: pinTooltip,
230
- unit: unit
235
+ isTooltipPinned: isTooltipPinned,
236
+ unit: unit,
237
+ onUnpinClick: ()=>{
238
+ setIsTooltipPinned(false);
239
+ }
231
240
  }),
232
241
  /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
242
+ sx: {
243
+ width: '100%',
244
+ height: '100%'
245
+ },
233
246
  option: option,
234
247
  theme: chartsTheme.echartsTheme,
235
248
  onEvents: handleEvents,
@@ -117,11 +117,15 @@ function StatChart(props) {
117
117
  sx: (theme)=>({
118
118
  color: color !== null && color !== void 0 ? color : theme.palette.text.primary,
119
119
  fontSize: `clamp(${MIN_VALUE_SIZE}px, ${valueSize}px, ${MAX_VALUE_SIZE}px)`,
120
- padding: `${containerPadding} ${containerPadding} 0 ${containerPadding}`
120
+ padding: sparkline ? `${containerPadding} ${containerPadding} 0 ${containerPadding}` : ` 0 ${containerPadding}`
121
121
  }),
122
122
  children: formattedValue
123
123
  }),
124
124
  sparkline !== undefined && /*#__PURE__*/ (0, _jsxRuntime.jsx)(_echart.EChart, {
125
+ sx: {
126
+ width: '100%',
127
+ height: '100%'
128
+ },
125
129
  option: option,
126
130
  theme: chartsTheme.echartsTheme,
127
131
  renderer: "svg"
@@ -0,0 +1,44 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "InnerTable", {
18
+ enumerable: true,
19
+ get: ()=>InnerTable
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = require("react");
24
+ const StyledMuiTable = (0, _material.styled)(_material.Table)(({ theme })=>({
25
+ // This value is needed to have a consistent table layout when scrolling.
26
+ tableLayout: 'fixed',
27
+ borderCollapse: 'separate',
28
+ backgroundColor: theme.palette.background.paper
29
+ }));
30
+ const TABLE_DENSITY_CONFIG = {
31
+ compact: 'small',
32
+ standard: 'medium'
33
+ };
34
+ const InnerTable = /*#__PURE__*/ (0, _react.forwardRef)(function InnerTable({ density , width , ...otherProps }, ref) {
35
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledMuiTable, {
36
+ ...otherProps,
37
+ tabIndex: -1,
38
+ size: TABLE_DENSITY_CONFIG[density],
39
+ ref: ref,
40
+ sx: {
41
+ width: width
42
+ }
43
+ });
44
+ });
@@ -0,0 +1,102 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "Table", {
18
+ enumerable: true,
19
+ get: ()=>Table
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _reactTable = require("@tanstack/react-table");
23
+ const _material = require("@mui/material");
24
+ const _react = require("react");
25
+ const _virtualizedTable = require("./VirtualizedTable");
26
+ const _tableCheckbox = require("./TableCheckbox");
27
+ const _tableModel = require("./model/table-model");
28
+ const DEFAULT_GET_ROW_ID = (data, index)=>{
29
+ return `${index}`;
30
+ };
31
+ function Table({ data , columns , density ='standard' , checkboxSelection , onRowSelectionChange , getCheckboxColor , getRowId =DEFAULT_GET_ROW_ID , rowSelection ={} , ...otherProps }) {
32
+ const theme = (0, _material.useTheme)();
33
+ const handleRowSelectionChange = (rowSelectionUpdater)=>{
34
+ const newRowSelection = typeof rowSelectionUpdater === 'function' ? rowSelectionUpdater(rowSelection) : rowSelectionUpdater;
35
+ onRowSelectionChange === null || onRowSelectionChange === void 0 ? void 0 : onRowSelectionChange(newRowSelection);
36
+ };
37
+ const checkboxColumn = (0, _react.useMemo)(()=>{
38
+ return {
39
+ id: 'checkboxRowSelect',
40
+ size: 32,
41
+ header: ({ table })=>{
42
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCheckbox.TableCheckbox, {
43
+ checked: table.getIsAllRowsSelected(),
44
+ indeterminate: table.getIsSomeRowsSelected(),
45
+ onChange: table.getToggleAllRowsSelectedHandler(),
46
+ color: theme.palette.text.primary,
47
+ density: density
48
+ });
49
+ },
50
+ cell: ({ row })=>{
51
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_tableCheckbox.TableCheckbox, {
52
+ checked: row.getIsSelected(),
53
+ indeterminate: row.getIsSomeSelected(),
54
+ onChange: (e)=>{
55
+ row.getToggleSelectedHandler()(e);
56
+ },
57
+ color: getCheckboxColor === null || getCheckboxColor === void 0 ? void 0 : getCheckboxColor(row.original),
58
+ density: density
59
+ });
60
+ }
61
+ };
62
+ }, [
63
+ density,
64
+ getCheckboxColor,
65
+ theme.palette.text.primary
66
+ ]);
67
+ const tableColumns = (0, _react.useMemo)(()=>{
68
+ const initTableColumns = (0, _tableModel.persesColumnsToTanstackColumns)(columns);
69
+ if (checkboxSelection) {
70
+ initTableColumns.unshift(checkboxColumn);
71
+ }
72
+ return initTableColumns;
73
+ }, [
74
+ checkboxColumn,
75
+ checkboxSelection,
76
+ columns
77
+ ]);
78
+ const table = (0, _reactTable.useReactTable)({
79
+ data,
80
+ columns: tableColumns,
81
+ getRowId,
82
+ getCoreRowModel: (0, _reactTable.getCoreRowModel)(),
83
+ enableRowSelection: !!checkboxSelection,
84
+ onRowSelectionChange: handleRowSelectionChange,
85
+ state: {
86
+ rowSelection
87
+ }
88
+ });
89
+ const handleRowClick = (0, _react.useCallback)((rowId)=>{
90
+ table.getRow(rowId).toggleSelected();
91
+ }, [
92
+ table
93
+ ]);
94
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_virtualizedTable.VirtualizedTable, {
95
+ ...otherProps,
96
+ density: density,
97
+ onRowClick: handleRowClick,
98
+ rows: table.getRowModel().rows,
99
+ columns: table.getAllFlatColumns(),
100
+ headers: table.getHeaderGroups()
101
+ });
102
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TableBody", {
18
+ enumerable: true,
19
+ get: ()=>TableBody
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = require("react");
24
+ const TableBody = /*#__PURE__*/ (0, _react.forwardRef)(function TableBody(props, ref) {
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableBody, {
26
+ ...props,
27
+ ref: ref
28
+ });
29
+ });
@@ -0,0 +1,97 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TableCell", {
18
+ enumerable: true,
19
+ get: ()=>TableCell
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = require("react");
24
+ const _tableModel = require("./model/table-model");
25
+ const StyledMuiTableCell = (0, _material.styled)(_material.TableCell)(({ theme })=>({
26
+ padding: 0,
27
+ backgroundColor: 'inherit',
28
+ '&.MuiTableCell-head': {
29
+ // Important to avoid scrolling behind the header showing through.
30
+ backgroundColor: theme.palette.background.paper
31
+ },
32
+ '&:focus-visible': {
33
+ outline: `solid 1px ${theme.palette.primary.main}`,
34
+ // Move inward a little to avoid getting cut off when focusing on items
35
+ // at the edge of the table.
36
+ outlineOffset: '-1px',
37
+ borderRadius: 0
38
+ }
39
+ }));
40
+ function TableCell({ children , density , variant , width , focusState ='none' , onFocusTrigger , ...otherProps }) {
41
+ const theme = (0, _material.useTheme)();
42
+ const elRef = (0, _react.useRef)();
43
+ const isHeader = variant === 'head';
44
+ (0, _react.useEffect)(()=>{
45
+ if (focusState === 'trigger-focus' && elRef.current) {
46
+ elRef.current.focus();
47
+ }
48
+ }, [
49
+ focusState
50
+ ]);
51
+ const handleFocus = (e)=>{
52
+ var ref;
53
+ // From https://zellwk.com/blog/keyboard-focusable-elements/
54
+ const nestedFocusTarget = (ref = e.currentTarget) === null || ref === void 0 ? void 0 : ref.querySelector('a[href], button, input, textarea, select, details');
55
+ if (nestedFocusTarget) {
56
+ // If the cell has a focusable child, focus it instead. Mostly used for
57
+ // checkbox cells, but could have other uses.
58
+ nestedFocusTarget.focus();
59
+ }
60
+ };
61
+ const handleInteractionFocusTrigger = (e)=>{
62
+ // We use `onClick` and `onKeyUp` events instead of `onFocus` because of
63
+ // some ordering issues with when the browser calls events and how this
64
+ // plays with the triggering of focus with keyboard interactions.
65
+ // These report that a focus event happened, so we can adjust the current
66
+ // tabindex and focuses to the right cell.
67
+ onFocusTrigger === null || onFocusTrigger === void 0 ? void 0 : onFocusTrigger(e);
68
+ };
69
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(StyledMuiTableCell, {
70
+ ...otherProps,
71
+ // Modify the tab index based on the currently focused cell. It's important
72
+ // to avoid having tabindex 0 on everything because it essentially traps
73
+ // a keyboard user in the table until they hit "tab" for every single
74
+ // cell.
75
+ tabIndex: focusState !== 'none' ? 0 : -1,
76
+ onFocus: handleFocus,
77
+ onClick: handleInteractionFocusTrigger,
78
+ onKeyUp: handleInteractionFocusTrigger,
79
+ sx: {
80
+ width: width,
81
+ borderBottom: isHeader ? (theme)=>`solid 1px ${theme.palette.grey[100]}` : `solid 1px ${theme.palette.grey[50]}`
82
+ },
83
+ ref: elRef,
84
+ children: /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Box, {
85
+ sx: {
86
+ ...(0, _tableModel.getTableCellLayout)(theme, density),
87
+ position: 'relative',
88
+ // Text truncation. Currently enforced on all cells. We may control
89
+ // this with a prop on column config in the future.
90
+ whiteSpace: 'nowrap',
91
+ overflow: 'hidden',
92
+ textOverflow: 'ellipsis'
93
+ },
94
+ children: children
95
+ })
96
+ });
97
+ }
@@ -0,0 +1,55 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TableCheckbox", {
18
+ enumerable: true,
19
+ get: ()=>TableCheckbox
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ function TableCheckbox({ color , density , ...otherProps }) {
24
+ const isCompact = density === 'compact';
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.Checkbox, {
26
+ size: isCompact ? 'small' : 'medium',
27
+ ...otherProps,
28
+ // Disable ripple and set background color below because of some issues
29
+ // with re-rendering with the keyboard interactions that causes the ripple
30
+ // animation to stutter.
31
+ focusRipple: false,
32
+ // Tab index is handled by the overall keyboard interactions for the table
33
+ // to avoid trapping a keyboard user in a table by requiring them to tab
34
+ // through every single checkbox.
35
+ tabIndex: -1,
36
+ sx: {
37
+ color: color,
38
+ padding: (theme)=>theme.spacing(isCompact ? 0.25 : 0.5),
39
+ // Centering.
40
+ position: 'absolute',
41
+ top: '50%',
42
+ left: '50%',
43
+ transform: 'translate(-50%, -50%)',
44
+ '&.Mui-checked': {
45
+ color: color
46
+ },
47
+ '&.Mui-focusVisible': {
48
+ background: color ? (0, _material.alpha)(color, 0.5) : undefined
49
+ },
50
+ '& .MuiSvgIcon-root': {
51
+ fontSize: isCompact ? 14 : 16
52
+ }
53
+ }
54
+ });
55
+ }
@@ -0,0 +1,29 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TableHead", {
18
+ enumerable: true,
19
+ get: ()=>TableHead
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = require("react");
24
+ const TableHead = /*#__PURE__*/ (0, _react.forwardRef)(function TableHead(props, ref) {
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableHead, {
26
+ ...props,
27
+ ref: ref
28
+ });
29
+ });
@@ -0,0 +1,35 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ Object.defineProperty(exports, "TableRow", {
18
+ enumerable: true,
19
+ get: ()=>TableRow
20
+ });
21
+ const _jsxRuntime = require("react/jsx-runtime");
22
+ const _material = require("@mui/material");
23
+ const _react = require("react");
24
+ const TableRow = /*#__PURE__*/ (0, _react.forwardRef)(function TableRow(props, ref) {
25
+ return /*#__PURE__*/ (0, _jsxRuntime.jsx)(_material.TableRow, {
26
+ ...props,
27
+ ref: ref,
28
+ sx: {
29
+ backgroundColor: (theme)=>theme.palette.background.paper,
30
+ '&:hover': {
31
+ backgroundColor: (theme)=>theme.palette.primary.light
32
+ }
33
+ }
34
+ });
35
+ });