@gridsuite/commons-ui 0.46.0 → 0.47.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 (183) hide show
  1. package/README.md +0 -17
  2. package/dist/components/AuthenticationRouter/AuthenticationRouter.js +147 -0
  3. package/dist/components/CardErrorBoundary/card-error-boundary.js +110 -0
  4. package/dist/components/ElementSearchDialog/element-search-dialog.js +139 -0
  5. package/dist/components/ElementSearchDialog/equipment-item.js +77 -0
  6. package/dist/components/ElementSearchDialog/tag-renderer.js +34 -0
  7. package/dist/components/FlatParameters/FlatParameters.js +411 -0
  8. package/dist/components/Login/Login.js +78 -0
  9. package/dist/components/Login/Logout.js +69 -0
  10. package/dist/components/MuiVirtualizedTable/ColumnHeader.js +127 -0
  11. package/dist/components/MuiVirtualizedTable/KeyedColumnsRowIndexer.js +548 -0
  12. package/dist/components/MuiVirtualizedTable/MuiVirtualizedTable.js +790 -0
  13. package/dist/components/MultipleSelectionDialog/MultipleSelectionDialog.js +87 -0
  14. package/dist/components/OverflowableText/overflowable-text.js +87 -0
  15. package/dist/components/ReportViewer/filter-button.js +64 -0
  16. package/dist/components/ReportViewer/log-report-item.js +95 -0
  17. package/dist/components/ReportViewer/log-report.js +49 -0
  18. package/dist/components/ReportViewer/log-table.js +131 -0
  19. package/dist/components/ReportViewer/multi-select-list.js +40 -0
  20. package/dist/components/ReportViewer/report-item.js +112 -0
  21. package/dist/components/ReportViewer/report-tree-view-context.js +8 -0
  22. package/dist/components/ReportViewer/report-viewer.js +158 -0
  23. package/dist/components/ReportViewerDialog/report-viewer-dialog.js +61 -0
  24. package/dist/components/SignInCallbackHandler/SignInCallbackHandler.js +13 -0
  25. package/dist/components/SilentRenewCallbackHandler/SilentRenewCallbackHandler.js +16 -0
  26. package/dist/components/SnackbarProvider/SnackbarProvider.js +28 -0
  27. package/dist/components/TopBar/AboutDialog.js +467 -0
  28. package/dist/components/TopBar/GridLogo.js +71 -0
  29. package/dist/components/TopBar/TopBar.js +679 -0
  30. package/dist/components/TreeViewFinder/TreeViewFinder.js +288 -0
  31. package/dist/components/react-hook-form/autocomplete-input.js +96 -0
  32. package/dist/components/react-hook-form/booleans/boolean-input.js +49 -0
  33. package/dist/components/react-hook-form/booleans/checkbox-input.js +24 -0
  34. package/dist/components/react-hook-form/booleans/switch-input.js +24 -0
  35. package/dist/components/react-hook-form/error-management/error-input.js +42 -0
  36. package/dist/components/react-hook-form/error-management/field-error-alert.js +9 -0
  37. package/dist/components/react-hook-form/error-management/mid-form-error.js +20 -0
  38. package/dist/components/react-hook-form/numbers/float-input.js +51 -0
  39. package/dist/components/react-hook-form/numbers/integer-input.js +36 -0
  40. package/dist/components/react-hook-form/numbers/utils.js +10 -0
  41. package/dist/components/react-hook-form/radio-input.js +44 -0
  42. package/dist/components/react-hook-form/select-input.js +31 -0
  43. package/dist/components/react-hook-form/slider-input.js +43 -0
  44. package/dist/components/react-hook-form/text-input.js +94 -0
  45. package/dist/components/react-hook-form/utils/cancel-button.js +16 -0
  46. package/dist/components/react-hook-form/utils/field-label.js +12 -0
  47. package/dist/components/react-hook-form/utils/functions.js +36 -0
  48. package/dist/components/react-hook-form/utils/submit-button.js +23 -0
  49. package/dist/components/react-hook-form/utils/text-field-with-adornment.js +96 -0
  50. package/dist/components/translations/card-error-boundary-en.js +8 -0
  51. package/dist/components/translations/card-error-boundary-fr.js +8 -0
  52. package/dist/components/translations/common-button-en.js +7 -0
  53. package/dist/components/translations/common-button-fr.js +7 -0
  54. package/dist/components/translations/element-search-en.js +7 -0
  55. package/dist/components/translations/element-search-fr.js +7 -0
  56. package/dist/components/translations/equipment-search-en.js +21 -0
  57. package/dist/components/translations/equipment-search-fr.js +21 -0
  58. package/dist/components/translations/flat-parameters-en.js +8 -0
  59. package/dist/components/translations/flat-parameters-fr.js +8 -0
  60. package/dist/components/translations/login-en.js +14 -0
  61. package/dist/components/translations/login-fr.js +14 -0
  62. package/dist/components/translations/multiple-selection-dialog-en.js +8 -0
  63. package/dist/components/translations/multiple-selection-dialog-fr.js +8 -0
  64. package/dist/components/translations/report-viewer-en.js +8 -0
  65. package/dist/components/translations/report-viewer-fr.js +8 -0
  66. package/dist/components/translations/table-en.js +6 -0
  67. package/dist/components/translations/table-fr.js +6 -0
  68. package/dist/components/translations/top-bar-en.js +27 -0
  69. package/dist/components/translations/top-bar-fr.js +27 -0
  70. package/dist/components/translations/treeview-finder-en.js +12 -0
  71. package/dist/components/translations/treeview-finder-fr.js +12 -0
  72. package/dist/hooks/useDebounce.js +17 -0
  73. package/{es/components/ElementSearchDialog/index.js → dist/hooks/useIntlRef.d.ts} +2 -2
  74. package/dist/hooks/useIntlRef.js +13 -0
  75. package/dist/hooks/useSnackMessage.js +81 -0
  76. package/dist/index.d.ts +225 -0
  77. package/dist/index.js +154 -0
  78. package/dist/utils/AuthService.js +336 -0
  79. package/dist/utils/ElementType.js +38 -0
  80. package/dist/utils/EquipmentType.js +132 -0
  81. package/dist/utils/UserManagerMock.js +85 -0
  82. package/dist/utils/actions.js +71 -0
  83. package/dist/utils/algos.js +24 -0
  84. package/dist/utils/styles.js +13 -0
  85. package/package.json +36 -21
  86. package/es/components/AuthenticationRouter/AuthenticationRouter.js +0 -102
  87. package/es/components/AuthenticationRouter/index.js +0 -7
  88. package/es/components/CardErrorBoundary/card-error-boundary.js +0 -138
  89. package/es/components/CardErrorBoundary/index.js +0 -7
  90. package/es/components/ElementSearchDialog/element-search-dialog.js +0 -153
  91. package/es/components/ElementSearchDialog/equipment-item.js +0 -63
  92. package/es/components/ElementSearchDialog/tag-renderer.js +0 -29
  93. package/es/components/FlatParameters/FlatParameters.js +0 -448
  94. package/es/components/FlatParameters/index.js +0 -8
  95. package/es/components/Login/Login.js +0 -79
  96. package/es/components/Login/Logout.js +0 -78
  97. package/es/components/Login/index.js +0 -7
  98. package/es/components/MuiVirtualizedTable/ColumnHeader.js +0 -125
  99. package/es/components/MuiVirtualizedTable/KeyedColumnsRowIndexer.js +0 -619
  100. package/es/components/MuiVirtualizedTable/MuiVirtualizedTable.js +0 -780
  101. package/es/components/MuiVirtualizedTable/index.js +0 -9
  102. package/es/components/MultipleSelectionDialog/MultipleSelectionDialog.js +0 -95
  103. package/es/components/MultipleSelectionDialog/index.js +0 -8
  104. package/es/components/OverflowableText/index.js +0 -7
  105. package/es/components/OverflowableText/overflowable-text.js +0 -81
  106. package/es/components/ReportViewer/filter-button.js +0 -77
  107. package/es/components/ReportViewer/index.js +0 -7
  108. package/es/components/ReportViewer/log-report-item.js +0 -97
  109. package/es/components/ReportViewer/log-report.js +0 -63
  110. package/es/components/ReportViewer/log-table.js +0 -130
  111. package/es/components/ReportViewer/multi-select-list.js +0 -56
  112. package/es/components/ReportViewer/report-item.js +0 -131
  113. package/es/components/ReportViewer/report-tree-view-context.js +0 -13
  114. package/es/components/ReportViewer/report-viewer.js +0 -167
  115. package/es/components/ReportViewerDialog/index.js +0 -7
  116. package/es/components/ReportViewerDialog/report-viewer-dialog.js +0 -67
  117. package/es/components/SignInCallbackHandler/SignInCallbackHandler.js +0 -19
  118. package/es/components/SignInCallbackHandler/index.js +0 -7
  119. package/es/components/SilentRenewCallbackHandler/SilentRenewCallbackHandler.js +0 -19
  120. package/es/components/SilentRenewCallbackHandler/index.js +0 -7
  121. package/es/components/SnackbarProvider/SnackbarProvider.js +0 -39
  122. package/es/components/SnackbarProvider/index.js +0 -7
  123. package/es/components/TopBar/AboutDialog.js +0 -456
  124. package/es/components/TopBar/GridLogo.js +0 -73
  125. package/es/components/TopBar/TopBar.js +0 -487
  126. package/es/components/TopBar/index.js +0 -9
  127. package/es/components/TreeViewFinder/TreeViewFinder.js +0 -341
  128. package/es/components/TreeViewFinder/index.js +0 -7
  129. package/es/components/images/powsybl_logo.svg +0 -35
  130. package/es/components/react-hook-form/autocomplete-input.js +0 -110
  131. package/es/components/react-hook-form/booleans/boolean-input.js +0 -56
  132. package/es/components/react-hook-form/booleans/checkbox-input.js +0 -28
  133. package/es/components/react-hook-form/booleans/switch-input.js +0 -28
  134. package/es/components/react-hook-form/error-management/error-input.js +0 -50
  135. package/es/components/react-hook-form/error-management/field-error-alert.js +0 -22
  136. package/es/components/react-hook-form/error-management/mid-form-error.js +0 -25
  137. package/es/components/react-hook-form/numbers/float-input.js +0 -105
  138. package/es/components/react-hook-form/numbers/integer-input.js +0 -35
  139. package/es/components/react-hook-form/numbers/utils.js +0 -6
  140. package/es/components/react-hook-form/radio-input.js +0 -55
  141. package/es/components/react-hook-form/select-input.js +0 -40
  142. package/es/components/react-hook-form/slider-input.js +0 -48
  143. package/es/components/react-hook-form/text-input.js +0 -100
  144. package/es/components/react-hook-form/utils/cancel-button.js +0 -28
  145. package/es/components/react-hook-form/utils/field-label.js +0 -15
  146. package/es/components/react-hook-form/utils/functions.js +0 -42
  147. package/es/components/react-hook-form/utils/submit-button.js +0 -29
  148. package/es/components/react-hook-form/utils/text-field-with-adornment.js +0 -92
  149. package/es/components/translations/card-error-boundary-en.js +0 -13
  150. package/es/components/translations/card-error-boundary-fr.js +0 -13
  151. package/es/components/translations/common-button-en.js +0 -12
  152. package/es/components/translations/common-button-fr.js +0 -12
  153. package/es/components/translations/element-search-en.js +0 -12
  154. package/es/components/translations/element-search-fr.js +0 -12
  155. package/es/components/translations/equipment-search-en.js +0 -26
  156. package/es/components/translations/equipment-search-fr.js +0 -26
  157. package/es/components/translations/flat-parameters-en.js +0 -13
  158. package/es/components/translations/flat-parameters-fr.js +0 -13
  159. package/es/components/translations/inputs-en.js +0 -25
  160. package/es/components/translations/inputs-fr.js +0 -25
  161. package/es/components/translations/login-en.js +0 -19
  162. package/es/components/translations/login-fr.js +0 -19
  163. package/es/components/translations/multiple-selection-dialog-en.js +0 -13
  164. package/es/components/translations/multiple-selection-dialog-fr.js +0 -13
  165. package/es/components/translations/report-viewer-en.js +0 -13
  166. package/es/components/translations/report-viewer-fr.js +0 -13
  167. package/es/components/translations/table-en.js +0 -11
  168. package/es/components/translations/table-fr.js +0 -11
  169. package/es/components/translations/top-bar-en.js +0 -32
  170. package/es/components/translations/top-bar-fr.js +0 -32
  171. package/es/components/translations/treeview-finder-en.js +0 -17
  172. package/es/components/translations/treeview-finder-fr.js +0 -17
  173. package/es/hooks/useDebounce.js +0 -26
  174. package/es/hooks/useIntlRef.js +0 -22
  175. package/es/hooks/useSnackMessage.js +0 -81
  176. package/es/index.js +0 -71
  177. package/es/utils/AuthService.js +0 -312
  178. package/es/utils/ElementType.js +0 -53
  179. package/es/utils/EquipmentType.js +0 -133
  180. package/es/utils/UserManagerMock.js +0 -81
  181. package/es/utils/actions.js +0 -65
  182. package/es/utils/algos.js +0 -29
  183. package/es/utils/styles.js +0 -35
