@deephaven/iris-grid 0.13.3-treemap.2 → 0.14.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 (184) hide show
  1. package/dist/AdvancedFilterCreator.d.ts +69 -63
  2. package/dist/AdvancedFilterCreator.d.ts.map +1 -1
  3. package/dist/AdvancedFilterCreator.js +79 -73
  4. package/dist/AdvancedFilterCreator.js.map +1 -1
  5. package/dist/AdvancedFilterCreatorSelectValue.d.ts +45 -45
  6. package/dist/AdvancedFilterCreatorSelectValue.d.ts.map +1 -1
  7. package/dist/AdvancedFilterCreatorSelectValue.js +32 -36
  8. package/dist/AdvancedFilterCreatorSelectValue.js.map +1 -1
  9. package/dist/AdvancedFilterCreatorSelectValueList.d.ts +47 -52
  10. package/dist/AdvancedFilterCreatorSelectValueList.d.ts.map +1 -1
  11. package/dist/AdvancedFilterCreatorSelectValueList.js +24 -39
  12. package/dist/AdvancedFilterCreatorSelectValueList.js.map +1 -1
  13. package/dist/ColumnStatistics.d.ts +34 -22
  14. package/dist/ColumnStatistics.d.ts.map +1 -1
  15. package/dist/ColumnStatistics.js +8 -12
  16. package/dist/ColumnStatistics.js.map +1 -1
  17. package/dist/CommonTypes.d.ts +58 -0
  18. package/dist/CommonTypes.d.ts.map +1 -0
  19. package/dist/CommonTypes.js +2 -0
  20. package/dist/CommonTypes.js.map +1 -0
  21. package/dist/CrossColumnSearch.d.ts +26 -24
  22. package/dist/CrossColumnSearch.d.ts.map +1 -1
  23. package/dist/CrossColumnSearch.js +9 -13
  24. package/dist/CrossColumnSearch.js.map +1 -1
  25. package/dist/FilterInputField.d.ts +48 -51
  26. package/dist/FilterInputField.d.ts.map +1 -1
  27. package/dist/FilterInputField.js +30 -27
  28. package/dist/FilterInputField.js.map +1 -1
  29. package/dist/IrisGrid.d.ts +409 -453
  30. package/dist/IrisGrid.d.ts.map +1 -1
  31. package/dist/IrisGrid.js +514 -449
  32. package/dist/IrisGrid.js.map +1 -1
  33. package/dist/IrisGridCellOverflowModal.d.ts +1 -1
  34. package/dist/IrisGridCellOverflowModal.d.ts.map +1 -1
  35. package/dist/IrisGridCellOverflowModal.js.map +1 -1
  36. package/dist/IrisGridCopyHandler.d.ts +52 -46
  37. package/dist/IrisGridCopyHandler.d.ts.map +1 -1
  38. package/dist/IrisGridCopyHandler.js +22 -38
  39. package/dist/IrisGridCopyHandler.js.map +1 -1
  40. package/dist/IrisGridMetricCalculator.d.ts +5 -4
  41. package/dist/IrisGridMetricCalculator.d.ts.map +1 -1
  42. package/dist/IrisGridMetricCalculator.js +5 -1
  43. package/dist/IrisGridMetricCalculator.js.map +1 -1
  44. package/dist/IrisGridModel.d.ts +37 -35
  45. package/dist/IrisGridModel.d.ts.map +1 -1
  46. package/dist/IrisGridModel.js +19 -3
  47. package/dist/IrisGridModel.js.map +1 -1
  48. package/dist/IrisGridModelFactory.d.ts +7 -5
  49. package/dist/IrisGridModelFactory.d.ts.map +1 -1
  50. package/dist/IrisGridModelFactory.js +5 -5
  51. package/dist/IrisGridModelFactory.js.map +1 -1
  52. package/dist/IrisGridModelUpdater.d.ts +13 -11
  53. package/dist/IrisGridModelUpdater.d.ts.map +1 -1
  54. package/dist/IrisGridModelUpdater.js.map +1 -1
  55. package/dist/IrisGridPartitionSelector.d.ts +38 -39
  56. package/dist/IrisGridPartitionSelector.d.ts.map +1 -1
  57. package/dist/IrisGridPartitionSelector.js +18 -24
  58. package/dist/IrisGridPartitionSelector.js.map +1 -1
  59. package/dist/IrisGridProxyModel.d.ts +111 -32
  60. package/dist/IrisGridProxyModel.d.ts.map +1 -1
  61. package/dist/IrisGridProxyModel.js +212 -170
  62. package/dist/IrisGridProxyModel.js.map +1 -1
  63. package/dist/IrisGridRenderer.d.ts +59 -31
  64. package/dist/IrisGridRenderer.d.ts.map +1 -1
  65. package/dist/IrisGridRenderer.js +92 -46
  66. package/dist/IrisGridRenderer.js.map +1 -1
  67. package/dist/IrisGridTableModel.d.ts +48 -147
  68. package/dist/IrisGridTableModel.d.ts.map +1 -1
  69. package/dist/IrisGridTableModel.js +58 -1381
  70. package/dist/IrisGridTableModel.js.map +1 -1
  71. package/dist/IrisGridTableModelTemplate.d.ts +219 -0
  72. package/dist/IrisGridTableModelTemplate.d.ts.map +1 -0
  73. package/dist/IrisGridTableModelTemplate.js +1623 -0
  74. package/dist/IrisGridTableModelTemplate.js.map +1 -0
  75. package/dist/IrisGridTestUtils.d.ts +18 -14
  76. package/dist/IrisGridTestUtils.d.ts.map +1 -1
  77. package/dist/IrisGridTestUtils.js +29 -1
  78. package/dist/IrisGridTestUtils.js.map +1 -1
  79. package/dist/IrisGridTheme.d.ts +35 -3
  80. package/dist/IrisGridTheme.d.ts.map +1 -1
  81. package/dist/IrisGridTheme.js.map +1 -1
  82. package/dist/IrisGridTreeTableModel.d.ts +26 -7
  83. package/dist/IrisGridTreeTableModel.d.ts.map +1 -1
  84. package/dist/IrisGridTreeTableModel.js +24 -14
  85. package/dist/IrisGridTreeTableModel.js.map +1 -1
  86. package/dist/IrisGridUtils.d.ts +257 -162
  87. package/dist/IrisGridUtils.d.ts.map +1 -1
  88. package/dist/IrisGridUtils.js +132 -95
  89. package/dist/IrisGridUtils.js.map +1 -1
  90. package/dist/MissingKeyError.d.ts +5 -3
  91. package/dist/MissingKeyError.d.ts.map +1 -1
  92. package/dist/MissingKeyError.js.map +1 -1
  93. package/dist/PartitionSelectorSearch.d.ts +61 -40
  94. package/dist/PartitionSelectorSearch.d.ts.map +1 -1
  95. package/dist/PartitionSelectorSearch.js +25 -15
  96. package/dist/PartitionSelectorSearch.js.map +1 -1
  97. package/dist/PendingDataBottomBar.d.ts +3 -6
  98. package/dist/PendingDataBottomBar.d.ts.map +1 -1
  99. package/dist/PendingDataBottomBar.js.map +1 -1
  100. package/dist/TableViewportUpdater.d.ts +39 -55
  101. package/dist/TableViewportUpdater.d.ts.map +1 -1
  102. package/dist/TableViewportUpdater.js +42 -64
  103. package/dist/TableViewportUpdater.js.map +1 -1
  104. package/dist/TreeTableViewportUpdater.d.ts +29 -37
  105. package/dist/TreeTableViewportUpdater.d.ts.map +1 -1
  106. package/dist/TreeTableViewportUpdater.js +39 -50
  107. package/dist/TreeTableViewportUpdater.js.map +1 -1
  108. package/dist/index.d.ts +9 -0
  109. package/dist/index.d.ts.map +1 -1
  110. package/dist/index.js +9 -0
  111. package/dist/index.js.map +1 -1
  112. package/dist/mousehandlers/IrisGridCellOverflowMouseHandler.d.ts.map +1 -1
  113. package/dist/mousehandlers/IrisGridCellOverflowMouseHandler.js.map +1 -1
  114. package/dist/mousehandlers/IrisGridColumnSelectMouseHandler.d.ts +1 -1
  115. package/dist/mousehandlers/IrisGridColumnSelectMouseHandler.d.ts.map +1 -1
  116. package/dist/mousehandlers/IrisGridColumnSelectMouseHandler.js +2 -0
  117. package/dist/mousehandlers/IrisGridColumnSelectMouseHandler.js.map +1 -1
  118. package/dist/mousehandlers/IrisGridColumnTooltipMouseHandler.js +1 -1
  119. package/dist/mousehandlers/IrisGridColumnTooltipMouseHandler.js.map +1 -1
  120. package/dist/mousehandlers/IrisGridContextMenuHandler.d.ts +41 -130
  121. package/dist/mousehandlers/IrisGridContextMenuHandler.d.ts.map +1 -1
  122. package/dist/mousehandlers/IrisGridContextMenuHandler.js +426 -317
  123. package/dist/mousehandlers/IrisGridContextMenuHandler.js.map +1 -1
  124. package/dist/mousehandlers/IrisGridFilterMouseHandler.d.ts.map +1 -1
  125. package/dist/mousehandlers/IrisGridFilterMouseHandler.js +2 -2
  126. package/dist/mousehandlers/IrisGridFilterMouseHandler.js.map +1 -1
  127. package/dist/mousehandlers/IrisGridSortMouseHandler.js +1 -1
  128. package/dist/mousehandlers/IrisGridSortMouseHandler.js.map +1 -1
  129. package/dist/mousehandlers/PendingMouseHandler.d.ts +8 -4
  130. package/dist/mousehandlers/PendingMouseHandler.d.ts.map +1 -1
  131. package/dist/mousehandlers/PendingMouseHandler.js +4 -5
  132. package/dist/mousehandlers/PendingMouseHandler.js.map +1 -1
  133. package/dist/sidebar/ChartBuilder.d.ts +48 -33
  134. package/dist/sidebar/ChartBuilder.d.ts.map +1 -1
  135. package/dist/sidebar/ChartBuilder.js +28 -27
  136. package/dist/sidebar/ChartBuilder.js.map +1 -1
  137. package/dist/sidebar/CustomColumnBuilder.d.ts +51 -41
  138. package/dist/sidebar/CustomColumnBuilder.d.ts.map +1 -1
  139. package/dist/sidebar/CustomColumnBuilder.js +22 -18
  140. package/dist/sidebar/CustomColumnBuilder.js.map +1 -1
  141. package/dist/sidebar/CustomColumnInput.d.ts +26 -36
  142. package/dist/sidebar/CustomColumnInput.d.ts.map +1 -1
  143. package/dist/sidebar/CustomColumnInput.js +11 -20
  144. package/dist/sidebar/CustomColumnInput.js.map +1 -1
  145. package/dist/sidebar/InputEditor.d.ts +34 -35
  146. package/dist/sidebar/InputEditor.d.ts.map +1 -1
  147. package/dist/sidebar/InputEditor.js +43 -24
  148. package/dist/sidebar/InputEditor.js.map +1 -1
  149. package/dist/sidebar/RollupRows.d.ts +67 -52
  150. package/dist/sidebar/RollupRows.d.ts.map +1 -1
  151. package/dist/sidebar/RollupRows.js +51 -53
  152. package/dist/sidebar/RollupRows.js.map +1 -1
  153. package/dist/sidebar/SelectDistinctBuilder.d.ts +27 -21
  154. package/dist/sidebar/SelectDistinctBuilder.d.ts.map +1 -1
  155. package/dist/sidebar/SelectDistinctBuilder.js +6 -10
  156. package/dist/sidebar/SelectDistinctBuilder.js.map +1 -1
  157. package/dist/sidebar/TableCsvExporter.d.ts +42 -39
  158. package/dist/sidebar/TableCsvExporter.d.ts.map +1 -1
  159. package/dist/sidebar/TableCsvExporter.js +12 -20
  160. package/dist/sidebar/TableCsvExporter.js.map +1 -1
  161. package/dist/sidebar/TableSaver.d.ts +59 -60
  162. package/dist/sidebar/TableSaver.d.ts.map +1 -1
  163. package/dist/sidebar/TableSaver.js +154 -68
  164. package/dist/sidebar/TableSaver.js.map +1 -1
  165. package/dist/sidebar/VisibilityOrderingBuilder.d.ts +56 -45
  166. package/dist/sidebar/VisibilityOrderingBuilder.d.ts.map +1 -1
  167. package/dist/sidebar/VisibilityOrderingBuilder.js +34 -29
  168. package/dist/sidebar/VisibilityOrderingBuilder.js.map +1 -1
  169. package/dist/sidebar/aggregations/Aggregations.d.ts.map +1 -1
  170. package/dist/sidebar/aggregations/Aggregations.js.map +1 -1
  171. package/dist/sidebar/conditional-formatting/ConditionalFormattingMenu.d.ts +2 -1
  172. package/dist/sidebar/conditional-formatting/ConditionalFormattingMenu.d.ts.map +1 -1
  173. package/dist/sidebar/conditional-formatting/ConditionalFormattingMenu.js.map +1 -1
  174. package/dist/sidebar/conditional-formatting/ConditionalFormattingUtils.d.ts +6 -5
  175. package/dist/sidebar/conditional-formatting/ConditionalFormattingUtils.d.ts.map +1 -1
  176. package/dist/sidebar/conditional-formatting/ConditionalFormattingUtils.js +5 -0
  177. package/dist/sidebar/conditional-formatting/ConditionalFormattingUtils.js.map +1 -1
  178. package/dist/sidebar/icons/index.d.ts +7 -7
  179. package/dist/sidebar/icons/index.d.ts.map +1 -1
  180. package/dist/sidebar/icons/index.js.map +1 -1
  181. package/dist/sidebar/index.d.ts +12 -12
  182. package/dist/sidebar/index.d.ts.map +1 -1
  183. package/dist/sidebar/index.js.map +1 -1
  184. package/package.json +17 -16
