@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
@@ -1,619 +0,0 @@
1
- function _createForOfIteratorHelperLoose(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (it) return (it = it.call(o)).next.bind(it); if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; return function () { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
2
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
4
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
7
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
8
- function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
- /**
10
- * Copyright (c) 2022, RTE (http://www.rte-france.com)
11
- * This Source Code Form is subject to the terms of the Mozilla Public
12
- * License, v. 2.0. If a copy of the MPL was not distributed with this
13
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
14
- */
15
-
16
- import { equalsArray } from '../../utils/algos';
17
- export var CHANGE_WAYS = {
18
- SIMPLE: 'Simple',
19
- TAIL: 'Tail',
20
- AMEND: 'Amend',
21
- REMOVE: 'Remove'
22
- };
23
-
24
- /* This is not real code commented
25
- const someTypicalColumns = [
26
- { label: 'strings column', dataKey: 'key1' },
27
- {
28
- label: 'integers column',
29
- dataKey: 'key2',
30
- numeric: true,
31
- fractionDigits: 0,
32
- },
33
- {
34
- label: 'column to ignore',
35
- dataKey: 'key3',
36
- nostat: true,
37
- },
38
- ];
39
- */
40
-
41
- export var noOpHelper = Object.freeze({
42
- debugName: 'noOp',
43
- maintainsStats: false,
44
- initStat: function initStat() {
45
- return undefined;
46
- },
47
- updateStat: function updateStat(colStat, value) {},
48
- accepts: function accepts(value, userParams, outerParams) {
49
- return true;
50
- }
51
- });
52
- var numericHelper = Object.freeze({
53
- debugName: 'num',
54
- maintainsStats: true,
55
- initStat: function initStat() {
56
- return {
57
- imin: null,
58
- imax: null
59
- };
60
- },
61
- updateStat: function updateStat(colStat, value) {
62
- if (colStat.imin === null || colStat.imin > value) {
63
- colStat.imin = value;
64
- }
65
- if (colStat.imax === null || colStat.imax < value) {
66
- colStat.imax = value;
67
- }
68
- },
69
- accepts: function accepts(value, userParams, outerParams) {
70
- return true;
71
- }
72
- });
73
- export var collectibleHelper = Object.freeze({
74
- debugName: 'collectible',
75
- maintainsStats: true,
76
- initStat: function initStat() {
77
- return {
78
- seen: {},
79
- kept: {}
80
- };
81
- },
82
- updateStat: function updateStat(colStat, cellValue, isForKeep) {
83
- var m = isForKeep ? colStat.kept : colStat.seen;
84
- if (!m[cellValue]) {
85
- m[cellValue] = 1;
86
- } else {
87
- m[cellValue] += 1;
88
- }
89
- },
90
- accepts: function accepts(value, userParams, outerParams) {
91
- return !userParams || userParams.some(function (v) {
92
- return v === value;
93
- });
94
- }
95
- });
96
- export var getHelper = function getHelper(column) {
97
- if (column === null || column === void 0 ? void 0 : column.numeric) {
98
- return numericHelper;
99
- } else if (!(column === null || column === void 0 ? void 0 : column.nostat)) {
100
- return collectibleHelper;
101
- } else {
102
- return noOpHelper;
103
- }
104
- };
105
-
106
- /**
107
- * A rows indexer for MuiVirtualizedTable to delegate to an instance of it
108
- * for filtering, grouping and multi-column sorting via
109
- * a view index to model index array.
110
- */
111
- export var KeyedColumnsRowIndexer = /*#__PURE__*/function () {
112
- function KeyedColumnsRowIndexer(isThreeState, singleColumnByDefault, delegatorCallback, versionSetter) {
113
- var _this = this;
114
- if (isThreeState === void 0) {
115
- isThreeState = true;
116
- }
117
- if (singleColumnByDefault === void 0) {
118
- singleColumnByDefault = false;
119
- }
120
- if (delegatorCallback === void 0) {
121
- delegatorCallback = null;
122
- }
123
- if (versionSetter === void 0) {
124
- versionSetter = null;
125
- }
126
- _defineProperty(this, "hasVersionSetter", function () {
127
- return !!_this._versionSetter;
128
- });
129
- _defineProperty(this, "getVersion", function () {
130
- return _this.version;
131
- });
132
- _defineProperty(this, "_bumpVersion", function (isFilter) {
133
- if (isFilter === void 0) {
134
- isFilter = false;
135
- }
136
- _this.version += 1;
137
- if (isFilter) {
138
- _this.filterVersion = _this.version;
139
- }
140
- if (_this.delegatorCallback) {
141
- _this.indirectionStatus = 'to sort';
142
- _this.delegatorCallback(_this, function (updated_ok) {
143
- _this.indirectionStatus = updated_ok ? 'done' : 'no_luck';
144
- });
145
- }
146
- if (_this._versionSetter) {
147
- _this._versionSetter(_this.version);
148
- }
149
- });
150
- _defineProperty(this, "updatePreferences", function (preferences) {
151
- if (preferences.isThreeState === _this.isThreeState && preferences.singleColumnByDefault === _this.singleColumnByDefault) {
152
- return false;
153
- }
154
- if (preferences.isThreeState !== _this.isThreeState) {
155
- _this.isThreeState = preferences.isThreeState;
156
- }
157
- if (preferences.singleColumnByDefault !== _this.singleColumnByDefault) {
158
- _this.singleColumnByDefault = preferences.singleColumnByDefault;
159
- }
160
- _this._bumpVersion();
161
- });
162
- // Does not mutate any internal
163
- // returns
164
- // { rowAndOrigIndex : [[row, originalRowIndex],...],
165
- // colsStats : {
166
- // colKey1 : {
167
- // seen : Map(value : count),
168
- // kept : Map(value : count)
169
- // },
170
- // colKey2 : {
171
- // imin : number,
172
- // imax : number,
173
- // }, colKeyN, ...
174
- // }
175
- // }
176
- _defineProperty(this, "preFilterRowMapping", function (columns, rows, rowFilter) {
177
- if (!(rows === null || rows === void 0 ? void 0 : rows.length) || !(columns === null || columns === void 0 ? void 0 : columns.length)) {
178
- return null;
179
- }
180
- var ri = [];
181
- var cs = {};
182
- for (var _iterator = _createForOfIteratorHelperLoose(columns), _step; !(_step = _iterator()).done;) {
183
- var _col2 = _step.value;
184
- var _helper2 = getHelper(_col2);
185
- var colStat = _helper2.initStat();
186
- if (colStat) {
187
- cs[_col2.dataKey] = colStat;
188
- }
189
- }
190
- for (var rowIdx = 0; rowIdx < rows.length; rowIdx++) {
191
- var row = rows[rowIdx];
192
- var acceptsRow = true;
193
- var acceptedOnRow = {};
194
- for (var colIdx = 0; colIdx < columns.length; colIdx++) {
195
- var _this$byColFilter;
196
- var col = columns[colIdx];
197
- var helper = getHelper(col);
198
- var colKey = col.dataKey;
199
- var cellValue = row[colKey];
200
- helper.updateStat(cs[colKey], cellValue, false);
201
- var colFilterParams = (_this$byColFilter = _this.byColFilter) === null || _this$byColFilter === void 0 ? void 0 : _this$byColFilter[colKey];
202
- var acceptsCell = true;
203
- if (colFilterParams) {
204
- var up = colFilterParams.userParams;
205
- var op = colFilterParams.outerParams;
206
- if (!helper.accepts(cellValue, up, op)) {
207
- acceptsCell = false;
208
- }
209
- }
210
- if (helper.maintainsStats && acceptsCell) {
211
- acceptedOnRow[colIdx] = cellValue;
212
- }
213
- acceptsRow &= acceptsCell;
214
- }
215
- if (acceptsRow && rowFilter) {
216
- acceptsRow = rowFilter(row);
217
- }
218
- if (acceptsRow && _this.byRowFilter) {
219
- acceptsRow = _this.byRowFilter(row);
220
- }
221
- if (acceptsRow) {
222
- for (var _i = 0, _Object$entries = Object.entries(acceptedOnRow); _i < _Object$entries.length; _i++) {
223
- var _Object$entries$_i = _Object$entries[_i],
224
- idx = _Object$entries$_i[0],
225
- value = _Object$entries$_i[1];
226
- var _col = columns[idx];
227
- var _helper = getHelper(_col);
228
- _helper.updateStat(cs[_col.dataKey], value, true);
229
- }
230
- ri.push([row, rowIdx]);
231
- }
232
- }
233
- return {
234
- rowAndOrigIndex: ri,
235
- colsStats: cs,
236
- rowsCount: rows.length
237
- };
238
- });
239
- // Does not mutate any internal
240
- // returns an array of indexes in rows given to preFilter
241
- _defineProperty(this, "makeGroupAndSortIndirector", function (preFilteredRowPairs, columns) {
242
- if (!preFilteredRowPairs) {
243
- return null;
244
- }
245
- var codedColumns = !_this.sortingState ? null : codedColumnsFromKeyAndDirection(_this.sortingState, columns);
246
- var groupingColumnsCount = _this.groupingCount;
247
- var indexedArray = groupAndSort(preFilteredRowPairs, codedColumns, groupingColumnsCount, columns);
248
- return !indexedArray ? null : indexedArray.map(function (k) {
249
- return k[1];
250
- });
251
- });
252
- _defineProperty(this, "getSortingAsKeyAndCodedRank", function () {
253
- if (!_this.sortingState) {
254
- return [];
255
- }
256
- return _this.sortingState.map(function (kd, i) {
257
- var sign = giveDirSignFor(kd[1]);
258
- var codedRank = sign * (i + 1);
259
- return [kd[0], codedRank];
260
- });
261
- });
262
- // returns true if really changed (and calls versionSetter if needed)
263
- _defineProperty(this, "updateSortingFromUser", function (colKey, change_way) {
264
- var keyAndDirections = _this.sortingState;
265
- if (change_way === CHANGE_WAYS.REMOVE) {
266
- if (!keyAndDirections) {
267
- return false;
268
- }
269
- var would = keyAndDirections.filter(function (p) {
270
- return p[0] !== colKey;
271
- });
272
- if (would.length === keyAndDirections.length) {
273
- return false;
274
- }
275
- _this.sortingState = would.length ? would : null;
276
- } else if (!keyAndDirections) {
277
- _this.sortingState = [[colKey, canonicalForSign(1)]];
278
- _this.lastUsedRank = 1;
279
- } else {
280
- var wasAtIdx = keyAndDirections.findIndex(function (p) {
281
- return p[0] === colKey;
282
- });
283
- var wasFuzzyDir = wasAtIdx < 0 ? 0 : keyAndDirections[wasAtIdx][1];
284
- var wasSignDir = giveDirSignFor(wasFuzzyDir);
285
- if (change_way === CHANGE_WAYS.SIMPLE) {
286
- if (wasSignDir < 0 && _this.isThreeState) {
287
- if (_this.sortingState.length === 1) {
288
- _this.sortingState = null;
289
- } else {
290
- _this.sortingState.splice(wasAtIdx, 1);
291
- }
292
- } else {
293
- if (_this.singleColumnByDefault || wasAtIdx < 0) {
294
- _this.sortingState = [];
295
- } else {
296
- _this.sortingState.splice(wasAtIdx, 1);
297
- }
298
- var nextSign = wasSignDir ? -wasSignDir : 1;
299
- var nextKD = [colKey, canonicalForSign(nextSign)];
300
- _this.sortingState.unshift(nextKD);
301
- }
302
- } else if (change_way === CHANGE_WAYS.TAIL) {
303
- if (wasAtIdx < 0) {
304
- _this.sortingState.push([colKey, canonicalForSign(1)]);
305
- } else if (wasAtIdx !== keyAndDirections.length - 1) {
306
- return false;
307
- } else if (!(_this.isThreeState && wasSignDir === -1)) {
308
- _this.sortingState[wasAtIdx][1] = canonicalForSign(-wasSignDir);
309
- } else {
310
- _this.sortingState.splice(wasAtIdx, 1);
311
- }
312
- } else {
313
- // AMEND
314
- if (wasAtIdx < 0) {
315
- if (_this.lastUsedRank - 1 > _this.sortingState.length) {
316
- return false;
317
- } else {
318
- _this.sortingState.splice(_this.lastUsedRank - 1, 0, [colKey, canonicalForSign(1)]);
319
- }
320
- } else if (!(_this.isThreeState && wasSignDir === -1)) {
321
- _this.sortingState[wasAtIdx][1] = canonicalForSign(-wasSignDir);
322
- } else {
323
- _this.lastUsedRank = wasAtIdx + 1;
324
- _this.sortingState.splice(wasAtIdx, 1);
325
- }
326
- }
327
- }
328
- _this._bumpVersion();
329
- return true;
330
- });
331
- _defineProperty(this, "codedRankByColumnIndex", function (columns) {
332
- return codedColumnsFromKeyAndDirection(_this.sortingState, columns);
333
- });
334
- _defineProperty(this, "columnSortingSignedRank", function (colKey) {
335
- var _this$sortingState;
336
- if (!(_this === null || _this === void 0 ? void 0 : (_this$sortingState = _this.sortingState) === null || _this$sortingState === void 0 ? void 0 : _this$sortingState.length)) {
337
- return 0;
338
- }
339
- var idx = _this.sortingState.findIndex(function (kd) {
340
- return kd[0] === colKey;
341
- });
342
- if (idx < 0) {
343
- return 0;
344
- }
345
- var colSorting = _this.sortingState[idx];
346
- return giveDirSignFor(colSorting[1]) * (idx + 1);
347
- });
348
- _defineProperty(this, "highestCodedColumn", function (columns) {
349
- var _this$sortingState2;
350
- if (!(_this === null || _this === void 0 ? void 0 : (_this$sortingState2 = _this.sortingState) === null || _this$sortingState2 === void 0 ? void 0 : _this$sortingState2.length)) {
351
- return 0;
352
- }
353
- var colSorting = _this.sortingState[0];
354
- var colKey = colSorting[0];
355
- var idx = columns.findIndex(function (col) {
356
- return col.dataKey === colKey;
357
- });
358
- if (idx < 0) {
359
- return 0;
360
- }
361
- return giveDirSignFor(colSorting[1]) * (idx + 1);
362
- });
363
- _defineProperty(this, "_getColFilterParams", function (colKey, isForUser) {
364
- if (!colKey || !_this.byColFilter) {
365
- return undefined;
366
- }
367
- var colFilter = _this.byColFilter[colKey];
368
- if (!colFilter) {
369
- return undefined;
370
- }
371
- return colFilter[isForUser ? 'userParams' : 'outerParams'];
372
- });
373
- _defineProperty(this, "_setColFilterParams", function (colKey, params, isForUser) {
374
- if (!colKey) {
375
- if (params) {
376
- throw new Error('column key has to be defined');
377
- }
378
- return false;
379
- }
380
- var fieldName = isForUser ? 'userParams' : 'outerParams';
381
- if (params) {
382
- if (!_this.byColFilter) {
383
- _this.byColFilter = {};
384
- }
385
- var colFilter = _this.byColFilter[colKey];
386
- if (!colFilter) {
387
- colFilter = {};
388
- _this.byColFilter[colKey] = colFilter;
389
- } else if (colFilter[fieldName] === params) {
390
- return false;
391
- }
392
- colFilter[fieldName] = params;
393
- } else {
394
- var _this$byColFilter$col;
395
- if (!_this.byColFilter) {
396
- return false;
397
- }
398
- var otherFieldName = !isForUser ? 'userParams' : 'outerParams';
399
- if ((_this$byColFilter$col = _this.byColFilter[colKey]) === null || _this$byColFilter$col === void 0 ? void 0 : _this$byColFilter$col[otherFieldName]) {
400
- delete _this.byColFilter[colKey][fieldName];
401
- } else {
402
- delete _this.byColFilter[colKey];
403
- }
404
- }
405
- if (isForUser) {
406
- _this._bumpVersion(true);
407
- }
408
- return true;
409
- });
410
- _defineProperty(this, "getColFilterOuterParams", function (colKey) {
411
- return _this._getColFilterParams(colKey, false);
412
- });
413
- _defineProperty(this, "setColFilterOuterParams", function (colKey, outerParams) {
414
- return _this._setColFilterParams(colKey, outerParams, false);
415
- });
416
- _defineProperty(this, "getColFilterUserParams", function (colKey) {
417
- return _this._getColFilterParams(colKey, true);
418
- });
419
- _defineProperty(this, "setColFilterUserParams", function (colKey, params) {
420
- return _this._setColFilterParams(colKey, params, true);
421
- });
422
- _defineProperty(this, "getUserFiltering", function () {
423
- var ret = {};
424
- if (_this.byColFilter) {
425
- Object.entries(_this.byColFilter).forEach(function (_ref) {
426
- var k = _ref[0],
427
- v = _ref[1];
428
- if (!v.userParams) {
429
- return;
430
- }
431
- ret[k] = [].concat(v.userParams);
432
- });
433
- }
434
- return ret;
435
- });
436
- _defineProperty(this, "updateRowFiltering", function (rowFilterFunc) {
437
- if (typeof rowFilterFunc !== 'function') {
438
- throw new Error('row filter should be a function');
439
- }
440
- _this.byRowFilter = rowFilterFunc;
441
- _this._bumpVersion();
442
- });
443
- this._versionSetter = versionSetter;
444
- this.version = 0;
445
- this.filterVersion = 0;
446
- this.delegatorCallback = delegatorCallback;
447
- this.indirectionStatus = null;
448
- this.isThreeState = isThreeState;
449
- this.singleColumnByDefault = singleColumnByDefault;
450
- this.lastUsedRank = 1;
451
- this.sortingState = null;
452
- this.groupingCount = 0;
453
- this.byColFilter = null; // common
454
- this.byRowFilter = null;
455
- }
456
- _createClass(KeyedColumnsRowIndexer, null, [{
457
- key: "CHANGE_WAYS",
458
- get: function get() {
459
- return CHANGE_WAYS;
460
- }
461
- }]);
462
- return KeyedColumnsRowIndexer;
463
- }();
464
- var giveDirSignFor = function giveDirSignFor(fuzzySign) {
465
- if (fuzzySign < 0) {
466
- return -1;
467
- }
468
- if (fuzzySign > 0) {
469
- return 1;
470
- }
471
- if (fuzzySign === 'asc') {
472
- return 1;
473
- }
474
- if (fuzzySign === 'desc') {
475
- return -1;
476
- }
477
- return 0;
478
- };
479
- var canonicalForSign = function canonicalForSign(dirSign) {
480
- if (dirSign > 0) {
481
- return 'asc';
482
- }
483
- if (dirSign < 0) {
484
- return 'desc';
485
- }
486
- return undefined;
487
- };
488
- var codedColumnsFromKeyAndDirection = function codedColumnsFromKeyAndDirection(keyAndDirections, columns) {
489
- if (!keyAndDirections) {
490
- return null;
491
- }
492
- var ret = [];
493
- var columIndexByKey = {};
494
- for (var colIdx = 0; colIdx < columns.length; colIdx++) {
495
- var col = columns[colIdx];
496
- var colKey = col.dataKey;
497
- columIndexByKey[colKey] = colIdx;
498
- }
499
- for (var _iterator2 = _createForOfIteratorHelperLoose(keyAndDirections), _step2; !(_step2 = _iterator2()).done;) {
500
- var knd = _step2.value;
501
- var _colKey = knd[0];
502
- var dir = knd[1];
503
- var _colIdx = columIndexByKey[_colKey];
504
- if (_colIdx === undefined) {
505
- continue;
506
- }
507
- var sign = giveDirSignFor(dir);
508
- ret.push((_colIdx + 1) * sign);
509
- }
510
- return ret;
511
- };
512
- var compareValue = function compareValue(a, b, isNumeric, undefSign) {
513
- if (undefSign === void 0) {
514
- undefSign = -1;
515
- }
516
- if (a === undefined && b === undefined) {
517
- return 0;
518
- } else {
519
- if (a === undefined) {
520
- return undefSign;
521
- } else {
522
- if (b === undefined) {
523
- return -undefSign;
524
- }
525
- }
526
- }
527
- if (!isNumeric) {
528
- return ('' + a).localeCompare(b);
529
- } else {
530
- if (isNaN(a)) {
531
- return isNaN(b) ? 0 : 1;
532
- }
533
- if (isNaN(b)) {
534
- return -1;
535
- }
536
- return Math.sign(Number(a) - Number(b));
537
- }
538
- };
539
- var makeCompositeComparatorFromCodedColumns = function makeCompositeComparatorFromCodedColumns(codedColumns, columns, rowExtractor) {
540
- return function (row_a_i, row_b_i) {
541
- var row_a = rowExtractor(row_a_i);
542
- var row_b = rowExtractor(row_b_i);
543
- for (var _iterator3 = _createForOfIteratorHelperLoose(codedColumns), _step3; !(_step3 = _iterator3()).done;) {
544
- var cc = _step3.value;
545
- var i = Math.abs(cc) - 1;
546
- var mul = Math.sign(cc);
547
- var col = columns[i];
548
- var key = col.dataKey;
549
- var sgn = compareValue(row_a[key], row_b[key], col.numeric);
550
- if (sgn) {
551
- return mul * sgn;
552
- }
553
- }
554
- return 0;
555
- };
556
- };
557
- var groupRows = function groupRows(groupingColumnsCount, columns, indexedArray) {
558
- var groupingComparator = makeCompositeComparatorFromCodedColumns(Array(groupingColumnsCount).map(function (x, i) {
559
- return i + 1;
560
- }), columns, function (ar) {
561
- return ar[0];
562
- });
563
- indexedArray.sort(groupingComparator);
564
- var groups = [];
565
- var prevSlice = null;
566
- var inBuildGroup = [];
567
- groups.push(inBuildGroup);
568
- for (var _iterator4 = _createForOfIteratorHelperLoose(indexedArray), _step4; !(_step4 = _iterator4()).done;) {
569
- var p = _step4.value;
570
- var nextSlice = p[0].slice(0, groupingColumnsCount);
571
- if (prevSlice === null || !equalsArray(prevSlice, nextSlice)) {
572
- inBuildGroup = [];
573
- groups.push(inBuildGroup);
574
- }
575
- inBuildGroup.push(p);
576
- prevSlice = nextSlice;
577
- }
578
- return groups;
579
- };
580
- var groupAndSort = function groupAndSort(preFilteredRowPairs, codedColumns, groupingColumnsCount, columns) {
581
- var nothingToDo = !codedColumns && !groupingColumnsCount;
582
- var indexedArray = preFilteredRowPairs.rowAndOrigIndex;
583
- var noOutFiltered = preFilteredRowPairs.rowsCount === indexedArray.length;
584
- if (nothingToDo && noOutFiltered) {
585
- return null;
586
- } else if (!nothingToDo) {
587
- // make a copy for not losing base order
588
- indexedArray = [].concat(indexedArray);
589
- }
590
- if (nothingToDo) {
591
- // just nothing
592
- } else if (!groupingColumnsCount) {
593
- var sortingComparator = makeCompositeComparatorFromCodedColumns(codedColumns, columns, function (ar) {
594
- return ar[0];
595
- });
596
- indexedArray.sort(sortingComparator);
597
- } else {
598
- var groups = groupRows(groupingColumnsCount, columns, indexedArray);
599
- var interGroupSortingComparator = makeCompositeComparatorFromCodedColumns(codedColumns, columns, function (ar) {
600
- return ar[0][0];
601
- });
602
- groups.sort(interGroupSortingComparator);
603
- var intraGroupSortingComparator = makeCompositeComparatorFromCodedColumns(codedColumns, columns, function (ar) {
604
- return ar[0];
605
- });
606
- indexedArray = [];
607
- for (var _iterator5 = _createForOfIteratorHelperLoose(groups), _step5; !(_step5 = _iterator5()).done;) {
608
- var _indexedArray;
609
- var group = _step5.value;
610
- group.sort(intraGroupSortingComparator);
611
- (_indexedArray = indexedArray).push.apply(_indexedArray, group);
612
- }
613
- }
614
- return indexedArray;
615
- };
616
- export var forTesting = {
617
- codedColumnsFromKeyAndDirection: codedColumnsFromKeyAndDirection,
618
- makeCompositeComparatorFromCodedColumns: makeCompositeComparatorFromCodedColumns
619
- };