@@ -0,0 +1,790 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
+ var __publicField = (obj, key, value) => {
4
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
+ return value;
6
+ };
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ import React, { createRef } from "react";
9
+ import { FormattedMessage } from "react-intl";
10
+ import PropTypes from "prop-types";
11
+ import clsx from "clsx";
12
+ import memoize from "memoize-one";
13
+ import { TableCell, IconButton, Popover, Autocomplete, TextField, Chip } from "@mui/material";
14
+ import { styled } from "@mui/system";
15
+ import { GetApp } from "@mui/icons-material";
16
+ import { Table, Column, AutoSizer } from "react-virtualized";
17
+ import CsvDownloader from "react-csv-downloader";
18
+ import { OverflowableText } from "../OverflowableText/overflowable-text.js";
19
+ import { toNestedGlobalSelectors, makeComposeClasses } from "../../utils/styles.js";
20
+ import { getHelper, collectibleHelper, KeyedColumnsRowIndexer, CHANGE_WAYS } from "./KeyedColumnsRowIndexer.js";
21
+ import ColumnHeader from "./ColumnHeader.js";
22
+ function getTextWidth(text) {
23
+ let canvas = getTextWidth.canvas || (getTextWidth.canvas = document.createElement("canvas"));
24
+ let context = canvas.getContext("2d");
25
+ context.font = '14px "Roboto", "Helvetica", "Arial", sans-serif';
26
+ let metrics = context.measureText(text);
27
+ return metrics.width;
28
+ }
29
+ const DEFAULT_CELL_PADDING = 16;
30
+ const DEFAULT_HEADER_HEIGHT = 48;
31
+ const DEFAULT_ROW_HEIGHT = 48;
32
+ const cssFlexContainer = "flexContainer";
33
+ const cssTable = "table";
34
+ const cssTableRow = "tableRow";
35
+ const cssTableRowHover = "tableRowHover";
36
+ const cssTableCell = "tableCell";
37
+ const cssTableCellColor = "tableCellColor";
38
+ const cssNoClick = "noClick";
39
+ const cssHeader = "header";
40
+ const cssRowBackgroundDark = "rowBackgroundDark";
41
+ const cssRowBackgroundLight = "rowBackgroundLight";
42
+ const defaultStyles = {
43
+ [cssFlexContainer]: {
44
+ display: "flex",
45
+ alignItems: "center",
46
+ boxSizing: "border-box"
47
+ },
48
+ [cssTable]: {
49
+ // temporary right-to-left patch, waiting for
50
+ // https://github.com/bvaughn/react-virtualized/issues/454
51
+ "& .ReactVirtualized__Table__headerRow": {
52
+ flip: false
53
+ }
54
+ },
55
+ [cssTableRow]: {
56
+ cursor: "pointer"
57
+ },
58
+ [cssTableRowHover]: {},
59
+ [cssTableCell]: {
60
+ flex: 1,
61
+ padding: DEFAULT_CELL_PADDING + "px"
62
+ },
63
+ [cssTableCellColor]: {},
64
+ [cssNoClick]: {
65
+ cursor: "initial"
66
+ },
67
+ [cssHeader]: {
68
+ fontWeight: "bold"
69
+ },
70
+ [cssRowBackgroundDark]: {},
71
+ [cssRowBackgroundLight]: {}
72
+ };
73
+ const defaultTooltipSx = {
74
+ maxWidth: "1260px",
75
+ fontSize: "0.9rem"
76
+ };
77
+ const generateMuiVirtualizedTableClass = (className) => `MuiVirtualizedTable-${className}`;
78
+ const composeClasses = makeComposeClasses(generateMuiVirtualizedTableClass);
79
+ const AmongChooser = (props) => {
80
+ const { options, value, setValue, id, onDropDownVisibility } = props;
81
+ return /* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(
82
+ Autocomplete,
83
+ {
84
+ id,
85
+ value: value ?? [],
86
+ multiple: true,
87
+ onChange: (evt, newVal) => {
88
+ setValue(newVal);
89
+ },
90
+ onClose: () => onDropDownVisibility(false),
91
+ onOpen: () => onDropDownVisibility(true),
92
+ options,
93
+ renderInput: (props2) => /* @__PURE__ */ jsx(TextField, { autoFocus: true, ...props2 }),
94
+ renderTags: (val, getTagsProps) => {
95
+ return val.map((code, index) => {
96
+ return /* @__PURE__ */ jsx(
97
+ Chip,
98
+ {
99
+ id: "chip_" + code,
100
+ size: "small",
101
+ label: code,
102
+ ...getTagsProps({ index })
103
+ }
104
+ );
105
+ });
106
+ }
107
+ }
108
+ ) });
109
+ };
110
+ function makeIndexRecord(viewIndexToModel, rows) {
111
+ return {
112
+ viewIndexToModel,
113
+ rowGetter: !viewIndexToModel ? (viewIndex) => rows[viewIndex] : (viewIndex) => {
114
+ if (viewIndex >= viewIndexToModel.length || viewIndex < 0) {
115
+ return {};
116
+ }
117
+ const modelIndex = viewIndexToModel[viewIndex];
118
+ return rows[modelIndex];
119
+ }
120
+ };
121
+ }
122
+ const initIndexer = (props, oldProps, versionSetter) => {
123
+ if (!props.sortable) {
124
+ return null;
125
+ }
126
+ if (props.indexer) {
127
+ return props.indexer;
128
+ }
129
+ return new KeyedColumnsRowIndexer(true, true, null, versionSetter);
130
+ };
131
+ const preFilterData = memoize(
132
+ (columns, rows, filterFromProps, indexer, filterVersion) => {
133
+ return indexer.preFilterRowMapping(columns, rows, filterFromProps);
134
+ }
135
+ );
136
+ const reorderIndex = memoize(
137
+ (indexer, indirectionVersion, rows, columns, filterFromProps, sortFromProps) => {
138
+ if (!rows) {
139
+ return {
140
+ viewIndexToModel: [],
141
+ rowGetter: (viewIndex) => viewIndex
142
+ };
143
+ }
144
+ const highestCodedColumn = !indexer ? 0 : indexer.highestCodedColumn(columns);
145
+ if (sortFromProps && highestCodedColumn) {
146
+ const colIdx = Math.abs(highestCodedColumn) - 1;
147
+ let reorderedIndex = sortFromProps(
148
+ columns[colIdx].dataKey,
149
+ highestCodedColumn > 0,
150
+ !!columns[colIdx].numeric
151
+ );
152
+ return makeIndexRecord(reorderedIndex, rows);
153
+ }
154
+ if (sortFromProps) {
155
+ try {
156
+ const viewIndexToModel = sortFromProps(null, false, false);
157
+ return makeIndexRecord(viewIndexToModel, rows);
158
+ } catch (e) {
159
+ console.warn(
160
+ "error in external sort. consider adding support for datakey=null in your external sort function"
161
+ );
162
+ }
163
+ }
164
+ if (indexer) {
165
+ const prefiltered = preFilterData(
166
+ columns,
167
+ rows,
168
+ filterFromProps,
169
+ indexer,
170
+ indirectionVersion
171
+ );
172
+ const reorderedIndex = indexer.makeGroupAndSortIndirector(
173
+ prefiltered,
174
+ columns
175
+ );
176
+ return makeIndexRecord(reorderedIndex, rows);
177
+ }
178
+ if (filterFromProps) {
179
+ const viewIndexToModel = rows.map((r, i) => [r, i]).filter(([r, idx]) => filterFromProps(r)).map(([r, j]) => j);
180
+ return makeIndexRecord(viewIndexToModel, rows);
181
+ }
182
+ return makeIndexRecord(null, rows);
183
+ }
184
+ );
185
+ class MuiVirtualizedTable extends React.PureComponent {
186
+ constructor(props, context) {
187
+ super(props, context);
188
+ __publicField(this, "setVersion", (v) => {
189
+ this.setState({ indirectionVersion: v });
190
+ });
191
+ __publicField(this, "computeDataWidth", (text) => {
192
+ return getTextWidth(text || "") + 2 * DEFAULT_CELL_PADDING;
193
+ });
194
+ __publicField(this, "sizes", memoize((columns, rows, rowGetter) => {
195
+ let sizes = {};
196
+ columns.forEach((col) => {
197
+ if (col.width) {
198
+ sizes[col.dataKey] = col.width;
199
+ } else {
200
+ let size = Math.max(
201
+ col.minWidth || 0,
202
+ this.computeDataWidth(col.label)
203
+ );
204
+ for (let i = 0; i < rows.length; ++i) {
205
+ const gotRow = rowGetter(i);
206
+ let text = this.getDisplayValue(col, gotRow[col.dataKey]);
207
+ size = Math.max(size, this.computeDataWidth(text));
208
+ }
209
+ if (col.maxWidth) {
210
+ size = Math.min(col.maxWidth, size);
211
+ }
212
+ sizes[col.dataKey] = Math.ceil(size);
213
+ }
214
+ });
215
+ return sizes;
216
+ }));
217
+ __publicField(this, "openPopover", (popoverTarget, colKey) => {
218
+ const col = this.props.columns.find((c) => c.dataKey === colKey);
219
+ if (getHelper(col) !== collectibleHelper) {
220
+ return;
221
+ }
222
+ this.dropDownVisible = false;
223
+ this.setState({
224
+ popoverAnchorEl: popoverTarget,
225
+ popoverColKey: colKey
226
+ });
227
+ });
228
+ __publicField(this, "handleKeyDownOnPopover", (evt) => {
229
+ if (evt.key === "Enter" && !this.dropDownVisible) {
230
+ this.closePopover(evt, "enterKeyDown");
231
+ }
232
+ });
233
+ __publicField(this, "closePopover", (evt, reason) => {
234
+ let bumpsVersion = false;
235
+ if (reason === "backdropClick" || reason === "enterKeyDown") {
236
+ bumpsVersion = this._commitFilterChange();
237
+ }
238
+ this.setState((state, props) => {
239
+ return {
240
+ popoverAnchorEl: null,
241
+ popoverColKey: null,
242
+ deferredFilterChange: null,
243
+ indirectionVersion: state.indirectionVersion + (bumpsVersion ? 1 : 0)
244
+ };
245
+ });
246
+ });
247
+ __publicField(this, "makeColumnFilterEditor", () => {
248
+ var _a;
249
+ const colKey = this.state.popoverColKey;
250
+ const outerParams = this.state.indexer.getColFilterOuterParams(colKey);
251
+ const userParams = !this.props.defersFilterChanges || !this.state.deferredFilterChange ? this.state.indexer.getColFilterUserParams(colKey) : this.state.deferredFilterChange.newVal;
252
+ const prefiltered = preFilterData(
253
+ this.props.columns,
254
+ this.props.rows,
255
+ this.props.filter,
256
+ this.state.indexer,
257
+ this.state.indirectionVersion
258
+ );
259
+ let options = [];
260
+ if (outerParams) {
261
+ options.push(...outerParams);
262
+ }
263
+ const colStat = (_a = prefiltered == null ? void 0 : prefiltered.colsStats) == null ? void 0 : _a[colKey];
264
+ if (colStat == null ? void 0 : colStat.seen) {
265
+ for (const key of Object.getOwnPropertyNames(colStat.seen)) {
266
+ if (options.findIndex((o) => o === key) < 0) {
267
+ options.push(key);
268
+ }
269
+ }
270
+ }
271
+ options.sort();
272
+ const col = this.props.columns.find((c) => c.dataKey === colKey);
273
+ return /* @__PURE__ */ jsx(
274
+ AmongChooser,
275
+ {
276
+ options,
277
+ value: userParams,
278
+ id: "fielt" + colKey,
279
+ label: (col == null ? void 0 : col.label) ?? "∈",
280
+ setValue: (newVal) => {
281
+ this.onFilterParamsChange(newVal, colKey);
282
+ },
283
+ onDropDownVisibility: (visible) => this.dropDownVisible = visible
284
+ }
285
+ );
286
+ });
287
+ __publicField(this, "_commitFilterChange", () => {
288
+ if (this.state.deferredFilterChange) {
289
+ const colKey = this.state.deferredFilterChange.colKey;
290
+ let newVal = this.state.deferredFilterChange.newVal;
291
+ if ((newVal == null ? void 0 : newVal.length) === 0) {
292
+ newVal = null;
293
+ }
294
+ if (this.state.indexer.setColFilterUserParams(colKey, newVal)) {
295
+ return true;
296
+ }
297
+ }
298
+ return false;
299
+ });
300
+ __publicField(this, "sortClickHandler", (evt, name, columnIndex) => {
301
+ const colKey = this.props.columns[columnIndex].dataKey;
302
+ if (evt.altKey) {
303
+ this.openPopover(evt.target, colKey);
304
+ return;
305
+ }
306
+ let way = CHANGE_WAYS.SIMPLE;
307
+ if (evt.ctrlKey && evt.shiftKey) {
308
+ way = CHANGE_WAYS.AMEND;
309
+ } else if (evt.ctrlKey) {
310
+ way = CHANGE_WAYS.REMOVE;
311
+ } else if (evt.shiftKey) {
312
+ way = CHANGE_WAYS.TAIL;
313
+ }
314
+ if (this.state.indexer.updateSortingFromUser(colKey, way)) {
315
+ this.setState({
316
+ indirectionVersion: this.state.indirectionVersion + 1
317
+ });
318
+ }
319
+ });
320
+ __publicField(this, "filterClickHandler", (evt, target, columnIndex) => {
321
+ const retargeted = target.parentNode ?? target;
322
+ const colKey = this.props.columns[columnIndex].dataKey;
323
+ this.openPopover(retargeted, colKey);
324
+ });
325
+ __publicField(this, "sortableHeader", ({ label, columnIndex }) => {
326
+ var _a;
327
+ const { columns } = this.props;
328
+ const indexer = this.state.indexer;
329
+ const colKey = columns[columnIndex].dataKey;
330
+ const signedRank = indexer.columnSortingSignedRank(colKey);
331
+ const userParams = indexer.getColFilterUserParams(colKey);
332
+ const numeric = columns[columnIndex].numeric;
333
+ const prefiltered = preFilterData(
334
+ columns,
335
+ this.props.rows,
336
+ this.props.filter,
337
+ indexer,
338
+ indexer.filterVersion
339
+ );
340
+ const colStat = (_a = prefiltered == null ? void 0 : prefiltered.colsStats) == null ? void 0 : _a[colKey];
341
+ let filterLevel = 0;
342
+ if (userParams == null ? void 0 : userParams.length) {
343
+ filterLevel += 1;
344
+ if (!(colStat == null ? void 0 : colStat.seen)) {
345
+ filterLevel += 2;
346
+ } else if (userParams.filter((v) => !colStat.seen[v]).length) {
347
+ filterLevel += 2;
348
+ }
349
+ }
350
+ const onFilterClick = numeric || this.props.sort || columns[columnIndex].cellRenderer ? void 0 : (ev, retargeted) => {
351
+ this.filterClickHandler(ev, retargeted, columnIndex);
352
+ };
353
+ return /* @__PURE__ */ jsx(
354
+ ColumnHeader,
355
+ {
356
+ label,
357
+ ref: (e) => this._registerHeader(label, e),
358
+ sortSignedRank: signedRank,
359
+ filterLevel,
360
+ numeric,
361
+ onSortClick: (ev, name) => {
362
+ this.sortClickHandler(ev, name, columnIndex);
363
+ },
364
+ onFilterClick
365
+ }
366
+ );
367
+ });
368
+ __publicField(this, "simpleHeaderRenderer", ({ label }) => {
369
+ return /* @__PURE__ */ jsx(
370
+ "div",
371
+ {
372
+ ref: (element) => {
373
+ this._registerHeader(label, element);
374
+ },
375
+ children: label
376
+ }
377
+ );
378
+ });
379
+ __publicField(this, "getRowClassName", ({ index, rowGetter }) => {
380
+ var _a;
381
+ const { classes, onRowClick } = this.props;
382
+ return clsx(
383
+ composeClasses(classes, cssTableRow),
384
+ composeClasses(classes, cssFlexContainer),
385
+ index % 2 === 0 && composeClasses(classes, cssRowBackgroundDark),
386
+ index % 2 !== 0 && composeClasses(classes, cssRowBackgroundLight),
387
+ ((_a = rowGetter(index)) == null ? void 0 : _a.notClickable) === true && composeClasses(classes, cssNoClick),
388
+ // Allow to define a row as not clickable
389
+ {
390
+ [composeClasses(classes, cssTableRowHover)]: index !== -1 && onRowClick != null
391
+ }
392
+ );
393
+ });
394
+ __publicField(this, "onClickableRowClick", (event) => {
395
+ var _a;
396
+ if (!(((_a = event.rowData) == null ? void 0 : _a.notClickable) === true)) {
397
+ this.props.onRowClick(event);
398
+ }
399
+ });
400
+ __publicField(this, "cellRenderer", ({ cellData, columnIndex, rowIndex }) => {
401
+ var _a, _b;
402
+ const { columns, classes, rowHeight, onCellClick, rows, tooltipSx } = this.props;
403
+ let displayedValue = this.getDisplayValue(
404
+ columns[columnIndex],
405
+ cellData
406
+ );
407
+ return /* @__PURE__ */ jsx(
408
+ TableCell,
409
+ {
410
+ component: "div",
411
+ className: clsx(
412
+ composeClasses(classes, cssTableCell),
413
+ composeClasses(classes, cssFlexContainer),
414
+ {
415
+ [composeClasses(classes, cssNoClick)]: displayedValue === void 0 || ((_a = rows[rowIndex]) == null ? void 0 : _a.notClickable) === true || onCellClick == null || columns[columnIndex].clickable === void 0 || !columns[columnIndex].clickable,
416
+ [composeClasses(classes, cssTableCellColor)]: displayedValue === void 0 || onCellClick !== null && !((_b = rows[rowIndex]) == null ? void 0 : _b.notClickable) === true && columns[columnIndex].clickable !== void 0 && columns[columnIndex].clickable
417
+ }
418
+ ),
419
+ variant: "body",
420
+ style: { height: rowHeight, width: "100%" },
421
+ align: columnIndex != null && columns[columnIndex].numeric || false ? "right" : "left",
422
+ onClick: () => {
423
+ var _a2;
424
+ if (onCellClick && columns[columnIndex].clickable !== void 0 && !((_a2 = rows[rowIndex]) == null ? void 0 : _a2.notClickable) === true && columns[columnIndex].clickable) {
425
+ onCellClick(rows[rowIndex], columns[columnIndex]);
426
+ }
427
+ },
428
+ children: /* @__PURE__ */ jsx(
429
+ OverflowableText,
430
+ {
431
+ text: displayedValue,
432
+ tooltipStyle: classes.cellTooltip,
433
+ tooltipSx: { ...defaultTooltipSx, ...tooltipSx }
434
+ }
435
+ )
436
+ }
437
+ );
438
+ });
439
+ __publicField(this, "makeSizedTable", (height, width, sizes, reorderedIndex, rowGetter) => {
440
+ const { sort, ...otherProps } = this.props;
441
+ return /* @__PURE__ */ jsx(
442
+ Table,
443
+ {
444
+ ...otherProps,
445
+ height,
446
+ width,
447
+ rowHeight: otherProps.rowHeight,
448
+ gridStyle: { direction: "inherit" },
449
+ headerHeight: this.state.headerHeight,
450
+ className: composeClasses(otherProps.classes, cssTable),
451
+ onRowClick: this.props.onRowClick && /* The {...otherProps} just above would hold the slot onRowClick */
452
+ this.onClickableRowClick,
453
+ rowCount: (reorderedIndex == null ? void 0 : reorderedIndex.length) ?? otherProps.rows.length,
454
+ rowClassName: ({ index }) => this.getRowClassName({ index, rowGetter }),
455
+ rowGetter: ({ index }) => rowGetter(index),
456
+ children: otherProps.columns.map(({ dataKey, ...other }, index) => {
457
+ return /* @__PURE__ */ jsx(
458
+ Column,
459
+ {
460
+ headerRenderer: this.makeHeaderRenderer(
461
+ dataKey,
462
+ index
463
+ ),
464
+ className: composeClasses(
465
+ otherProps.classes,
466
+ cssFlexContainer
467
+ ),
468
+ cellRenderer: this.cellRenderer,
469
+ dataKey,
470
+ flexGrow: 1,
471
+ width: sizes[dataKey],
472
+ ...other
473
+ },
474
+ dataKey
475
+ );
476
+ })
477
+ }
478
+ );
479
+ });
480
+ __publicField(this, "getCSVFilename", () => {
481
+ var _a;
482
+ if (((_a = this.props.name) == null ? void 0 : _a.length) > 0) {
483
+ return this.props.name.replace(/\s/g, "_");
484
+ } else {
485
+ let filename = Object.entries(this.props.columns).map((p) => p[1].label).join("_");
486
+ return filename;
487
+ }
488
+ });
489
+ __publicField(this, "getCSVData", () => {
490
+ var _a;
491
+ let reorderedIndex = reorderIndex(
492
+ this.state.indexer,
493
+ this.state.indirectionVersion,
494
+ this.props.rows,
495
+ this.props.columns,
496
+ this.props.filter,
497
+ this.props.sort
498
+ );
499
+ let rowsCount = ((_a = reorderedIndex.viewIndexToModel) == null ? void 0 : _a.length) ?? this.props.rows.length;
500
+ const csvData = [];
501
+ for (let index = 0; index < rowsCount; ++index) {
502
+ const myobj = {};
503
+ const sortedRow = reorderedIndex.rowGetter(index);
504
+ const exportedKeys = this.props.exportCSVDataKeys;
505
+ this.props.columns.forEach((col) => {
506
+ if (exportedKeys == null ? void 0 : exportedKeys.find((el) => el === col.dataKey)) {
507
+ myobj[col.dataKey] = sortedRow[col.dataKey];
508
+ }
509
+ });
510
+ csvData.push(myobj);
511
+ }
512
+ return Promise.resolve(csvData);
513
+ });
514
+ __publicField(this, "csvHeaders", memoize((columns, exportCSVDataKeys) => {
515
+ let tempHeaders = [];
516
+ columns.forEach((col) => {
517
+ if (exportCSVDataKeys !== void 0 && exportCSVDataKeys.find((el) => el === col.dataKey)) {
518
+ tempHeaders.push({
519
+ displayName: col.label,
520
+ id: col.dataKey
521
+ });
522
+ }
523
+ });
524
+ return tempHeaders;
525
+ }));
526
+ this._computeHeaderSize = this._computeHeaderSize.bind(this);
527
+ this._registerHeader = this._registerHeader.bind(this);
528
+ this._registerObserver = this._registerObserver.bind(this);
529
+ this.headers = createRef();
530
+ this.headers.current = {};
531
+ let options = {
532
+ root: null,
533
+ rootMargin: "0px",
534
+ threshold: 0.1
535
+ };
536
+ this.observer = new IntersectionObserver(
537
+ this._computeHeaderSize,
538
+ options
539
+ );
540
+ this.state = {
541
+ headerHeight: this.props.headerHeight,
542
+ indexer: initIndexer(props, null, this.setVersion),
543
+ indirectionVersion: 0,
544
+ popoverAnchorEl: null,
545
+ popoverColKey: null,
546
+ deferredFilterChange: null
547
+ };
548
+ }
549
+ componentDidUpdate(oldProps) {
550
+ if (oldProps.indexer !== this.props.indexer || oldProps.sortable !== this.props.sortable) {
551
+ this.setState((state) => {
552
+ return {
553
+ indexer: initIndexer(this.props, oldProps, this.setVersion),
554
+ indirectionVersion: ((state == null ? void 0 : state.indirectionVersion) ?? 0) + 1
555
+ };
556
+ });
557
+ }
558
+ if (oldProps.headerHeight !== this.props.headerHeight) {
559
+ this._computeHeaderSize();
560
+ }
561
+ }
562
+ componentDidMount() {
563
+ window.addEventListener("resize", this._computeHeaderSize);
564
+ }
565
+ componentWillUnmount() {
566
+ window.removeEventListener("resize", this._computeHeaderSize);
567
+ this.observer.disconnect();
568
+ }
569
+ _registerHeader(label, header) {
570
+ if (header !== null) {
571
+ this.headers.current[label] = header;
572
+ }
573
+ }
574
+ _registerObserver(element) {
575
+ if (element !== null) {
576
+ this.observer.observe(element);
577
+ }
578
+ }
579
+ onFilterParamsChange(newVal, colKey) {
580
+ const nonEmpty = newVal.length === 0 ? null : newVal;
581
+ if (this.props.defersFilterChanges) {
582
+ this.setState({
583
+ deferredFilterChange: { newVal, colKey }
584
+ });
585
+ } else if (this.state.indexer.setColFilterUserParams(colKey, nonEmpty)) {
586
+ this.setState({
587
+ indirectionVersion: this.state.indirectionVersion + 1
588
+ });
589
+ }
590
+ }
591
+ getDisplayValue(column, cellData) {
592
+ let displayedValue;
593
+ if (!column.numeric) {
594
+ displayedValue = cellData;
595
+ } else if (isNaN(cellData)) {
596
+ displayedValue = "";
597
+ } else if (column.fractionDigits === void 0 || column.fractionDigits === 0) {
598
+ displayedValue = Math.round(cellData);
599
+ } else {
600
+ displayedValue = Number(cellData).toFixed(column.fractionDigits);
601
+ }
602
+ if (column.unit !== void 0) {
603
+ displayedValue += " ";
604
+ displayedValue += column.unit;
605
+ }
606
+ return displayedValue;
607
+ }
608
+ _computeHeaderSize() {
609
+ const headers = Object.values(this.headers.current);
610
+ if (headers.length === 0) {
611
+ return;
612
+ }
613
+ const scrollHeights = headers.map((header) => header.scrollHeight);
614
+ let headerHeight = Math.max(
615
+ Math.max(...scrollHeights) + DEFAULT_CELL_PADDING,
616
+ this.props.headerHeight
617
+ // hides (most often) padding override by forcing height
618
+ );
619
+ if (headerHeight !== this.state.headerHeight) {
620
+ this.setState({
621
+ headerHeight
622
+ });
623
+ }
624
+ }
625
+ makeHeaderRenderer(dataKey, columnIndex) {
626
+ const { columns, classes } = this.props;
627
+ return (headerProps) => {
628
+ return /* @__PURE__ */ jsxs(
629
+ TableCell,
630
+ {
631
+ component: "div",
632
+ className: clsx(
633
+ composeClasses(classes, cssTableCell),
634
+ composeClasses(classes, cssFlexContainer),
635
+ composeClasses(classes, cssNoClick),
636
+ composeClasses(classes, cssHeader)
637
+ ),
638
+ variant: "head",
639
+ style: { height: this.state.headerHeight },
640
+ align: columns[columnIndex].numeric || false ? "right" : "left",
641
+ ref: (e) => this._registerObserver(e),
642
+ children: [
643
+ this.props.sortable && this.state.indexer ? this.sortableHeader({
644
+ ...headerProps,
645
+ columnIndex,
646
+ key: { dataKey }
647
+ }) : this.simpleHeaderRenderer({
648
+ ...headerProps
649
+ }),
650
+ columns[columnIndex].extra && columns[columnIndex].extra
651
+ ]
652
+ }
653
+ );
654
+ };
655
+ }
656
+ render() {
657
+ const { viewIndexToModel, rowGetter } = reorderIndex(
658
+ this.state.indexer,
659
+ this.state.indirectionVersion,
660
+ this.props.rows,
661
+ this.props.columns,
662
+ this.props.filter,
663
+ this.props.sort
664
+ );
665
+ const sizes = this.sizes(
666
+ this.props.columns,
667
+ this.props.rows,
668
+ rowGetter
669
+ );
670
+ const csvHeaders = this.csvHeaders(
671
+ this.props.columns,
672
+ this.props.exportCSVDataKeys
673
+ );
674
+ return /* @__PURE__ */ jsxs(
675
+ "div",
676
+ {
677
+ style: {
678
+ display: "flex",
679
+ flexDirection: "column",
680
+ height: "100%"
681
+ },
682
+ className: this.props.className,
683
+ children: [
684
+ this.props.enableExportCSV && /* @__PURE__ */ jsxs(
685
+ "div",
686
+ {
687
+ style: {
688
+ display: "flex",
689
+ justifyContent: "flex-end",
690
+ alignItems: "center"
691
+ },
692
+ children: [
693
+ /* @__PURE__ */ jsx(FormattedMessage, { id: "MuiVirtualizedTable/exportCSV" }),
694
+ /* @__PURE__ */ jsx(
695
+ CsvDownloader,
696
+ {
697
+ datas: this.getCSVData,
698
+ columns: csvHeaders,
699
+ filename: this.getCSVFilename(),
700
+ children: /* @__PURE__ */ jsx(
701
+ IconButton,
702
+ {
703
+ "aria-label": "exportCSVButton",
704
+ size: "large",
705
+ children: /* @__PURE__ */ jsx(GetApp, {})
706
+ }
707
+ )
708
+ }
709
+ )
710
+ ]
711
+ }
712
+ ),
713
+ /* @__PURE__ */ jsx("div", { style: { flexGrow: 1 }, children: /* @__PURE__ */ jsx(AutoSizer, { children: ({ height, width }) => this.makeSizedTable(
714
+ height,
715
+ width,
716
+ sizes,
717
+ viewIndexToModel,
718
+ rowGetter
719
+ ) }) }),
720
+ this.state.popoverAnchorEl && /* @__PURE__ */ jsx(
721
+ Popover,
722
+ {
723
+ anchorEl: this.state.popoverAnchorEl,
724
+ anchorOrigin: {
725
+ vertical: "bottom",
726
+ horizontal: "left"
727
+ },
728
+ transformOrigin: {
729
+ vertical: "top",
730
+ horizontal: "left"
731
+ },
732
+ onKeyDownCapture: this.handleKeyDownOnPopover,
733
+ onClose: this.closePopover,
734
+ open: !!this.state.popoverAnchorEl,
735
+ PaperProps: { style: { minWidth: "20ex" } },
736
+ children: this.makeColumnFilterEditor()
737
+ }
738
+ )
739
+ ]
740
+ }
741
+ );
742
+ }
743
+ }
744
+ __publicField(MuiVirtualizedTable, "defaultProps", {
745
+ headerHeight: DEFAULT_HEADER_HEIGHT,
746
+ rowHeight: DEFAULT_ROW_HEIGHT,
747
+ enableExportCSV: false,
748
+ classes: {}
749
+ });
750
+ MuiVirtualizedTable.propTypes = {
751
+ name: PropTypes.string,
752
+ classes: PropTypes.object,
753
+ rows: PropTypes.array,
754
+ columns: PropTypes.arrayOf(
755
+ PropTypes.shape({
756
+ dataKey: PropTypes.string.isRequired,
757
+ label: PropTypes.string.isRequired,
758
+ numeric: PropTypes.bool,
759
+ width: PropTypes.number,
760
+ minWidth: PropTypes.number,
761
+ maxWidth: PropTypes.number,
762
+ unit: PropTypes.string,
763
+ fractionDigits: PropTypes.number,
764
+ extra: PropTypes.element
765
+ })
766
+ ).isRequired,
767
+ enableExportCSV: PropTypes.bool,
768
+ exportCSVDataKeys: PropTypes.array,
769
+ sort: PropTypes.func,
770
+ sortable: PropTypes.bool,
771
+ indexer: PropTypes.object,
772
+ headerHeight: PropTypes.number,
773
+ onRowClick: PropTypes.func,
774
+ onCellClick: PropTypes.func,
775
+ rowHeight: PropTypes.number,
776
+ filter: PropTypes.func,
777
+ tooltipSx: PropTypes.object
778
+ };
779
+ const nestedGlobalSelectorsStyles = toNestedGlobalSelectors(
780
+ defaultStyles,
781
+ generateMuiVirtualizedTableClass
782
+ );
783
+ const MuiVirtualizedTable$1 = styled(MuiVirtualizedTable)(nestedGlobalSelectorsStyles);
784
+ export {
785
+ DEFAULT_CELL_PADDING,
786
+ DEFAULT_HEADER_HEIGHT,
787
+ DEFAULT_ROW_HEIGHT,
788
+ MuiVirtualizedTable$1 as default,
789
+ generateMuiVirtualizedTableClass
790
+ };