@@ -0,0 +1,1623 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
6
+
7
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
8
+
9
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+
11
+ /* eslint class-methods-use-this: "off" */
12
+ import memoize from 'memoize-one';
13
+ import throttle from 'lodash.throttle';
14
+ import { GridRange, memoizeClear } from '@deephaven/grid';
15
+ import dh from '@deephaven/jsapi-shim';
16
+ import Log from '@deephaven/log';
17
+ import { EventShimCustomEvent, PromiseUtils, assertNotNull } from '@deephaven/utils';
18
+ import { TableUtils, Formatter, FormatterUtils } from '@deephaven/jsapi-utils';
19
+ import IrisGridModel from "./IrisGridModel.js";
20
+ import AggregationOperation from "./sidebar/aggregations/AggregationOperation.js";
21
+ import IrisGridUtils from "./IrisGridUtils.js";
22
+ import MissingKeyError from "./MissingKeyError.js";
23
+ import IrisGridTableModel from "./IrisGridTableModel.js";
24
+ var log = Log.module('IrisGridTableModel');
25
+ var SET_VIEWPORT_THROTTLE = 150;
26
+ var APPLY_VIEWPORT_THROTTLE = 0;
27
+ export function isIrisGridTableModelTemplate(model) {
28
+ return model.table !== undefined;
29
+ }
30
+ /**
31
+ * Template model for a grid
32
+ */
33
+
34
+ class IrisGridTableModelTemplate extends IrisGridModel {
35
+ export() {
36
+ throw new Error('Method not implemented.');
37
+ }
38
+
39
+ columnStatistics(column) {
40
+ throw new Error('Method not implemented.');
41
+ }
42
+
43
+ get customColumns() {
44
+ return [];
45
+ }
46
+
47
+ set customColumns(customColumns) {
48
+ throw new Error('Method not implemented.');
49
+ }
50
+
51
+ get formatColumns() {
52
+ return [];
53
+ }
54
+
55
+ set formatColumns(formatColumns) {
56
+ throw new Error('Method not implemented.');
57
+ }
58
+
59
+ updateFrozenColumns(columns) {
60
+ throw new Error('Method not implemented.');
61
+ }
62
+
63
+ get rollupConfig() {
64
+ throw new Error('Method not implemented.');
65
+ }
66
+
67
+ set rollupConfig(rollupConfig) {
68
+ throw new Error('Method not implemented.');
69
+ }
70
+
71
+ get selectDistinctColumns() {
72
+ throw new Error('Method not implemented.');
73
+ }
74
+
75
+ set selectDistinctColumns(names) {
76
+ throw new Error('Method not implemented.');
77
+ }
78
+
79
+ get columns() {
80
+ return this.table.columns;
81
+ }
82
+
83
+ /**
84
+ * @param table Iris data table to be used in the model
85
+ * @param formatter The formatter to use when getting formats
86
+ * @param inputTable Iris input table associated with this table
87
+ */
88
+ constructor(table) {
89
+ var _formatter = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : new Formatter();
90
+
91
+ var inputTable = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
92
+ super();
93
+
94
+ _defineProperty(this, "irisFormatter", void 0);
95
+
96
+ _defineProperty(this, "inputTable", void 0);
97
+
98
+ _defineProperty(this, "subscription", void 0);
99
+
100
+ _defineProperty(this, "table", void 0);
101
+
102
+ _defineProperty(this, "viewport", void 0);
103
+
104
+ _defineProperty(this, "viewportData", void 0);
105
+
106
+ _defineProperty(this, "formattedStringData", void 0);
107
+
108
+ _defineProperty(this, "pendingStringData", void 0);
109
+
110
+ _defineProperty(this, "isSaveInProgress", void 0);
111
+
112
+ _defineProperty(this, "totalsTable", void 0);
113
+
114
+ _defineProperty(this, "totalsTablePromise", void 0);
115
+
116
+ _defineProperty(this, "totals", void 0);
117
+
118
+ _defineProperty(this, "totalsDataMap", void 0);
119
+
120
+ _defineProperty(this, "pendingNewDataMap", void 0);
121
+
122
+ _defineProperty(this, "pendingNewRowCount", 0);
123
+
124
+ _defineProperty(this, "pendingNewDataErrors", void 0);
125
+
126
+ _defineProperty(this, "getMemoizedColumnMap", memoize(tableColumns => {
127
+ var columnMap = new Map();
128
+ tableColumns.forEach(col => columnMap.set(col.name, col));
129
+ return columnMap;
130
+ }));
131
+
132
+ _defineProperty(this, "getColumnIndicesByNameMap", memoize(columns => {
133
+ var indices = new Map();
134
+ columns.forEach((_ref, i) => {
135
+ var {
136
+ name
137
+ } = _ref;
138
+ return indices.set(name, i);
139
+ });
140
+ return indices;
141
+ }));
142
+
143
+ _defineProperty(this, "setViewport", throttle((top, bottom, columns) => {
144
+ if (bottom < top) {
145
+ log.error('Invalid viewport', top, bottom);
146
+ return;
147
+ }
148
+
149
+ var {
150
+ viewport
151
+ } = this;
152
+
153
+ if (viewport != null && viewport.top === top && viewport.bottom === bottom && viewport.columns === columns) {
154
+ log.debug2('Ignoring duplicate viewport', viewport);
155
+ return;
156
+ }
157
+
158
+ this.viewport = {
159
+ top,
160
+ bottom,
161
+ columns
162
+ };
163
+ log.debug2('setViewport', this.viewport);
164
+ this.applyViewport();
165
+ }, SET_VIEWPORT_THROTTLE));
166
+
167
+ _defineProperty(this, "applyViewport", throttle(() => {
168
+ if (!this.viewport) {
169
+ return;
170
+ }
171
+
172
+ log.debug2('applyViewport', this.viewport);
173
+ var {
174
+ top,
175
+ bottom,
176
+ columns
177
+ } = this.viewport;
178
+ var [viewportTop, viewportBottom] = this.getCachedViewportRowRange(top, bottom);
179
+ this.applyBufferedViewport(viewportTop, viewportBottom, columns);
180
+ }, APPLY_VIEWPORT_THROTTLE, {
181
+ leading: false
182
+ }));
183
+
184
+ _defineProperty(this, "getCachedFormattedString", memoizeClear((formatter, value, columnType, columnName, formatOverride) => formatter.getFormattedString(value, columnType, columnName, formatOverride), {
185
+ max: 10000
186
+ }));
187
+
188
+ _defineProperty(this, "getCachedCustomColumnFormatFlag", memoizeClear(FormatterUtils.isCustomColumnFormatDefined, {
189
+ max: 10000
190
+ }));
191
+
192
+ _defineProperty(this, "getCachedViewportRowRange", memoize((top, bottom) => {
193
+ var viewHeight = bottom - top;
194
+ var viewportTop = Math.max(0, top - viewHeight * IrisGridTableModel.ROW_BUFFER_PAGES);
195
+ var viewportBottom = bottom + viewHeight * IrisGridTableModel.ROW_BUFFER_PAGES;
196
+ return [viewportTop, viewportBottom];
197
+ }));
198
+
199
+ _defineProperty(this, "getCachedPendingErrors", memoize((pendingDataMap, columns, keyColumnCount) => {
200
+ var map = new Map();
201
+ pendingDataMap.forEach((row, rowIndex) => {
202
+ var {
203
+ data: rowData
204
+ } = row;
205
+
206
+ for (var i = 0; i < keyColumnCount; i += 1) {
207
+ if (!rowData.has(i)) {
208
+ var _map$get;
209
+
210
+ if (!map.has(rowIndex)) {
211
+ map.set(rowIndex, []);
212
+ }
213
+
214
+ (_map$get = map.get(rowIndex)) === null || _map$get === void 0 ? void 0 : _map$get.push(new MissingKeyError(rowIndex, columns[i].name));
215
+ }
216
+ }
217
+ });
218
+ return map;
219
+ }));
220
+
221
+ this.handleTableDisconnect = this.handleTableDisconnect.bind(this);
222
+ this.handleTableReconnect = this.handleTableReconnect.bind(this);
223
+ this.handleTableUpdate = this.handleTableUpdate.bind(this);
224
+ this.handleTotalsUpdate = this.handleTotalsUpdate.bind(this);
225
+ this.handleRequestFailed = this.handleRequestFailed.bind(this);
226
+ this.handleCustomColumnsChanged = this.handleCustomColumnsChanged.bind(this);
227
+ this.irisFormatter = _formatter;
228
+ this.inputTable = inputTable;
229
+ this.subscription = null;
230
+ this.table = table;
231
+ this.viewport = null;
232
+ this.viewportData = null;
233
+ this.formattedStringData = [];
234
+ this.pendingStringData = [];
235
+ this.isSaveInProgress = false;
236
+ this.totalsTable = null;
237
+ this.totalsTablePromise = null;
238
+ this.totals = null;
239
+ this.totalsDataMap = null; // Map from new row index to their values. Only for input tables that can have new rows added.
240
+ // The index of these rows start at 0, and they are appended at the end of the regular table data.
241
+ // These rows can be sparse, so using a map instead of an array.
242
+
243
+ this.pendingNewDataMap = new Map();
244
+ this.pendingNewDataErrors = null;
245
+ this.pendingNewRowCount = 0;
246
+ }
247
+
248
+ close() {
249
+ this.table.close();
250
+
251
+ if (this.totalsTable !== null) {
252
+ this.totalsTable.close();
253
+ }
254
+
255
+ if (this.totalsTablePromise !== null) {
256
+ this.totalsTablePromise.cancel();
257
+ }
258
+ }
259
+
260
+ startListening() {
261
+ super.startListening();
262
+ this.table.addEventListener(dh.Table.EVENT_DISCONNECT, this.handleTableDisconnect);
263
+ this.table.addEventListener(dh.Table.EVENT_RECONNECT, this.handleTableReconnect);
264
+ this.table.addEventListener(dh.Table.EVENT_UPDATED, this.handleTableUpdate);
265
+ this.table.addEventListener(dh.Client.EVENT_REQUEST_FAILED, this.handleRequestFailed);
266
+ this.table.addEventListener(dh.Table.EVENT_CUSTOMCOLUMNSCHANGED, this.handleCustomColumnsChanged);
267
+
268
+ if (this.totalsTable != null) {
269
+ this.addTotalsListeners(this.totalsTable);
270
+ }
271
+
272
+ this.applyViewport();
273
+ }
274
+
275
+ stopListening() {
276
+ super.stopListening();
277
+ this.table.removeEventListener(dh.Table.EVENT_DISCONNECT, this.handleTableDisconnect);
278
+ this.table.removeEventListener(dh.Table.EVENT_RECONNECT, this.handleTableReconnect);
279
+ this.table.removeEventListener(dh.Table.EVENT_UPDATED, this.handleTableUpdate);
280
+ this.table.removeEventListener(dh.Client.EVENT_REQUEST_FAILED, this.handleRequestFailed);
281
+ this.table.removeEventListener(dh.Table.EVENT_CUSTOMCOLUMNSCHANGED, this.handleCustomColumnsChanged);
282
+
283
+ if (this.totalsTable != null) {
284
+ this.removeTotalsListeners(this.totalsTable);
285
+ }
286
+
287
+ this.closeSubscription();
288
+ }
289
+
290
+ addTotalsListeners(totalsTable) {
291
+ totalsTable.addEventListener(dh.Table.EVENT_UPDATED, this.handleTotalsUpdate); // Totals table only has one row of data
292
+
293
+ totalsTable.setViewport(0, 0);
294
+ }
295
+
296
+ removeTotalsListeners(totalsTable) {
297
+ totalsTable.removeEventListener(dh.Table.EVENT_UPDATED, this.handleTotalsUpdate);
298
+ }
299
+
300
+ handleTableDisconnect() {
301
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.DISCONNECT));
302
+ }
303
+
304
+ handleTableReconnect() {
305
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.RECONNECT));
306
+ }
307
+
308
+ handleTableUpdate(event) {
309
+ this.copyViewportData(event.detail);
310
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
311
+ }
312
+
313
+ handleTotalsUpdate(event) {
314
+ this.copyTotalsData(event.detail);
315
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
316
+ }
317
+
318
+ handleRequestFailed(event) {
319
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.REQUEST_FAILED, event));
320
+ }
321
+
322
+ handleCustomColumnsChanged() {
323
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.COLUMNS_CHANGED, {
324
+ detail: this.columns
325
+ }));
326
+ }
327
+
328
+ get rowCount() {
329
+ var _this$totals$operatio, _this$totals, _this$totals$operatio2;
330
+
331
+ return this.table.size + this.pendingNewRowCount + ((_this$totals$operatio = (_this$totals = this.totals) === null || _this$totals === void 0 ? void 0 : (_this$totals$operatio2 = _this$totals.operationOrder) === null || _this$totals$operatio2 === void 0 ? void 0 : _this$totals$operatio2.length) !== null && _this$totals$operatio !== void 0 ? _this$totals$operatio : 0);
332
+ }
333
+
334
+ get pendingDataErrors() {
335
+ var _this$inputTable$keyC, _this$inputTable;
336
+
337
+ return this.getCachedPendingErrors(this.pendingNewDataMap, this.columns, (_this$inputTable$keyC = (_this$inputTable = this.inputTable) === null || _this$inputTable === void 0 ? void 0 : _this$inputTable.keyColumns.length) !== null && _this$inputTable$keyC !== void 0 ? _this$inputTable$keyC : 0);
338
+ }
339
+
340
+ get pendingDataMap() {
341
+ return this.pendingNewDataMap;
342
+ }
343
+
344
+ set pendingDataMap(map) {
345
+ if (map === this.pendingNewDataMap) {
346
+ return;
347
+ }
348
+
349
+ map.forEach((row, rowIndex) => {
350
+ if (!IrisGridUtils.isValidIndex(rowIndex)) {
351
+ throw new Error("Invalid rowIndex ".concat(rowIndex));
352
+ }
353
+
354
+ var {
355
+ data
356
+ } = row;
357
+ data.forEach((value, columnIndex) => {
358
+ if (!IrisGridUtils.isValidIndex(columnIndex)) {
359
+ throw new Error("Invalid columnIndex ".concat(columnIndex));
360
+ }
361
+ });
362
+ });
363
+ this.pendingNewDataMap = map;
364
+ this.pendingNewRowCount = Math.max(this.pendingNewRowCount, this.maxPendingDataRow);
365
+ this.formattedStringData = [];
366
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.PENDING_DATA_UPDATED));
367
+ }
368
+
369
+ get pendingRowCount() {
370
+ return this.pendingNewRowCount;
371
+ }
372
+
373
+ set pendingRowCount(count) {
374
+ if (count === this.pendingNewRowCount) {
375
+ return;
376
+ }
377
+
378
+ this.pendingNewRowCount = Math.max(0, count, this.maxPendingDataRow);
379
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
380
+ }
381
+
382
+ get maxPendingDataRow() {
383
+ return this.pendingNewDataMap.size > 0 ? Math.max(...this.pendingNewDataMap.keys()) + 1 : 0;
384
+ }
385
+
386
+ get columnCount() {
387
+ return this.columns.length;
388
+ }
389
+
390
+ get floatingBottomRowCount() {
391
+ var _this$totals2, _this$totals$operatio3, _this$totals3, _this$totals3$operati;
392
+
393
+ return (_this$totals2 = this.totals) !== null && _this$totals2 !== void 0 && _this$totals2.showOnTop ? 0 : (_this$totals$operatio3 = (_this$totals3 = this.totals) === null || _this$totals3 === void 0 ? void 0 : (_this$totals3$operati = _this$totals3.operationOrder) === null || _this$totals3$operati === void 0 ? void 0 : _this$totals3$operati.length) !== null && _this$totals$operatio3 !== void 0 ? _this$totals$operatio3 : 0;
394
+ }
395
+
396
+ get floatingTopRowCount() {
397
+ var _this$totals4, _this$totals$operatio4, _this$totals5, _this$totals5$operati;
398
+
399
+ return (_this$totals4 = this.totals) !== null && _this$totals4 !== void 0 && _this$totals4.showOnTop ? (_this$totals$operatio4 = (_this$totals5 = this.totals) === null || _this$totals5 === void 0 ? void 0 : (_this$totals5$operati = _this$totals5.operationOrder) === null || _this$totals5$operati === void 0 ? void 0 : _this$totals5$operati.length) !== null && _this$totals$operatio4 !== void 0 ? _this$totals$operatio4 : 0 : 0;
400
+ }
401
+
402
+ get isChartBuilderAvailable() {
403
+ return true;
404
+ }
405
+
406
+ get isTotalsAvailable() {
407
+ return this.table.getTotalsTable != null;
408
+ }
409
+
410
+ get isEditable() {
411
+ return !this.isSaveInProgress && this.inputTable != null;
412
+ }
413
+
414
+ cacheFormattedValue(x, y, text) {
415
+ if (this.formattedStringData[x] == null) {
416
+ this.formattedStringData[x] = [];
417
+ }
418
+
419
+ this.formattedStringData[x][y] = text;
420
+ }
421
+
422
+ cachePendingValue(x, y, text) {
423
+ if (this.pendingStringData[x] == null) {
424
+ this.pendingStringData[x] = [];
425
+ }
426
+
427
+ this.pendingStringData[x][y] = text;
428
+ }
429
+
430
+ clearPendingValue(x, y) {
431
+ var column = this.pendingStringData[x];
432
+
433
+ if (column != null) {
434
+ delete column[y];
435
+ }
436
+ }
437
+
438
+ textValueForCell(x, y) {
439
+ var _this$pendingStringDa, _this$formattedString;
440
+
441
+ // First check if there's any pending values we should read from
442
+ if (((_this$pendingStringDa = this.pendingStringData[x]) === null || _this$pendingStringDa === void 0 ? void 0 : _this$pendingStringDa[y]) !== undefined) {
443
+ return this.pendingStringData[x][y];
444
+ } // Use a separate cache from memoization just for the strings that are currently displayed
445
+
446
+
447
+ if (((_this$formattedString = this.formattedStringData[x]) === null || _this$formattedString === void 0 ? void 0 : _this$formattedString[y]) === undefined) {
448
+ var _this$totalsColumn;
449
+
450
+ var _value = this.valueForCell(x, y);
451
+
452
+ if (_value == null) {
453
+ return null;
454
+ }
455
+
456
+ var _column = (_this$totalsColumn = this.totalsColumn(x, y)) !== null && _this$totalsColumn !== void 0 ? _this$totalsColumn : this.columns[x];
457
+
458
+ var hasCustomColumnFormat = this.getCachedCustomColumnFormatFlag(this.formatter, _column.name, _column.type);
459
+ var formatOverride;
460
+
461
+ if (!hasCustomColumnFormat) {
462
+ var formatForCell = this.formatForCell(x, y);
463
+
464
+ if ((formatForCell === null || formatForCell === void 0 ? void 0 : formatForCell.formatString) != null) {
465
+ formatOverride = formatForCell;
466
+ }
467
+ }
468
+
469
+ var text = this.displayString(_value, _column.type, _column.name, formatOverride);
470
+ this.cacheFormattedValue(x, y, text);
471
+ }
472
+
473
+ return this.formattedStringData[x][y];
474
+ }
475
+
476
+ textForCell(x, y) {
477
+ var text = this.textValueForCell(x, y);
478
+
479
+ if (text == null && this.isKeyColumn(x)) {
480
+ var pendingRow = this.pendingRow(y);
481
+
482
+ if (pendingRow != null && this.pendingDataMap.has(pendingRow)) {
483
+ // Asterisk to show a value is required for a key column on a row that has some data entered
484
+ return '*';
485
+ }
486
+ }
487
+
488
+ return text !== null && text !== void 0 ? text : '';
489
+ }
490
+
491
+ truncationCharForCell(x) {
492
+ var column = this.columns[x];
493
+ var {
494
+ type
495
+ } = column;
496
+
497
+ if (TableUtils.isNumberType(type) && this.formatter.truncateNumbersWithPound) {
498
+ return '#';
499
+ }
500
+
501
+ return undefined;
502
+ }
503
+
504
+ colorForCell(x, y, theme) {
505
+ var data = this.dataForCell(x, y);
506
+
507
+ if (data) {
508
+ var {
509
+ format,
510
+ value: _value2
511
+ } = data;
512
+
513
+ if (_value2 == null || _value2 === '') {
514
+ assertNotNull(theme.nullStringColor);
515
+ return theme.nullStringColor;
516
+ }
517
+
518
+ if (format && format.color) {
519
+ return format.color;
520
+ }
521
+
522
+ if (this.isPendingRow(y)) {
523
+ // Data entered in a pending row
524
+ assertNotNull(theme.pendingTextColor);
525
+ return theme.pendingTextColor;
526
+ } // Fallback to formatting based on the value/type of the cell
527
+
528
+
529
+ if (_value2 != null) {
530
+ var _this$totalsColumn2;
531
+
532
+ var _column2 = (_this$totalsColumn2 = this.totalsColumn(x, y)) !== null && _this$totalsColumn2 !== void 0 ? _this$totalsColumn2 : this.columns[x];
533
+
534
+ if (TableUtils.isDateType(_column2.type) || _column2.name === 'Date') {
535
+ assertNotNull(theme.dateColor);
536
+ return theme.dateColor;
537
+ }
538
+
539
+ if (TableUtils.isNumberType(_column2.type)) {
540
+ if (_value2 > 0) {
541
+ assertNotNull(theme.positiveNumberColor);
542
+ return theme.positiveNumberColor;
543
+ }
544
+
545
+ if (_value2 < 0) {
546
+ assertNotNull(theme.negativeNumberColor);
547
+ return theme.negativeNumberColor;
548
+ }
549
+
550
+ assertNotNull(theme.zeroNumberColor);
551
+ return theme.zeroNumberColor;
552
+ }
553
+ }
554
+ } else if (this.isPendingRow(y) && this.isKeyColumn(x)) {
555
+ assertNotNull(theme.errorTextColor);
556
+ return theme.errorTextColor;
557
+ }
558
+
559
+ return theme.textColor;
560
+ }
561
+
562
+ backgroundColorForCell(x, y) {
563
+ var _this$formatForCell$b, _this$formatForCell;
564
+
565
+ return (_this$formatForCell$b = (_this$formatForCell = this.formatForCell(x, y)) === null || _this$formatForCell === void 0 ? void 0 : _this$formatForCell.backgroundColor) !== null && _this$formatForCell$b !== void 0 ? _this$formatForCell$b : null;
566
+ }
567
+
568
+ textAlignForCell(x) {
569
+ var column = this.columns[x];
570
+ var {
571
+ type
572
+ } = column;
573
+
574
+ if (TableUtils.isNumberType(type)) {
575
+ return 'right';
576
+ }
577
+
578
+ if (TableUtils.isDateType(type) || column.name === 'Date') {
579
+ return 'center';
580
+ }
581
+
582
+ return 'left';
583
+ }
584
+
585
+ textForColumnHeader(x) {
586
+ var column = this.columns[x];
587
+ return "".concat(column.name);
588
+ }
589
+
590
+ textForRowFooter(y) {
591
+ var totalsRow = this.totalsRow(y);
592
+
593
+ if (totalsRow != null && this.totals) {
594
+ return this.totals.operationOrder[totalsRow];
595
+ }
596
+
597
+ return '';
598
+ }
599
+
600
+ get columnMap() {
601
+ return this.getMemoizedColumnMap(this.table.columns);
602
+ }
603
+
604
+ get groupedColumns() {
605
+ return [];
606
+ }
607
+
608
+ row(y) {
609
+ var _this$totals$operatio5, _this$totals6, _this$totals6$operati, _this$totals$showOnTo, _this$totals7, _this$viewportData$of, _this$viewportData, _this$viewportData$ro, _this$viewportData2, _this$viewportData2$r;
610
+
611
+ var totalsRowCount = (_this$totals$operatio5 = (_this$totals6 = this.totals) === null || _this$totals6 === void 0 ? void 0 : (_this$totals6$operati = _this$totals6.operationOrder) === null || _this$totals6$operati === void 0 ? void 0 : _this$totals6$operati.length) !== null && _this$totals$operatio5 !== void 0 ? _this$totals$operatio5 : 0;
612
+ var showOnTop = (_this$totals$showOnTo = (_this$totals7 = this.totals) === null || _this$totals7 === void 0 ? void 0 : _this$totals7.showOnTop) !== null && _this$totals$showOnTo !== void 0 ? _this$totals$showOnTo : false;
613
+ var totalsRow = this.totalsRow(y);
614
+
615
+ if (totalsRow != null) {
616
+ var _this$totals8, _this$totalsDataMap$g, _this$totalsDataMap;
617
+
618
+ var operation = (_this$totals8 = this.totals) === null || _this$totals8 === void 0 ? void 0 : _this$totals8.operationOrder[totalsRow];
619
+ assertNotNull(operation);
620
+ return (_this$totalsDataMap$g = (_this$totalsDataMap = this.totalsDataMap) === null || _this$totalsDataMap === void 0 ? void 0 : _this$totalsDataMap.get(operation)) !== null && _this$totalsDataMap$g !== void 0 ? _this$totalsDataMap$g : null;
621
+ }
622
+
623
+ var pendingRow = this.pendingRow(y);
624
+
625
+ if (pendingRow != null) {
626
+ var _this$pendingNewDataM;
627
+
628
+ return (_this$pendingNewDataM = this.pendingNewDataMap.get(pendingRow)) !== null && _this$pendingNewDataM !== void 0 ? _this$pendingNewDataM : null;
629
+ }
630
+
631
+ var offset = (_this$viewportData$of = (_this$viewportData = this.viewportData) === null || _this$viewportData === void 0 ? void 0 : _this$viewportData.offset) !== null && _this$viewportData$of !== void 0 ? _this$viewportData$of : 0;
632
+ var viewportY = (showOnTop ? y - totalsRowCount : y) - offset;
633
+ return (_this$viewportData$ro = (_this$viewportData2 = this.viewportData) === null || _this$viewportData2 === void 0 ? void 0 : (_this$viewportData2$r = _this$viewportData2.rows) === null || _this$viewportData2$r === void 0 ? void 0 : _this$viewportData2$r[viewportY]) !== null && _this$viewportData$ro !== void 0 ? _this$viewportData$ro : null;
634
+ }
635
+ /**
636
+ * Retrieve the totals column if this is a totals row, or null otherwise
637
+ * @param x Column index to get the totals column from
638
+ * @param y Row index to get the totals column from
639
+ */
640
+
641
+
642
+ totalsColumn(x, y) {
643
+ var _this$totals9, _this$totals$defaultO, _this$totals10, _this$totalsTable;
644
+
645
+ var totalsRow = this.totalsRow(y);
646
+ if (totalsRow == null) return null;
647
+ var operation = (_this$totals9 = this.totals) === null || _this$totals9 === void 0 ? void 0 : _this$totals9.operationOrder[totalsRow];
648
+ var defaultOperation = (_this$totals$defaultO = (_this$totals10 = this.totals) === null || _this$totals10 === void 0 ? void 0 : _this$totals10.defaultOperation) !== null && _this$totals$defaultO !== void 0 ? _this$totals$defaultO : AggregationOperation.SUM;
649
+ var tableColumn = this.columns[x]; // Find the matching totals table column for the operation
650
+ // When there are multiple aggregations, the column name will be the original name of the column with the operation appended afterward
651
+ // When the the operation is the default operation OR there is only one operation, then the totals column name is just the original column name
652
+
653
+ return (_this$totalsTable = this.totalsTable) === null || _this$totalsTable === void 0 ? void 0 : _this$totalsTable.columns.find(column => {
654
+ var _this$totals11;
655
+
656
+ return column.name === "".concat(tableColumn.name, "__").concat(operation) || (operation === defaultOperation || ((_this$totals11 = this.totals) === null || _this$totals11 === void 0 ? void 0 : _this$totals11.operationOrder.length) === 1) && column.name === tableColumn.name;
657
+ });
658
+ }
659
+ /**
660
+ * Translate from the row in the model to a row in the totals table.
661
+ * If the row is not a totals row, return null
662
+ * @param y The row in the model to get the totals row for
663
+ * @returns The row within the totals table if it's a totals row, null otherwise
664
+ */
665
+
666
+
667
+ totalsRow(y) {
668
+ var _this$totals$operatio6, _this$totals12, _this$totals12$operat, _this$totals$showOnTo2, _this$totals13;
669
+
670
+ var totalsRowCount = (_this$totals$operatio6 = (_this$totals12 = this.totals) === null || _this$totals12 === void 0 ? void 0 : (_this$totals12$operat = _this$totals12.operationOrder) === null || _this$totals12$operat === void 0 ? void 0 : _this$totals12$operat.length) !== null && _this$totals$operatio6 !== void 0 ? _this$totals$operatio6 : 0;
671
+ var showOnTop = (_this$totals$showOnTo2 = (_this$totals13 = this.totals) === null || _this$totals13 === void 0 ? void 0 : _this$totals13.showOnTop) !== null && _this$totals$showOnTo2 !== void 0 ? _this$totals$showOnTo2 : false;
672
+ var totalsRow = showOnTop ? y : y - this.table.size;
673
+
674
+ if (totalsRow >= 0 && totalsRow < totalsRowCount) {
675
+ return totalsRow;
676
+ }
677
+
678
+ return null;
679
+ }
680
+ /**
681
+ * Translate from the row in the model to a pending input row.
682
+ * If the row is not a pending input row, return null
683
+ * @param y The row in the model to get the pending row for
684
+ * @returns The row within the pending input rows if it's a pending row, null otherwise
685
+ */
686
+
687
+
688
+ pendingRow(y) {
689
+ var pendingRow = y - this.floatingTopRowCount - this.table.size;
690
+
691
+ if (pendingRow >= 0 && pendingRow < this.pendingNewRowCount) {
692
+ return pendingRow;
693
+ }
694
+
695
+ return null;
696
+ }
697
+ /**
698
+ * Check if a row is a totals table row
699
+ * @param y The row in the model to check if it's a totals table row
700
+ * @returns True if the row is a totals row, false if not
701
+ */
702
+
703
+
704
+ isTotalsRow(y) {
705
+ return this.totalsRow(y) != null;
706
+ }
707
+ /**
708
+ * Check if a row is a pending input row
709
+ * @param y The row in the model to check if it's a pending new row
710
+ * @returns True if the row is a pending new row, false if not
711
+ */
712
+
713
+
714
+ isPendingRow(y) {
715
+ return this.pendingRow(y) != null;
716
+ }
717
+
718
+ dataForCell(x, y) {
719
+ var _this$row;
720
+
721
+ return (_this$row = this.row(y)) === null || _this$row === void 0 ? void 0 : _this$row.data.get(x);
722
+ }
723
+
724
+ formatForCell(x, y) {
725
+ var _this$dataForCell;
726
+
727
+ return (_this$dataForCell = this.dataForCell(x, y)) === null || _this$dataForCell === void 0 ? void 0 : _this$dataForCell.format;
728
+ }
729
+
730
+ valueForCell(x, y) {
731
+ var data = this.dataForCell(x, y);
732
+
733
+ if (data) {
734
+ var _data$value;
735
+
736
+ return (_data$value = data.value) !== null && _data$value !== void 0 ? _data$value : null;
737
+ }
738
+
739
+ return null;
740
+ }
741
+
742
+ copyViewportData(data) {
743
+ if (!data) {
744
+ log.warn('invalid data!');
745
+ return;
746
+ }
747
+
748
+ this.viewportData = this.extractViewportData(data);
749
+ this.formattedStringData = [];
750
+ }
751
+
752
+ copyTotalsData(totalsData) {
753
+ var _this$totals$defaultO2,
754
+ _this$totals14,
755
+ _this$totals15,
756
+ _this = this;
757
+
758
+ if (!totalsData) {
759
+ log.warn('invalid data!');
760
+ return;
761
+ }
762
+
763
+ var {
764
+ columns,
765
+ rows
766
+ } = totalsData;
767
+
768
+ if (rows.length !== 1) {
769
+ log.error('Unexpected number of rows received for totals table, ignoring update');
770
+ return;
771
+ }
772
+
773
+ var dataMap = new Map();
774
+ var row = rows[0];
775
+ var defaultOperation = (_this$totals$defaultO2 = (_this$totals14 = this.totals) === null || _this$totals14 === void 0 ? void 0 : _this$totals14.defaultOperation) !== null && _this$totals$defaultO2 !== void 0 ? _this$totals$defaultO2 : AggregationOperation.SUM;
776
+ var operationMap = (_this$totals15 = this.totals) === null || _this$totals15 === void 0 ? void 0 : _this$totals15.operationMap;
777
+
778
+ var _loop = function _loop(c) {
779
+ var _operationMap$name$, _operationMap$name;
780
+
781
+ var column = columns[c];
782
+ var [name, operation = (_operationMap$name$ = operationMap === null || operationMap === void 0 ? void 0 : (_operationMap$name = operationMap[name]) === null || _operationMap$name === void 0 ? void 0 : _operationMap$name[0]) !== null && _operationMap$name$ !== void 0 ? _operationMap$name$ : defaultOperation] = column.name.split('__');
783
+
784
+ if (!dataMap.has(operation)) {
785
+ dataMap.set(operation, {
786
+ data: new Map()
787
+ });
788
+ }
789
+
790
+ var {
791
+ data: rowData
792
+ } = dataMap.get(operation);
793
+
794
+ var columnIndex = _this.columns.findIndex(col => col.name === name);
795
+
796
+ rowData.set(columnIndex, {
797
+ value: row.get(column),
798
+ format: row.getFormat(column)
799
+ });
800
+ };
801
+
802
+ for (var c = 0; c < columns.length; c += 1) {
803
+ _loop(c);
804
+ }
805
+
806
+ log.debug2('copyTotalsData', dataMap);
807
+ this.totalsDataMap = dataMap;
808
+ this.formattedStringData = [];
809
+ }
810
+ /**
811
+ * Use this as the canonical column index since things like layoutHints could have
812
+ * changed the column order.
813
+ */
814
+
815
+
816
+ getColumnIndexByName(name) {
817
+ return this.getColumnIndicesByNameMap(this.columns).get(name);
818
+ }
819
+
820
+ /**
821
+ * Copies all the viewport data into an object that we can reference later.
822
+ * @param data The data to copy from
823
+ */
824
+ extractViewportData(data) {
825
+ var newData = {
826
+ offset: data.offset,
827
+ rows: []
828
+ };
829
+ var {
830
+ columns
831
+ } = data;
832
+
833
+ for (var r = 0; r < data.rows.length; r += 1) {
834
+ var _row = data.rows[r];
835
+ var newRow = this.extractViewportRow(_row, columns);
836
+ newData.rows.push(newRow);
837
+ }
838
+
839
+ return newData;
840
+ }
841
+
842
+ extractViewportRow(row, columns) {
843
+ var data = new Map();
844
+
845
+ for (var c = 0; c < columns.length; c += 1) {
846
+ var _column3 = columns[c];
847
+ var index = this.getColumnIndexByName(_column3.name);
848
+ assertNotNull(index);
849
+ data.set(index, {
850
+ value: row.get(_column3),
851
+ format: row.getFormat(_column3)
852
+ });
853
+ }
854
+
855
+ return {
856
+ data
857
+ };
858
+ }
859
+
860
+ closeSubscription() {
861
+ log.debug2('closeSubscription', this.subscription);
862
+
863
+ if (this.subscription) {
864
+ this.subscription.close();
865
+ this.subscription = null;
866
+ }
867
+
868
+ this.setViewport.cancel();
869
+ this.applyViewport.cancel();
870
+ }
871
+
872
+ get filter() {
873
+ return this.table.filter;
874
+ }
875
+
876
+ set filter(filter) {
877
+ this.closeSubscription();
878
+ this.table.applyFilter(filter);
879
+ this.applyViewport();
880
+ }
881
+
882
+ get formatter() {
883
+ return this.irisFormatter;
884
+ }
885
+
886
+ set formatter(formatter) {
887
+ this.irisFormatter = formatter;
888
+ this.formattedStringData = [];
889
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.FORMATTER_UPDATED));
890
+ }
891
+
892
+ displayString(value, columnType) {
893
+ var columnName = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
894
+ var formatOverride = arguments.length > 3 ? arguments[3] : undefined;
895
+ return this.getCachedFormattedString(this.formatter, value, columnType, columnName, formatOverride);
896
+ }
897
+
898
+ get sort() {
899
+ return this.table.sort;
900
+ }
901
+
902
+ set sort(sort) {
903
+ this.closeSubscription();
904
+ this.table.applySort(sort);
905
+ this.applyViewport();
906
+ }
907
+
908
+ set totalsConfig(totalsConfig) {
909
+ log.debug('set totalsConfig', totalsConfig);
910
+
911
+ if (totalsConfig === this.totals) {
912
+ // Totals already set, or it will be set when the next model actually gets set
913
+ return;
914
+ }
915
+
916
+ this.totals = totalsConfig;
917
+ this.formattedStringData = [];
918
+
919
+ if (this.totalsTablePromise != null) {
920
+ this.totalsTablePromise.cancel();
921
+ }
922
+
923
+ this.setTotalsTable(null);
924
+
925
+ if (totalsConfig == null) {
926
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
927
+ return;
928
+ }
929
+
930
+ this.totalsTablePromise = PromiseUtils.makeCancelable(this.table.getTotalsTable(totalsConfig), table => table.close());
931
+ this.totalsTablePromise.then(totalsTable => {
932
+ this.totalsTablePromise = null;
933
+ this.setTotalsTable(totalsTable);
934
+ }).catch(err => {
935
+ if (PromiseUtils.isCanceled(err)) {
936
+ return;
937
+ }
938
+
939
+ log.error('Unable to set next totalsTable', err);
940
+ this.totalsTablePromise = null;
941
+ this.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.REQUEST_FAILED, {
942
+ detail: err
943
+ }));
944
+ });
945
+ }
946
+
947
+ setTotalsTable(totalsTable) {
948
+ log.debug('setTotalsTable', totalsTable);
949
+
950
+ if (this.totalsTable !== null) {
951
+ if (this.listenerCount > 0) {
952
+ this.removeTotalsListeners(this.totalsTable);
953
+ }
954
+
955
+ this.totalsTable.close();
956
+ }
957
+
958
+ this.totalsTable = totalsTable;
959
+ this.totalsDataMap = null;
960
+
961
+ if (this.listenerCount > 0 && this.totalsTable != null) {
962
+ this.addTotalsListeners(this.totalsTable);
963
+ }
964
+ }
965
+
966
+ applyBufferedViewport(viewportTop, viewportBottom, columns) {
967
+ log.debug2('applyBufferedViewport', viewportTop, viewportBottom, columns);
968
+
969
+ if (this.subscription == null) {
970
+ log.debug2('applyBufferedViewport creating new subscription');
971
+ this.subscription = this.table.setViewport(viewportTop, viewportBottom, columns);
972
+ } else {
973
+ log.debug2('applyBufferedViewport using existing subscription');
974
+ this.subscription.setViewport(viewportTop, viewportBottom, columns);
975
+ }
976
+ }
977
+
978
+ snapshot(ranges) {
979
+ var _arguments = arguments,
980
+ _this2 = this;
981
+
982
+ return _asyncToGenerator(function* () {
983
+ var includeHeaders = _arguments.length > 1 && _arguments[1] !== undefined ? _arguments[1] : false;
984
+ var formatValue = _arguments.length > 2 && _arguments[2] !== undefined ? _arguments[2] : value => value;
985
+
986
+ if (_this2.subscription == null) {
987
+ throw new Error('No subscription available');
988
+ }
989
+
990
+ var consolidated = GridRange.consolidate(ranges);
991
+
992
+ if (!IrisGridUtils.isValidSnapshotRanges(consolidated)) {
993
+ throw new Error("Invalid snapshot ranges ".concat(ranges));
994
+ } // Need to separate out the floating ranges as they're from a different source
995
+
996
+
997
+ var topFloatingRowsSet = new Set();
998
+ var tableRanges = [];
999
+ var bottomFloatingRowsSet = new Set();
1000
+
1001
+ for (var i = 0; i < consolidated.length; i += 1) {
1002
+ var range = consolidated[i];
1003
+ assertNotNull(range.endRow);
1004
+ assertNotNull(range.startRow); // Get the rows that are in the top aggregations section
1005
+
1006
+ for (var r = range.startRow; r <= range.endRow && r < _this2.floatingTopRowCount; r += 1) {
1007
+ topFloatingRowsSet.add(r);
1008
+ } // Separate out the range that is part of the actual table (ie. not the floating ranges, not aggregations)
1009
+
1010
+
1011
+ if (range.endRow >= _this2.floatingTopRowCount && range.startRow <= _this2.floatingTopRowCount + _this2.table.size) {
1012
+ tableRanges.push(new GridRange(range.startColumn, Math.min(Math.max(0, range.startRow - _this2.floatingTopRowCount)), range.endColumn, Math.min(Math.max(0, range.endRow - _this2.floatingTopRowCount), _this2.table.size - _this2.floatingTopRowCount)));
1013
+ } // Get the rows that are in the bottom aggregations section
1014
+
1015
+
1016
+ for (var _r = Math.max(range.startRow, _this2.floatingTopRowCount + _this2.table.size); _r <= range.endRow && _r < _this2.floatingTopRowCount + _this2.table.size + _this2.floatingBottomRowCount; _r += 1) {
1017
+ bottomFloatingRowsSet.add(_r);
1018
+ }
1019
+ }
1020
+
1021
+ var columns = IrisGridUtils.columnsFromRanges(consolidated, _this2.columns);
1022
+ var result = [];
1023
+
1024
+ if (includeHeaders) {
1025
+ result.push(columns.map(c => c.name));
1026
+ }
1027
+
1028
+ var topFloatingRows = [...topFloatingRowsSet].sort();
1029
+
1030
+ var _loop2 = function _loop2(_i) {
1031
+ var row = topFloatingRows[_i];
1032
+ var rowData = columns.map(column => {
1033
+ var index = _this2.getColumnIndexByName(column.name);
1034
+
1035
+ assertNotNull(index);
1036
+ return formatValue(_this2.valueForCell(index, row), column);
1037
+ });
1038
+
1039
+ if (includeHeaders) {
1040
+ rowData.push(_this2.textForRowFooter(row));
1041
+ }
1042
+
1043
+ result.push(rowData);
1044
+ };
1045
+
1046
+ for (var _i = 0; _i < topFloatingRows.length; _i += 1) {
1047
+ _loop2(_i);
1048
+ }
1049
+
1050
+ if (tableRanges.length > 0) {
1051
+ var rangeSet = IrisGridUtils.rangeSetFromRanges(tableRanges);
1052
+ var snapshot = yield _this2.subscription.snapshot(rangeSet, columns);
1053
+ result.push(...snapshot.rows.map(rowData => columns.map(column => formatValue(rowData.get(column), column))));
1054
+ }
1055
+
1056
+ var bottomFloatingRows = [...bottomFloatingRowsSet].sort();
1057
+
1058
+ var _loop3 = function _loop3(_i2) {
1059
+ var row = bottomFloatingRows[_i2];
1060
+ var rowData = columns.map(column => {
1061
+ var index = _this2.getColumnIndexByName(column.name);
1062
+
1063
+ assertNotNull(index);
1064
+ return formatValue(_this2.valueForCell(index, row), column);
1065
+ });
1066
+
1067
+ if (includeHeaders) {
1068
+ rowData.push(_this2.textForRowFooter(row));
1069
+ }
1070
+
1071
+ result.push(rowData);
1072
+ };
1073
+
1074
+ for (var _i2 = 0; _i2 < bottomFloatingRows.length; _i2 += 1) {
1075
+ _loop3(_i2);
1076
+ }
1077
+
1078
+ return result;
1079
+ })();
1080
+ }
1081
+ /**
1082
+ * Get a text snapshot of the provided ranges
1083
+ * @param ranges The ranges to get the snapshot for
1084
+ * @param includeHeaders Whether to include the headers in the snapshot or not
1085
+ * @param formatValue Function for formatting the raw value into a string
1086
+ * @returns A formatted string of all the data, columns separated by `\t` and rows separated by `\n`
1087
+ */
1088
+
1089
+
1090
+ textSnapshot(ranges) {
1091
+ var _arguments2 = arguments,
1092
+ _this3 = this;
1093
+
1094
+ return _asyncToGenerator(function* () {
1095
+ var includeHeaders = _arguments2.length > 1 && _arguments2[1] !== undefined ? _arguments2[1] : false;
1096
+ var formatValue = _arguments2.length > 2 && _arguments2[2] !== undefined ? _arguments2[2] : value => "".concat(value);
1097
+ log.debug2('textSnapshot', ranges, includeHeaders);
1098
+ var data = yield _this3.snapshot(ranges, includeHeaders, formatValue);
1099
+ return data.map(row => row.join('\t')).join('\n');
1100
+ })();
1101
+ }
1102
+
1103
+ valuesTable(column) {
1104
+ var _this4 = this;
1105
+
1106
+ return _asyncToGenerator(function* () {
1107
+ var table = null;
1108
+
1109
+ try {
1110
+ table = yield _this4.table.copy();
1111
+ table.applyFilter([]);
1112
+ table.applySort([]);
1113
+ return table.selectDistinct([column]);
1114
+ } finally {
1115
+ if (table != null) {
1116
+ table.close();
1117
+ }
1118
+ }
1119
+ })();
1120
+ }
1121
+
1122
+ isKeyColumn(x) {
1123
+ var _this$inputTable$keyC2, _this$inputTable2;
1124
+
1125
+ return x < ((_this$inputTable$keyC2 = (_this$inputTable2 = this.inputTable) === null || _this$inputTable2 === void 0 ? void 0 : _this$inputTable2.keyColumns.length) !== null && _this$inputTable$keyC2 !== void 0 ? _this$inputTable$keyC2 : 0);
1126
+ }
1127
+
1128
+ isRowMovable() {
1129
+ return false;
1130
+ }
1131
+
1132
+ isEditableRange(range) {
1133
+ return this.inputTable != null && GridRange.isBounded(range) && (this.isPendingRow(range.startRow) && this.isPendingRow(range.endRow) || range.startColumn >= this.inputTable.keyColumns.length && range.endColumn >= this.inputTable.keyColumns.length) && range.startRow >= this.floatingTopRowCount && range.startRow < this.floatingTopRowCount + this.table.size + this.pendingRowCount && range.endRow < this.floatingTopRowCount + this.table.size + this.pendingRowCount;
1134
+ }
1135
+
1136
+ isDeletableRange(range) {
1137
+ return this.inputTable != null && range.startRow != null && range.endRow != null && range.startRow >= this.floatingTopRowCount && range.startRow < this.floatingTopRowCount + this.table.size + this.pendingRowCount && range.endRow < this.floatingTopRowCount + this.table.size + this.pendingRowCount;
1138
+ }
1139
+
1140
+ isEditableRanges(ranges) {
1141
+ return ranges.every(range => this.isEditableRange(range));
1142
+ }
1143
+
1144
+ isDeletableRanges(ranges) {
1145
+ return ranges.every(range => this.isDeletableRange(range));
1146
+ }
1147
+ /**
1148
+ * @returns A range corresponding to the underlying table
1149
+ */
1150
+
1151
+
1152
+ getTableAreaRange() {
1153
+ return new GridRange(null, this.floatingTopRowCount, null, this.floatingTopRowCount + this.table.size - 1);
1154
+ }
1155
+ /**
1156
+ * @returns {GridRange} A range corresponding to the pending new rows
1157
+ */
1158
+
1159
+
1160
+ getPendingAreaRange() {
1161
+ return new GridRange(null, this.floatingTopRowCount + this.table.size, null, this.floatingTopRowCount + this.table.size + this.pendingNewRowCount - 1);
1162
+ }
1163
+ /**
1164
+ * Set value in an editable table
1165
+ * @param x The column to set
1166
+ * @param y The row to set
1167
+ * @param value The value to set
1168
+ * @returns A promise that resolves successfully when the operation is complete, or rejects if there's an error
1169
+ */
1170
+
1171
+
1172
+ setValueForCell(x, y, text) {
1173
+ var _this5 = this;
1174
+
1175
+ return _asyncToGenerator(function* () {
1176
+ // Cache the value in our pending string cache so that it stays displayed until our edit has been completed
1177
+ return _this5.setValueForRanges([new GridRange(x, y, x, y)], text);
1178
+ })();
1179
+ }
1180
+ /**
1181
+ * Set value in an editable table
1182
+ * @param ranges The ranges to set
1183
+ * @param value The values to set
1184
+ * @returns A promise that resolves successfully when the operation is complete, or rejects if there's an error
1185
+ */
1186
+
1187
+
1188
+ setValueForRanges(ranges, text) {
1189
+ var _this6 = this;
1190
+
1191
+ return _asyncToGenerator(function* () {
1192
+ if (!_this6.isEditableRanges(ranges)) {
1193
+ throw new Error("Uneditable ranges ".concat(ranges));
1194
+ }
1195
+
1196
+ try {
1197
+ // Cache the value in our pending string cache so that it stays displayed until our edit has been completed
1198
+ var columnSet = new Set(); // Formatted text for each column
1199
+ // Since there could be different formatting for each column, but the value will be the same across rows
1200
+
1201
+ var formattedText = [];
1202
+ GridRange.forEachCell(ranges, (x, y) => {
1203
+ var column = _this6.columns[x];
1204
+ columnSet.add(column);
1205
+
1206
+ if (formattedText[x] === undefined) {
1207
+ var _value3 = TableUtils.makeValue(column.type, text, _this6.formatter.timeZone);
1208
+
1209
+ formattedText[x] = _value3 != null ? _this6.displayString(_value3, column.type, column.name) : null;
1210
+ }
1211
+
1212
+ _this6.cachePendingValue(x, y, formattedText[x]);
1213
+ }); // Take care of updates to the pending new area first, as they can be updated synchronously
1214
+
1215
+ var pendingAreaRange = _this6.getPendingAreaRange();
1216
+
1217
+ var pendingRanges = ranges.map(range => GridRange.intersection(pendingAreaRange, range)).filter(range => range != null).map(range => {
1218
+ assertNotNull(range);
1219
+ return GridRange.offset(range, 0, -(_this6.floatingTopRowCount + _this6.table.size));
1220
+ });
1221
+
1222
+ if (pendingRanges.length > 0) {
1223
+ var newDataMap = new Map(_this6.pendingNewDataMap);
1224
+ GridRange.forEachCell(pendingRanges, (columnIndex, rowIndex) => {
1225
+ if (!newDataMap.has(rowIndex)) {
1226
+ newDataMap.set(rowIndex, {
1227
+ data: new Map()
1228
+ });
1229
+ }
1230
+
1231
+ var column = _this6.columns[columnIndex];
1232
+ var row = newDataMap.get(rowIndex);
1233
+ assertNotNull(row);
1234
+ var {
1235
+ data: rowData
1236
+ } = row;
1237
+ var newRowData = new Map(rowData);
1238
+ var value = TableUtils.makeValue(column.type, text, _this6.formatter.timeZone);
1239
+
1240
+ if (value != null) {
1241
+ newRowData.set(columnIndex, {
1242
+ value
1243
+ });
1244
+ } else {
1245
+ newRowData.delete(columnIndex);
1246
+ }
1247
+
1248
+ if (newRowData.size > 0) {
1249
+ newDataMap.set(rowIndex, _objectSpread(_objectSpread({}, row), {}, {
1250
+ data: newRowData
1251
+ }));
1252
+ } else {
1253
+ newDataMap.delete(rowIndex);
1254
+ }
1255
+ });
1256
+ _this6.pendingDataMap = newDataMap;
1257
+ }
1258
+
1259
+ _this6.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
1260
+
1261
+ var tableAreaRange = _this6.getTableAreaRange();
1262
+
1263
+ var tableRanges = ranges.map(range => GridRange.intersection(tableAreaRange, range)).filter(range => range != null);
1264
+
1265
+ if (tableRanges.length > 0) {
1266
+ var _this6$inputTable;
1267
+
1268
+ // Get a snapshot of the full rows, as we need to write a full row when editing
1269
+ var data = yield _this6.snapshot(tableRanges.map(range => {
1270
+ var _range$startRow, _range$endRow;
1271
+
1272
+ return new GridRange(null, (_range$startRow = range === null || range === void 0 ? void 0 : range.startRow) !== null && _range$startRow !== void 0 ? _range$startRow : null, null, (_range$endRow = range === null || range === void 0 ? void 0 : range.endRow) !== null && _range$endRow !== void 0 ? _range$endRow : null);
1273
+ }));
1274
+ var newRows = data.map(row => {
1275
+ var newRow = {};
1276
+
1277
+ for (var c = 0; c < _this6.columns.length; c += 1) {
1278
+ newRow[_this6.columns[c].name] = row[c];
1279
+ }
1280
+
1281
+ columnSet.forEach(column => {
1282
+ newRow[column.name] = TableUtils.makeValue(column.type, text, _this6.formatter.timeZone);
1283
+ });
1284
+ return newRow;
1285
+ });
1286
+ var result = yield (_this6$inputTable = _this6.inputTable) === null || _this6$inputTable === void 0 ? void 0 : _this6$inputTable.addRows(newRows);
1287
+ log.debug('setValueForRanges(', ranges, ',', text, ') set tableRanges', tableRanges, 'result', result);
1288
+ } // Add the changes to the formatted cache so it's still displayed until the update event is received
1289
+ // The update event could be received on the next tick, after the input rows have been committed,
1290
+ // so make sure we don't display stale data
1291
+
1292
+
1293
+ GridRange.forEachCell(ranges, (x, y) => {
1294
+ var cellText = formattedText[x];
1295
+ assertNotNull(cellText);
1296
+
1297
+ _this6.cacheFormattedValue(x, y, cellText);
1298
+ });
1299
+ } catch (err) {
1300
+ log.error('Unable to set ranges', ranges, text, err);
1301
+ } finally {
1302
+ GridRange.forEachCell(ranges, (x, y) => {
1303
+ _this6.clearPendingValue(x, y);
1304
+ });
1305
+ }
1306
+ })();
1307
+ }
1308
+
1309
+ setValues() {
1310
+ var _arguments3 = arguments,
1311
+ _this7 = this;
1312
+
1313
+ return _asyncToGenerator(function* () {
1314
+ var edits = _arguments3.length > 0 && _arguments3[0] !== undefined ? _arguments3[0] : [];
1315
+ log.debug('setValues(', edits, ')');
1316
+
1317
+ if (!edits.every(edit => {
1318
+ var _edit$column, _edit$row;
1319
+
1320
+ return _this7.isEditableRange(GridRange.makeCell((_edit$column = edit.column) !== null && _edit$column !== void 0 ? _edit$column : edit.x, (_edit$row = edit.row) !== null && _edit$row !== void 0 ? _edit$row : edit.y));
1321
+ })) {
1322
+ throw new Error("Uneditable ranges ".concat(edits));
1323
+ }
1324
+
1325
+ try {
1326
+ var newDataMap = new Map(_this7.pendingNewDataMap); // Cache the display values
1327
+
1328
+ edits.forEach(edit => {
1329
+ var _edit$column2, _edit$row2;
1330
+
1331
+ var {
1332
+ text
1333
+ } = edit;
1334
+ var x = (_edit$column2 = edit.column) !== null && _edit$column2 !== void 0 ? _edit$column2 : edit.x;
1335
+ var y = (_edit$row2 = edit.row) !== null && _edit$row2 !== void 0 ? _edit$row2 : edit.y;
1336
+ var column = _this7.columns[x];
1337
+ var value = TableUtils.makeValue(column.type, text, _this7.formatter.timeZone);
1338
+ var formattedText = value != null ? _this7.displayString(value, column.type, column.name) : null;
1339
+
1340
+ _this7.cachePendingValue(x, y, formattedText); // Take care of updates to the pending new area as well, as that can be updated synchronously
1341
+
1342
+
1343
+ var pendingRow = _this7.pendingRow(y);
1344
+
1345
+ if (pendingRow != null) {
1346
+ if (!newDataMap.has(pendingRow)) {
1347
+ newDataMap.set(pendingRow, {
1348
+ data: new Map()
1349
+ });
1350
+ }
1351
+
1352
+ var _row2 = newDataMap.get(pendingRow);
1353
+
1354
+ assertNotNull(_row2);
1355
+ var {
1356
+ data: rowData
1357
+ } = _row2;
1358
+ var newRowData = new Map(rowData);
1359
+
1360
+ if (value != null) {
1361
+ newRowData.set(x, {
1362
+ value
1363
+ });
1364
+ } else {
1365
+ newRowData.delete(x);
1366
+ }
1367
+
1368
+ if (newRowData.size > 0) {
1369
+ newDataMap.set(pendingRow, _objectSpread(_objectSpread({}, _row2), {}, {
1370
+ data: newRowData
1371
+ }));
1372
+ } else {
1373
+ newDataMap.delete(pendingRow);
1374
+ }
1375
+ }
1376
+ });
1377
+ _this7.pendingDataMap = newDataMap; // Send an update right after setting the pending map so the values are displayed immediately
1378
+
1379
+ _this7.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED)); // Need to group by row...
1380
+
1381
+
1382
+ var rowEditMap = edits.reduce((rowMap, edit) => {
1383
+ var _edit$row3, _rowMap$get;
1384
+
1385
+ var y = (_edit$row3 = edit.row) !== null && _edit$row3 !== void 0 ? _edit$row3 : edit.y;
1386
+
1387
+ if (!rowMap.has(y)) {
1388
+ rowMap.set(y, []);
1389
+ }
1390
+
1391
+ (_rowMap$get = rowMap.get(y)) === null || _rowMap$get === void 0 ? void 0 : _rowMap$get.push(edit);
1392
+ return rowMap;
1393
+ }, new Map());
1394
+ var ranges = GridRange.consolidate(edits.map(edit => {
1395
+ var _edit$column3, _edit$row4;
1396
+
1397
+ return GridRange.makeCell((_edit$column3 = edit.column) !== null && _edit$column3 !== void 0 ? _edit$column3 : edit.x, (_edit$row4 = edit.row) !== null && _edit$row4 !== void 0 ? _edit$row4 : edit.y);
1398
+ }));
1399
+
1400
+ var tableAreaRange = _this7.getTableAreaRange();
1401
+
1402
+ var tableRanges = ranges.map(range => GridRange.intersection(tableAreaRange, range)).filter(range => range != null);
1403
+
1404
+ if (tableRanges.length > 0) {
1405
+ var _this7$inputTable;
1406
+
1407
+ // Get a snapshot of the full rows, as we need to write a full row when editing
1408
+ var data = yield _this7.snapshot(tableRanges.map(range => {
1409
+ assertNotNull(range);
1410
+ return new GridRange(null, range.startRow, null, range.endRow);
1411
+ }));
1412
+ var newRows = data.map((row, dataIndex) => {
1413
+ var rowIndex = null;
1414
+ var r = dataIndex;
1415
+
1416
+ for (var i = 0; i < tableRanges.length; i += 1) {
1417
+ var range = tableRanges[i];
1418
+ assertNotNull(range);
1419
+ var rangeRowCount = GridRange.rowCount([range]);
1420
+
1421
+ if (r < rangeRowCount) {
1422
+ assertNotNull(range.startRow);
1423
+ rowIndex = range.startRow + r;
1424
+ break;
1425
+ }
1426
+
1427
+ r -= rangeRowCount;
1428
+ }
1429
+
1430
+ var newRow = {};
1431
+
1432
+ for (var c = 0; c < _this7.columns.length; c += 1) {
1433
+ newRow[_this7.columns[c].name] = row[c];
1434
+ }
1435
+
1436
+ assertNotNull(rowIndex);
1437
+ var rowEdits = rowEditMap.get(rowIndex);
1438
+
1439
+ if (rowEdits != null) {
1440
+ rowEdits.forEach(edit => {
1441
+ var _edit$column4;
1442
+
1443
+ var column = _this7.columns[(_edit$column4 = edit.column) !== null && _edit$column4 !== void 0 ? _edit$column4 : edit.x];
1444
+ newRow[column.name] = TableUtils.makeValue(column.type, edit.text, _this7.formatter.timeZone);
1445
+ });
1446
+ }
1447
+
1448
+ return newRow;
1449
+ });
1450
+ log.info('setValues setting tableRanges', tableRanges);
1451
+ var result = yield (_this7$inputTable = _this7.inputTable) === null || _this7$inputTable === void 0 ? void 0 : _this7$inputTable.addRows(newRows);
1452
+ log.info('setValues set tableRanges', tableRanges, 'SUCCESS', result);
1453
+ } // We've sent the changes to the server, but have not yet got an update with those changes committed
1454
+ // Add the changes to the formatted cache so it's still displayed until the update event is received
1455
+ // The update event could be received on the next tick, after the input rows have been committed,
1456
+ // so make sure we don't display stale data
1457
+
1458
+
1459
+ edits.forEach(edit => {
1460
+ var _edit$column5, _edit$row5;
1461
+
1462
+ var {
1463
+ text
1464
+ } = edit;
1465
+ var x = (_edit$column5 = edit.column) !== null && _edit$column5 !== void 0 ? _edit$column5 : edit.x;
1466
+ var y = (_edit$row5 = edit.row) !== null && _edit$row5 !== void 0 ? _edit$row5 : edit.y;
1467
+ var column = _this7.columns[x];
1468
+ var value = TableUtils.makeValue(column.type, text, _this7.formatter.timeZone);
1469
+ var formattedText = value != null ? _this7.displayString(value, column.type, column.name) : null;
1470
+
1471
+ _this7.cacheFormattedValue(x, y, formattedText);
1472
+ });
1473
+ } finally {
1474
+ edits.forEach(edit => {
1475
+ _this7.clearPendingValue(edit.column, edit.row);
1476
+ });
1477
+ }
1478
+ })();
1479
+ }
1480
+
1481
+ commitPending() {
1482
+ var _this8 = this;
1483
+
1484
+ return _asyncToGenerator(function* () {
1485
+ if (_this8.pendingNewDataMap.size <= 0) {
1486
+ throw new Error('No pending changes to commit');
1487
+ }
1488
+
1489
+ try {
1490
+ var _this8$inputTable, _this8$viewport$botto, _this8$viewport;
1491
+
1492
+ _this8.isSaveInProgress = true;
1493
+ var newRows = [];
1494
+
1495
+ _this8.pendingNewDataMap.forEach(row => {
1496
+ var newRow = {};
1497
+ row.data.forEach((_ref2, columnIndex) => {
1498
+ var {
1499
+ value
1500
+ } = _ref2;
1501
+ var column = _this8.columns[columnIndex];
1502
+ newRow[column.name] = value;
1503
+ });
1504
+ newRows.push(newRow);
1505
+ });
1506
+
1507
+ var result = yield (_this8$inputTable = _this8.inputTable) === null || _this8$inputTable === void 0 ? void 0 : _this8$inputTable.addRows(newRows);
1508
+ log.debug('commitPending()', _this8.pendingNewDataMap, 'result', result);
1509
+ _this8.pendingNewDataMap = new Map();
1510
+ _this8.pendingNewDataErrors = new Map();
1511
+ _this8.pendingNewRowCount = Math.max(0, ((_this8$viewport$botto = (_this8$viewport = _this8.viewport) === null || _this8$viewport === void 0 ? void 0 : _this8$viewport.bottom) !== null && _this8$viewport$botto !== void 0 ? _this8$viewport$botto : 0) - _this8.table.size);
1512
+ _this8.formattedStringData = [];
1513
+
1514
+ _this8.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.PENDING_DATA_UPDATED));
1515
+ } finally {
1516
+ _this8.isSaveInProgress = false;
1517
+ }
1518
+ })();
1519
+ }
1520
+
1521
+ editValueForCell(x, y) {
1522
+ return this.textValueForCell(x, y);
1523
+ }
1524
+
1525
+ delete(ranges) {
1526
+ var _this9 = this;
1527
+
1528
+ return _asyncToGenerator(function* () {
1529
+ if (!_this9.isDeletableRanges(ranges)) {
1530
+ throw new Error("Undeletable ranges ".concat(ranges));
1531
+ }
1532
+
1533
+ assertNotNull(_this9.inputTable);
1534
+ var {
1535
+ keyColumns
1536
+ } = _this9.inputTable;
1537
+
1538
+ if (keyColumns.length === 0) {
1539
+ throw new Error('No key columns to allow deletion');
1540
+ }
1541
+
1542
+ var pendingAreaRange = _this9.getPendingAreaRange();
1543
+
1544
+ var pendingRanges = ranges.map(range => GridRange.intersection(pendingAreaRange, range)).filter(range => range != null).map(range => {
1545
+ assertNotNull(range);
1546
+ return GridRange.offset(range, 0, -(_this9.floatingTopRowCount + _this9.table.size));
1547
+ });
1548
+
1549
+ if (pendingRanges.length > 0) {
1550
+ var newDataMap = new Map(_this9.pendingNewDataMap);
1551
+
1552
+ for (var i = 0; i < pendingRanges.length; i += 1) {
1553
+ var pendingRange = pendingRanges[i];
1554
+ assertNotNull(pendingRange.startRow);
1555
+ assertNotNull(pendingRange.endRow);
1556
+
1557
+ for (var r = pendingRange.startRow; r <= pendingRange.endRow; r += 1) {
1558
+ newDataMap.delete(r);
1559
+ }
1560
+ }
1561
+
1562
+ _this9.pendingNewDataMap = newDataMap;
1563
+ _this9.formattedStringData = [];
1564
+
1565
+ _this9.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.PENDING_DATA_UPDATED));
1566
+
1567
+ _this9.dispatchEvent(new EventShimCustomEvent(IrisGridModel.EVENT.UPDATED));
1568
+ }
1569
+
1570
+ var tableAreaRange = _this9.getTableAreaRange();
1571
+
1572
+ var tableRanges = ranges.map(range => GridRange.intersection(tableAreaRange, range)).filter(range => range != null);
1573
+
1574
+ if (tableRanges.length <= 0) {
1575
+ return;
1576
+ }
1577
+
1578
+ var [data, deleteTable] = yield Promise.all([// Need to get the key values of each row
1579
+ _this9.snapshot(tableRanges.map(range => {
1580
+ assertNotNull(range);
1581
+ return new GridRange(0, range.startRow, keyColumns.length - 1, range.endRow);
1582
+ })), _this9.table.copy()]); // Now copy the existing table and filter it on the values in the snapshot for the key columns in the input table
1583
+
1584
+ var filters = data.map(row => {
1585
+ var columnFilters = [];
1586
+
1587
+ for (var c = 0; c < keyColumns.length; c += 1) {
1588
+ var _column4 = keyColumns[c];
1589
+ var _value4 = row[c];
1590
+ var filterValue = TableUtils.makeFilterRawValue(_column4.type, _value4);
1591
+
1592
+ var _filter = _column4.filter().eq(filterValue);
1593
+
1594
+ columnFilters.push(_filter);
1595
+ }
1596
+
1597
+ return columnFilters.reduce((agg, curr) => agg ? agg.and(curr) : curr);
1598
+ });
1599
+ var filter = filters.reduce((agg, curr) => agg ? agg.or(curr) : curr);
1600
+ deleteTable.applyFilter([filter]); // await this.inputTable?.deleteTable(deleteTable);
1601
+
1602
+ deleteTable.close();
1603
+ })();
1604
+ }
1605
+
1606
+ isValidForCell(x, y, value) {
1607
+ try {
1608
+ var _column5 = this.columns[x];
1609
+ TableUtils.makeValue(_column5.type, value, this.formatter.timeZone);
1610
+ return true;
1611
+ } catch (e) {
1612
+ return false;
1613
+ }
1614
+ }
1615
+
1616
+ }
1617
+
1618
+ _defineProperty(IrisGridTableModelTemplate, "ROW_BUFFER_PAGES", 1);
1619
+
1620
+ _defineProperty(IrisGridTableModelTemplate, "COLUMN_BUFFER_PAGES", 0);
1621
+
1622
+ export default IrisGridTableModelTemplate;
1623
+ //# sourceMappingURL=IrisGridTableModelTemplate.js.map