@vuu-ui/vuu-data-local 0.13.7 → 0.13.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/index.js +1992 -6
- package/cjs/index.js.map +1 -1
- package/esm/index.js +1993 -3
- package/esm/index.js.map +1 -1
- package/package.json +7 -7
- package/cjs/array-data-source/aggregate-utils.js +0 -237
- package/cjs/array-data-source/aggregate-utils.js.map +0 -1
- package/cjs/array-data-source/array-data-source.js +0 -669
- package/cjs/array-data-source/array-data-source.js.map +0 -1
- package/cjs/array-data-source/array-data-utils.js +0 -52
- package/cjs/array-data-source/array-data-utils.js.map +0 -1
- package/cjs/array-data-source/group-utils.js +0 -181
- package/cjs/array-data-source/group-utils.js.map +0 -1
- package/cjs/array-data-source/sort-utils.js +0 -54
- package/cjs/array-data-source/sort-utils.js.map +0 -1
- package/cjs/json-data-source/JsonDataSource.js +0 -398
- package/cjs/json-data-source/JsonDataSource.js.map +0 -1
- package/cjs/tree-data-source/IconProvider.js +0 -31
- package/cjs/tree-data-source/IconProvider.js.map +0 -1
- package/cjs/tree-data-source/TreeDataSource.js +0 -421
- package/cjs/tree-data-source/TreeDataSource.js.map +0 -1
- package/esm/array-data-source/aggregate-utils.js +0 -235
- package/esm/array-data-source/aggregate-utils.js.map +0 -1
- package/esm/array-data-source/array-data-source.js +0 -667
- package/esm/array-data-source/array-data-source.js.map +0 -1
- package/esm/array-data-source/array-data-utils.js +0 -49
- package/esm/array-data-source/array-data-utils.js.map +0 -1
- package/esm/array-data-source/group-utils.js +0 -177
- package/esm/array-data-source/group-utils.js.map +0 -1
- package/esm/array-data-source/sort-utils.js +0 -52
- package/esm/array-data-source/sort-utils.js.map +0 -1
- package/esm/json-data-source/JsonDataSource.js +0 -396
- package/esm/json-data-source/JsonDataSource.js.map +0 -1
- package/esm/tree-data-source/IconProvider.js +0 -29
- package/esm/tree-data-source/IconProvider.js.map +0 -1
- package/esm/tree-data-source/TreeDataSource.js +0 -419
- package/esm/tree-data-source/TreeDataSource.js.map +0 -1
package/cjs/index.js
CHANGED
|
@@ -1,12 +1,1998 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
var TreeDataSource = require('./tree-data-source/TreeDataSource.js');
|
|
3
|
+
var vuuFilterParser = require('@vuu-ui/vuu-filter-parser');
|
|
4
|
+
var vuuUtils = require('@vuu-ui/vuu-utils');
|
|
6
5
|
|
|
6
|
+
const aggregateData = (aggregations, targetData, groupBy, leafData, columnMap, groupMap) => {
|
|
7
|
+
const aggType = aggregations[aggregations.length - 1].aggType;
|
|
8
|
+
const groupIndices = groupBy.map((column) => columnMap[column]);
|
|
9
|
+
switch (aggType) {
|
|
10
|
+
case 1:
|
|
11
|
+
return aggregateSum(
|
|
12
|
+
groupMap,
|
|
13
|
+
leafData,
|
|
14
|
+
columnMap,
|
|
15
|
+
aggregations,
|
|
16
|
+
targetData,
|
|
17
|
+
groupIndices
|
|
18
|
+
);
|
|
19
|
+
case 2:
|
|
20
|
+
return aggregateAverage(
|
|
21
|
+
groupMap,
|
|
22
|
+
leafData,
|
|
23
|
+
columnMap,
|
|
24
|
+
aggregations,
|
|
25
|
+
targetData,
|
|
26
|
+
groupIndices
|
|
27
|
+
);
|
|
28
|
+
case 3:
|
|
29
|
+
return aggregateCount(
|
|
30
|
+
groupMap,
|
|
31
|
+
columnMap,
|
|
32
|
+
aggregations,
|
|
33
|
+
targetData,
|
|
34
|
+
groupIndices
|
|
35
|
+
);
|
|
36
|
+
case 4:
|
|
37
|
+
return aggregateHigh(
|
|
38
|
+
groupMap,
|
|
39
|
+
leafData,
|
|
40
|
+
columnMap,
|
|
41
|
+
aggregations,
|
|
42
|
+
targetData,
|
|
43
|
+
groupIndices
|
|
44
|
+
);
|
|
45
|
+
case 5:
|
|
46
|
+
return aggregateLow(
|
|
47
|
+
groupMap,
|
|
48
|
+
leafData,
|
|
49
|
+
columnMap,
|
|
50
|
+
aggregations,
|
|
51
|
+
targetData,
|
|
52
|
+
groupIndices
|
|
53
|
+
);
|
|
54
|
+
case 6:
|
|
55
|
+
return aggregateDistinct(
|
|
56
|
+
groupMap,
|
|
57
|
+
leafData,
|
|
58
|
+
columnMap,
|
|
59
|
+
aggregations,
|
|
60
|
+
targetData,
|
|
61
|
+
groupIndices
|
|
62
|
+
);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
function aggregateCount(groupMap, columnMap, aggregations, targetData, groupIndices) {
|
|
66
|
+
const counts = {};
|
|
67
|
+
const aggColumn = getAggColumn(columnMap, aggregations);
|
|
68
|
+
function countRecursive(map) {
|
|
69
|
+
if (Array.isArray(map)) {
|
|
70
|
+
return map.length;
|
|
71
|
+
} else {
|
|
72
|
+
let count2 = 0;
|
|
73
|
+
for (const key in map) {
|
|
74
|
+
count2 += 1 + countRecursive(map[key]);
|
|
75
|
+
}
|
|
76
|
+
return count2;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
for (const key in groupMap) {
|
|
80
|
+
const count2 = countRecursive(groupMap[key]);
|
|
81
|
+
counts[key] = count2;
|
|
82
|
+
}
|
|
83
|
+
for (let index = 0; index < targetData.length; index++) {
|
|
84
|
+
for (const key in counts) {
|
|
85
|
+
if (targetData[index][groupIndices[0]] === key) {
|
|
86
|
+
targetData[index][aggColumn] = counts[key];
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return counts;
|
|
91
|
+
}
|
|
92
|
+
function getAggColumn(columnMap, aggregations) {
|
|
93
|
+
const columnName = aggregations[aggregations.length - 1].column;
|
|
94
|
+
const columnNumber = columnMap[columnName];
|
|
95
|
+
return columnNumber;
|
|
96
|
+
}
|
|
97
|
+
function aggregateSum(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
|
|
98
|
+
const sums = {};
|
|
99
|
+
const aggColumn = getAggColumn(columnMap, aggregations);
|
|
100
|
+
function sumRecursive(map, leafData2, aggColumn2) {
|
|
101
|
+
if (Array.isArray(map)) {
|
|
102
|
+
let sum = 0;
|
|
103
|
+
for (const key of map) {
|
|
104
|
+
sum += Number(leafData2[key][aggColumn2]);
|
|
105
|
+
}
|
|
106
|
+
return sum;
|
|
107
|
+
} else {
|
|
108
|
+
let sum = 0;
|
|
109
|
+
for (const key in map) {
|
|
110
|
+
sum += sumRecursive(map[key], leafData2, aggColumn2);
|
|
111
|
+
}
|
|
112
|
+
return sum;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (const key in groupMap) {
|
|
116
|
+
const sum = Number(sumRecursive(groupMap[key], leafData, aggColumn));
|
|
117
|
+
sums[key] = sum;
|
|
118
|
+
}
|
|
119
|
+
for (let index = 0; index < targetData.length; index++) {
|
|
120
|
+
for (const key in sums) {
|
|
121
|
+
if (targetData[index][groupIndices[0]] === key) {
|
|
122
|
+
targetData[index][aggColumn] = sums[key];
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return sums;
|
|
127
|
+
}
|
|
128
|
+
function aggregateAverage(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
|
|
129
|
+
const averages = {};
|
|
130
|
+
const aggColumn = getAggColumn(columnMap, aggregations);
|
|
131
|
+
const count2 = aggregateCount(
|
|
132
|
+
groupMap,
|
|
133
|
+
columnMap,
|
|
134
|
+
aggregations,
|
|
135
|
+
targetData,
|
|
136
|
+
groupIndices
|
|
137
|
+
);
|
|
138
|
+
const sum = aggregateSum(
|
|
139
|
+
groupMap,
|
|
140
|
+
leafData,
|
|
141
|
+
columnMap,
|
|
142
|
+
aggregations,
|
|
143
|
+
targetData,
|
|
144
|
+
groupIndices
|
|
145
|
+
);
|
|
146
|
+
for (const key in count2) {
|
|
147
|
+
let average = 0;
|
|
148
|
+
average = sum[key] / count2[key];
|
|
149
|
+
averages[key] = average;
|
|
150
|
+
}
|
|
151
|
+
for (let index = 0; index < targetData.length; index++) {
|
|
152
|
+
for (const key in averages) {
|
|
153
|
+
if (targetData[index][groupIndices[0]] === key) {
|
|
154
|
+
targetData[index][aggColumn] = averages[key];
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
console.log("!!!! targetData", targetData);
|
|
159
|
+
console.log("!!!! averages", averages);
|
|
160
|
+
return averages;
|
|
161
|
+
}
|
|
162
|
+
function getLeafColumnData(map, leafData, aggColumn) {
|
|
163
|
+
const data = [];
|
|
164
|
+
if (Array.isArray(map)) {
|
|
165
|
+
for (const key of map) {
|
|
166
|
+
data.push(leafData[key][aggColumn]);
|
|
167
|
+
}
|
|
168
|
+
} else {
|
|
169
|
+
for (const key in map) {
|
|
170
|
+
data.push(...getLeafColumnData(map[key], leafData, aggColumn));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return data;
|
|
174
|
+
}
|
|
175
|
+
function aggregateDistinct(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
|
|
176
|
+
const distincts = {};
|
|
177
|
+
const aggColumn = getAggColumn(columnMap, aggregations);
|
|
178
|
+
for (const key in groupMap) {
|
|
179
|
+
const leafColumnData = getLeafColumnData(
|
|
180
|
+
groupMap[key],
|
|
181
|
+
leafData,
|
|
182
|
+
aggColumn
|
|
183
|
+
);
|
|
184
|
+
const distinct = [...new Set(leafColumnData)];
|
|
185
|
+
distincts[key] = distinct.length;
|
|
186
|
+
}
|
|
187
|
+
for (let index = 0; index < targetData.length; index++) {
|
|
188
|
+
for (const key in distincts) {
|
|
189
|
+
if (targetData[index][groupIndices[0]] === key) {
|
|
190
|
+
targetData[index][aggColumn] = distincts[key];
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
return distincts;
|
|
195
|
+
}
|
|
196
|
+
function aggregateHigh(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
|
|
197
|
+
const highs = {};
|
|
198
|
+
const aggColumn = getAggColumn(columnMap, aggregations);
|
|
199
|
+
for (const key in groupMap) {
|
|
200
|
+
const leafColumnData = getLeafColumnData(
|
|
201
|
+
groupMap[key],
|
|
202
|
+
leafData,
|
|
203
|
+
aggColumn
|
|
204
|
+
);
|
|
205
|
+
const maxNumber = Math.max(...leafColumnData);
|
|
206
|
+
highs[key] = maxNumber;
|
|
207
|
+
}
|
|
208
|
+
for (let index = 0; index < targetData.length; index++) {
|
|
209
|
+
for (const key in highs) {
|
|
210
|
+
if (targetData[index][groupIndices[0]] === key) {
|
|
211
|
+
targetData[index][aggColumn] = highs[key];
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return highs;
|
|
216
|
+
}
|
|
217
|
+
function aggregateLow(groupMap, leafData, columnMap, aggregations, targetData, groupIndices) {
|
|
218
|
+
const mins = {};
|
|
219
|
+
const aggColumn = getAggColumn(columnMap, aggregations);
|
|
220
|
+
for (const key in groupMap) {
|
|
221
|
+
const leafColumnData = getLeafColumnData(
|
|
222
|
+
groupMap[key],
|
|
223
|
+
leafData,
|
|
224
|
+
aggColumn
|
|
225
|
+
);
|
|
226
|
+
const minNumber = Math.min(...leafColumnData);
|
|
227
|
+
mins[key] = minNumber;
|
|
228
|
+
}
|
|
229
|
+
for (let index = 0; index < targetData.length; index++) {
|
|
230
|
+
for (const key in mins) {
|
|
231
|
+
if (targetData[index][groupIndices[0]] === key) {
|
|
232
|
+
targetData[index][aggColumn] = mins[key];
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
return mins;
|
|
237
|
+
}
|
|
7
238
|
|
|
239
|
+
const { RENDER_IDX, SELECTED: SELECTED$2 } = vuuUtils.metadataKeys;
|
|
240
|
+
const toClientRow$2 = (row, keys, selection, dataIndices) => {
|
|
241
|
+
const [rowIndex] = row;
|
|
242
|
+
let clientRow;
|
|
243
|
+
if (dataIndices) {
|
|
244
|
+
const { count } = vuuUtils.metadataKeys;
|
|
245
|
+
clientRow = row.slice(0, count).concat(dataIndices.map((idx) => row[idx]));
|
|
246
|
+
} else {
|
|
247
|
+
clientRow = row.slice();
|
|
248
|
+
}
|
|
249
|
+
clientRow[RENDER_IDX] = keys.keyFor(rowIndex);
|
|
250
|
+
clientRow[SELECTED$2] = vuuUtils.getSelectionStatus(selection, rowIndex);
|
|
251
|
+
return clientRow;
|
|
252
|
+
};
|
|
253
|
+
const divergentMaps = (columnMap, dataMap) => {
|
|
254
|
+
if (dataMap) {
|
|
255
|
+
const { count: mapOffset } = vuuUtils.metadataKeys;
|
|
256
|
+
for (const [columnName, index] of Object.entries(columnMap)) {
|
|
257
|
+
const dataIdx = dataMap[columnName];
|
|
258
|
+
if (dataIdx === void 0) {
|
|
259
|
+
throw Error(
|
|
260
|
+
`ArrayDataSource column ${columnName} is not in underlying data set`
|
|
261
|
+
);
|
|
262
|
+
} else if (dataIdx !== index - mapOffset) {
|
|
263
|
+
return true;
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
return false;
|
|
268
|
+
};
|
|
269
|
+
const getDataIndices = (columnMap, dataMap) => {
|
|
270
|
+
const { count: mapOffset } = vuuUtils.metadataKeys;
|
|
271
|
+
const result = [];
|
|
272
|
+
Object.entries(columnMap).forEach(([columnName]) => {
|
|
273
|
+
result.push(dataMap[columnName] + mapOffset);
|
|
274
|
+
});
|
|
275
|
+
return result;
|
|
276
|
+
};
|
|
277
|
+
const buildDataToClientMap = (columnMap, dataMap) => {
|
|
278
|
+
if (dataMap && divergentMaps(columnMap, dataMap)) {
|
|
279
|
+
return getDataIndices(columnMap, dataMap);
|
|
280
|
+
}
|
|
281
|
+
return void 0;
|
|
282
|
+
};
|
|
8
283
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
284
|
+
const { DEPTH: DEPTH$2, IS_EXPANDED: IS_EXPANDED$2, KEY: KEY$4 } = vuuUtils.metadataKeys;
|
|
285
|
+
const collapseGroup = (key, groupedRows) => {
|
|
286
|
+
const rows = [];
|
|
287
|
+
for (let i = 0, idx = 0, collapsed = false, len = groupedRows.length; i < len; i++) {
|
|
288
|
+
const row = groupedRows[i];
|
|
289
|
+
const { [DEPTH$2]: depth, [KEY$4]: rowKey } = row;
|
|
290
|
+
if (rowKey === key) {
|
|
291
|
+
const collapsedRow = row.slice();
|
|
292
|
+
collapsedRow[IS_EXPANDED$2] = false;
|
|
293
|
+
rows.push(collapsedRow);
|
|
294
|
+
idx += 1;
|
|
295
|
+
collapsed = true;
|
|
296
|
+
while (i < len - 1 && groupedRows[i + 1][DEPTH$2] > depth) {
|
|
297
|
+
i += 1;
|
|
298
|
+
}
|
|
299
|
+
} else if (collapsed) {
|
|
300
|
+
const newRow = row.slice();
|
|
301
|
+
newRow[0] = idx;
|
|
302
|
+
newRow[1] = idx;
|
|
303
|
+
rows.push(newRow);
|
|
304
|
+
idx += 1;
|
|
305
|
+
} else {
|
|
306
|
+
rows.push(row);
|
|
307
|
+
idx += 1;
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return rows;
|
|
311
|
+
};
|
|
312
|
+
const expandGroup = (keys, sourceRows, groupBy, columnMap, groupMap, processedData) => {
|
|
313
|
+
const groupIndices = groupBy.map((column) => columnMap[column]);
|
|
314
|
+
return dataRowsFromGroups2(
|
|
315
|
+
groupMap,
|
|
316
|
+
groupIndices,
|
|
317
|
+
keys,
|
|
318
|
+
sourceRows,
|
|
319
|
+
void 0,
|
|
320
|
+
void 0,
|
|
321
|
+
void 0,
|
|
322
|
+
processedData
|
|
323
|
+
);
|
|
324
|
+
};
|
|
325
|
+
const dataRowsFromGroups2 = (groupMap, groupIndices, openKeys, sourceRows = [], root = "$root", depth = 1, rows = [], processedData) => {
|
|
326
|
+
const keys = Object.keys(groupMap).sort();
|
|
327
|
+
for (const key of keys) {
|
|
328
|
+
const idx = rows.length;
|
|
329
|
+
const groupKey = `${root}|${key}`;
|
|
330
|
+
const row = [
|
|
331
|
+
idx,
|
|
332
|
+
idx,
|
|
333
|
+
false,
|
|
334
|
+
false,
|
|
335
|
+
depth,
|
|
336
|
+
childCount(groupMap[key]),
|
|
337
|
+
groupKey,
|
|
338
|
+
0
|
|
339
|
+
];
|
|
340
|
+
row[groupIndices[depth - 1]] = key;
|
|
341
|
+
rows.push(row);
|
|
342
|
+
if (openKeys.includes(groupKey)) {
|
|
343
|
+
row[IS_EXPANDED$2] = true;
|
|
344
|
+
if (Array.isArray(groupMap[key])) {
|
|
345
|
+
pushChildren(
|
|
346
|
+
rows,
|
|
347
|
+
groupMap[key],
|
|
348
|
+
sourceRows,
|
|
349
|
+
groupKey,
|
|
350
|
+
depth + 1
|
|
351
|
+
);
|
|
352
|
+
} else {
|
|
353
|
+
dataRowsFromGroups2(
|
|
354
|
+
groupMap[key],
|
|
355
|
+
groupIndices,
|
|
356
|
+
openKeys,
|
|
357
|
+
sourceRows,
|
|
358
|
+
groupKey,
|
|
359
|
+
depth + 1,
|
|
360
|
+
rows,
|
|
361
|
+
processedData
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
for (const key in rows) {
|
|
367
|
+
for (const index in rows) {
|
|
368
|
+
if (rows[key][2] === false && processedData[index] != void 0) {
|
|
369
|
+
if (rows[key][groupIndices[0]] === processedData[index][groupIndices[0]]) {
|
|
370
|
+
rows[key] = rows[key].splice(0, 8).concat(
|
|
371
|
+
processedData[index].slice(
|
|
372
|
+
8,
|
|
373
|
+
// groupIndices[0] + 1,
|
|
374
|
+
processedData[index].length
|
|
375
|
+
)
|
|
376
|
+
);
|
|
377
|
+
break;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
return rows;
|
|
383
|
+
};
|
|
384
|
+
const pushChildren = (rows, tree, sourceRows, parentKey, depth) => {
|
|
385
|
+
for (const rowIdx of tree) {
|
|
386
|
+
const idx = rows.length;
|
|
387
|
+
const sourceRow = sourceRows[rowIdx].slice();
|
|
388
|
+
sourceRow[0] = idx;
|
|
389
|
+
sourceRow[1] = idx;
|
|
390
|
+
sourceRow[DEPTH$2] = depth;
|
|
391
|
+
sourceRow[KEY$4] = `${parentKey}|${sourceRow[KEY$4]}`;
|
|
392
|
+
rows.push(sourceRow);
|
|
393
|
+
}
|
|
394
|
+
};
|
|
395
|
+
const groupRows = (rows, groupBy, columnMap) => {
|
|
396
|
+
const groupIndices = groupBy.map((column) => columnMap[column]);
|
|
397
|
+
const groupTree = groupLeafRows(rows, groupIndices);
|
|
398
|
+
const groupedDataRows = dataRowsFromGroups(groupTree, groupIndices);
|
|
399
|
+
return [groupedDataRows, groupTree];
|
|
400
|
+
};
|
|
401
|
+
const dataRowsFromGroups = (groupTree, groupIndices) => {
|
|
402
|
+
const depth = 0;
|
|
403
|
+
const rows = [];
|
|
404
|
+
let idx = 0;
|
|
405
|
+
const keys = Object.keys(groupTree).sort();
|
|
406
|
+
for (const key of keys) {
|
|
407
|
+
const row = [
|
|
408
|
+
idx,
|
|
409
|
+
idx,
|
|
410
|
+
false,
|
|
411
|
+
false,
|
|
412
|
+
1,
|
|
413
|
+
childCount(groupTree[key]),
|
|
414
|
+
`$root|${key}`,
|
|
415
|
+
0
|
|
416
|
+
];
|
|
417
|
+
row[groupIndices[depth]] = key;
|
|
418
|
+
rows.push(row);
|
|
419
|
+
idx += 1;
|
|
420
|
+
}
|
|
421
|
+
return rows;
|
|
422
|
+
};
|
|
423
|
+
function childCount(list) {
|
|
424
|
+
if (Array.isArray(list)) {
|
|
425
|
+
return list.length;
|
|
426
|
+
} else {
|
|
427
|
+
return Object.keys(list).length;
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
function groupLeafRows(leafRows, groupby) {
|
|
431
|
+
const groups = {};
|
|
432
|
+
const levels = groupby.length;
|
|
433
|
+
const lastLevel = levels - 1;
|
|
434
|
+
for (let i = 0, len = leafRows.length; i < len; i++) {
|
|
435
|
+
const leafRow = leafRows[i];
|
|
436
|
+
let target = groups;
|
|
437
|
+
let targetNode;
|
|
438
|
+
let key;
|
|
439
|
+
for (let level = 0; level < levels; level++) {
|
|
440
|
+
const colIdx = groupby[level];
|
|
441
|
+
key = leafRow[colIdx].toString();
|
|
442
|
+
targetNode = target[key];
|
|
443
|
+
if (targetNode && level === lastLevel) {
|
|
444
|
+
targetNode.push(i);
|
|
445
|
+
} else if (targetNode) {
|
|
446
|
+
target = targetNode;
|
|
447
|
+
} else if (!targetNode && level < lastLevel) {
|
|
448
|
+
target = target[key] = {};
|
|
449
|
+
} else if (!targetNode) {
|
|
450
|
+
target[key] = [i];
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
return groups;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
const defaultSortPredicate = (r1, r2, [i, direction]) => {
|
|
458
|
+
const val1 = direction === "D" ? r2[i] : r1[i];
|
|
459
|
+
const val2 = direction === "D" ? r1[i] : r2[i];
|
|
460
|
+
if (val1 === val2) {
|
|
461
|
+
return 0;
|
|
462
|
+
} else if (val2 === null || val1 > val2) {
|
|
463
|
+
return 1;
|
|
464
|
+
} else {
|
|
465
|
+
return -1;
|
|
466
|
+
}
|
|
467
|
+
};
|
|
468
|
+
const sortComparator = (sortDefs) => {
|
|
469
|
+
if (sortDefs.length === 1) {
|
|
470
|
+
return singleColComparator(sortDefs);
|
|
471
|
+
} else if (sortDefs.length === 2) {
|
|
472
|
+
return twoColComparator(sortDefs);
|
|
473
|
+
} else {
|
|
474
|
+
return multiColComparator(sortDefs);
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
const singleColComparator = ([[i, direction]]) => (r1, r2) => {
|
|
478
|
+
const v1 = direction === "D" ? r2[i] : r1[i];
|
|
479
|
+
const v2 = direction === "D" ? r1[i] : r2[i];
|
|
480
|
+
return v1 > v2 ? 1 : v2 > v1 ? -1 : 0;
|
|
481
|
+
};
|
|
482
|
+
const twoColComparator = ([[idx1, direction1], [idx2, direction2]]) => (r1, r2) => {
|
|
483
|
+
const v1 = direction1 === "D" ? r2[idx1] : r1[idx1];
|
|
484
|
+
const v2 = direction1 === "D" ? r1[idx1] : r2[idx1];
|
|
485
|
+
const v3 = direction2 === "D" ? r2[idx2] : r1[idx2];
|
|
486
|
+
const v4 = direction2 === "D" ? r1[idx2] : r2[idx2];
|
|
487
|
+
return v1 > v2 ? 1 : v2 > v1 ? -1 : v3 > v4 ? 1 : v4 > v3 ? -1 : 0;
|
|
488
|
+
};
|
|
489
|
+
const multiColComparator = (sortDefs, test = defaultSortPredicate) => (r1, r2) => {
|
|
490
|
+
for (const sortDef of sortDefs) {
|
|
491
|
+
const result = test(r1, r2, sortDef);
|
|
492
|
+
if (result !== 0) {
|
|
493
|
+
return result;
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
return 0;
|
|
497
|
+
};
|
|
498
|
+
const sortRows = (rows, { sortDefs }, columnMap) => {
|
|
499
|
+
const indexedSortDefs = sortDefs.map(({ column, sortType }) => [
|
|
500
|
+
columnMap[column],
|
|
501
|
+
sortType
|
|
502
|
+
]);
|
|
503
|
+
const comparator = sortComparator(indexedSortDefs);
|
|
504
|
+
return rows.slice().sort(comparator);
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
var __defProp$3 = Object.defineProperty;
|
|
508
|
+
var __typeError$3 = (msg) => {
|
|
509
|
+
throw TypeError(msg);
|
|
510
|
+
};
|
|
511
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
512
|
+
var __publicField$3 = (obj, key, value) => __defNormalProp$3(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
513
|
+
var __accessCheck$3 = (obj, member, msg) => member.has(obj) || __typeError$3("Cannot " + msg);
|
|
514
|
+
var __privateGet$3 = (obj, member, getter) => (__accessCheck$3(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
515
|
+
var __privateAdd$3 = (obj, member, value) => member.has(obj) ? __typeError$3("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
516
|
+
var __privateSet$2 = (obj, member, value, setter) => (__accessCheck$3(obj, member, "write to private field"), member.set(obj, value), value);
|
|
517
|
+
var _columnMap, _data$2, _keys, _links, _range$1, _selectedRowsCount$2, _status$2, _title$1;
|
|
518
|
+
const { debug, info } = vuuUtils.logger("ArrayDataSource");
|
|
519
|
+
const { KEY: KEY$3 } = vuuUtils.metadataKeys;
|
|
520
|
+
const toDataSourceRow = (key) => (data, index) => {
|
|
521
|
+
return [index, index, true, false, 1, 0, String(data[key]), 0, ...data];
|
|
522
|
+
};
|
|
523
|
+
const buildTableSchema = (columns, keyColumn) => {
|
|
524
|
+
const schema = {
|
|
525
|
+
columns: columns.map(({ name, serverDataType = "string" }) => ({
|
|
526
|
+
name,
|
|
527
|
+
serverDataType
|
|
528
|
+
})),
|
|
529
|
+
key: keyColumn ?? columns[0].name,
|
|
530
|
+
table: { module: "", table: "Array" }
|
|
531
|
+
};
|
|
532
|
+
return schema;
|
|
533
|
+
};
|
|
534
|
+
class ArrayDataSource extends vuuUtils.EventEmitter {
|
|
535
|
+
constructor({
|
|
536
|
+
aggregations,
|
|
537
|
+
baseFilterSpec,
|
|
538
|
+
// different from RemoteDataSource
|
|
539
|
+
columnDescriptors,
|
|
540
|
+
data,
|
|
541
|
+
dataMap,
|
|
542
|
+
filterSpec,
|
|
543
|
+
groupBy,
|
|
544
|
+
keyColumn,
|
|
545
|
+
rangeChangeRowset = "delta",
|
|
546
|
+
sort,
|
|
547
|
+
title,
|
|
548
|
+
viewport
|
|
549
|
+
}) {
|
|
550
|
+
super();
|
|
551
|
+
__publicField$3(this, "clientCallback");
|
|
552
|
+
__publicField$3(this, "columnDescriptors");
|
|
553
|
+
/** sorted offsets of data within raw data, reflecting sort order
|
|
554
|
+
* of columns specified by client.
|
|
555
|
+
*/
|
|
556
|
+
__publicField$3(this, "dataIndices");
|
|
557
|
+
/** Map reflecting positions of data items in raw data */
|
|
558
|
+
__publicField$3(this, "dataMap");
|
|
559
|
+
__publicField$3(this, "groupMap");
|
|
560
|
+
/** the index of key field within raw data row */
|
|
561
|
+
__publicField$3(this, "key");
|
|
562
|
+
__publicField$3(this, "lastRangeServed", { from: 0, to: 0 });
|
|
563
|
+
__publicField$3(this, "rangeChangeRowset");
|
|
564
|
+
__publicField$3(this, "openTreeNodes", []);
|
|
565
|
+
/** Map reflecting positions of columns in client data sent to user */
|
|
566
|
+
__privateAdd$3(this, _columnMap);
|
|
567
|
+
__publicField$3(this, "_config", vuuUtils.vanillaConfig);
|
|
568
|
+
__privateAdd$3(this, _data$2);
|
|
569
|
+
__privateAdd$3(this, _keys, new vuuUtils.KeySet(vuuUtils.NULL_RANGE));
|
|
570
|
+
__privateAdd$3(this, _links);
|
|
571
|
+
__privateAdd$3(this, _range$1, vuuUtils.Range(0, 0));
|
|
572
|
+
__privateAdd$3(this, _selectedRowsCount$2, 0);
|
|
573
|
+
__privateAdd$3(this, _status$2, "initialising");
|
|
574
|
+
__privateAdd$3(this, _title$1);
|
|
575
|
+
__publicField$3(this, "_menu");
|
|
576
|
+
__publicField$3(this, "selectedRows", []);
|
|
577
|
+
__publicField$3(this, "tableSchema");
|
|
578
|
+
__publicField$3(this, "viewport");
|
|
579
|
+
__publicField$3(this, "processedData");
|
|
580
|
+
__publicField$3(this, "insert", (row) => {
|
|
581
|
+
const dataSourceRow = toDataSourceRow(this.key)(row, this.size);
|
|
582
|
+
__privateGet$3(this, _data$2).push(dataSourceRow);
|
|
583
|
+
const { from, to } = __privateGet$3(this, _range$1);
|
|
584
|
+
const [rowIdx] = dataSourceRow;
|
|
585
|
+
if (rowIdx >= from && rowIdx < to) {
|
|
586
|
+
this.sendRowsToClient();
|
|
587
|
+
}
|
|
588
|
+
});
|
|
589
|
+
__publicField$3(this, "updateDataItem", (keyValue, columnName, value) => {
|
|
590
|
+
this.validateDataValue(columnName, value);
|
|
591
|
+
const colIndex = __privateGet$3(this, _columnMap)[columnName];
|
|
592
|
+
const dataColIndex = this.dataMap?.[columnName];
|
|
593
|
+
const dataIndex = this.indexOfRowWithKey(keyValue);
|
|
594
|
+
if (dataIndex !== -1 && dataColIndex !== void 0) {
|
|
595
|
+
const dataSourceRow = __privateGet$3(this, _data$2)[dataIndex];
|
|
596
|
+
dataSourceRow[colIndex] = value;
|
|
597
|
+
const { from, to } = __privateGet$3(this, _range$1);
|
|
598
|
+
const [rowIdx] = dataSourceRow;
|
|
599
|
+
if (rowIdx >= from && rowIdx < to) {
|
|
600
|
+
this.sendRowsToClient(false, dataSourceRow);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
});
|
|
604
|
+
__publicField$3(this, "indexOfRowWithKey", (key) => __privateGet$3(this, _data$2).findIndex((row) => row[KEY$3] === key));
|
|
605
|
+
__publicField$3(this, "update", (row, columnName) => {
|
|
606
|
+
const keyValue = row[this.key];
|
|
607
|
+
const dataColIndex = this.dataMap?.[columnName];
|
|
608
|
+
return this.updateDataItem(keyValue, columnName, row[dataColIndex]);
|
|
609
|
+
});
|
|
610
|
+
__publicField$3(this, "updateRow", (row) => {
|
|
611
|
+
const keyValue = row[this.key];
|
|
612
|
+
const dataIndex = __privateGet$3(this, _data$2).findIndex((row2) => row2[KEY$3] === keyValue);
|
|
613
|
+
if (dataIndex !== -1) {
|
|
614
|
+
const dataSourceRow = toDataSourceRow(this.key)(row, dataIndex);
|
|
615
|
+
__privateGet$3(this, _data$2)[dataIndex] = dataSourceRow;
|
|
616
|
+
const { from, to } = __privateGet$3(this, _range$1);
|
|
617
|
+
if (dataIndex >= from && dataIndex < to) {
|
|
618
|
+
this.sendRowsToClient(false, dataSourceRow);
|
|
619
|
+
}
|
|
620
|
+
}
|
|
621
|
+
});
|
|
622
|
+
if (!data || !columnDescriptors) {
|
|
623
|
+
throw Error(
|
|
624
|
+
"ArrayDataSource constructor called without data or without columnDescriptors"
|
|
625
|
+
);
|
|
626
|
+
}
|
|
627
|
+
this.columnDescriptors = columnDescriptors;
|
|
628
|
+
this.dataMap = dataMap;
|
|
629
|
+
this.key = keyColumn ? this.columnDescriptors.findIndex((col) => col.name === keyColumn) : 0;
|
|
630
|
+
this.rangeChangeRowset = rangeChangeRowset;
|
|
631
|
+
this.tableSchema = buildTableSchema(columnDescriptors, keyColumn);
|
|
632
|
+
this.viewport = viewport || vuuUtils.uuid();
|
|
633
|
+
__privateSet$2(this, _title$1, title);
|
|
634
|
+
const columns = columnDescriptors.map((col) => col.name);
|
|
635
|
+
__privateSet$2(this, _columnMap, vuuUtils.buildColumnMap(columns));
|
|
636
|
+
this.dataIndices = buildDataToClientMap(__privateGet$3(this, _columnMap), this.dataMap);
|
|
637
|
+
__privateSet$2(this, _data$2, data.map(toDataSourceRow(this.key)));
|
|
638
|
+
this.config = {
|
|
639
|
+
...this._config,
|
|
640
|
+
aggregations: aggregations || this._config.aggregations,
|
|
641
|
+
baseFilterSpec,
|
|
642
|
+
columns,
|
|
643
|
+
filterSpec: filterSpec || this._config.filterSpec,
|
|
644
|
+
groupBy: groupBy || this._config.groupBy,
|
|
645
|
+
sort: sort || this._config.sort
|
|
646
|
+
};
|
|
647
|
+
debug?.(`columnMap: ${JSON.stringify(__privateGet$3(this, _columnMap))}`);
|
|
648
|
+
}
|
|
649
|
+
async subscribe({
|
|
650
|
+
viewport = this.viewport ?? (this.viewport = vuuUtils.uuid()),
|
|
651
|
+
columns,
|
|
652
|
+
aggregations,
|
|
653
|
+
baseFilterSpec,
|
|
654
|
+
range,
|
|
655
|
+
selectedIndexValues,
|
|
656
|
+
selectedKeyValues,
|
|
657
|
+
sort,
|
|
658
|
+
groupBy,
|
|
659
|
+
filterSpec
|
|
660
|
+
}, callback) {
|
|
661
|
+
console.log(`%cArrayDataSource subscribe`, "color: red;font-weight:bold;");
|
|
662
|
+
this.clientCallback = callback;
|
|
663
|
+
this.viewport = viewport;
|
|
664
|
+
__privateSet$2(this, _status$2, "subscribed");
|
|
665
|
+
this.selectedRows = selectedIndexValues ?? this.convertKeysToIndexValues(selectedKeyValues) ?? [];
|
|
666
|
+
__privateSet$2(this, _selectedRowsCount$2, vuuUtils.selectionCount(this.selectedRows));
|
|
667
|
+
this.lastRangeServed = { from: 0, to: 0 };
|
|
668
|
+
let config = this._config;
|
|
669
|
+
const hasConfigProps = aggregations || columns || filterSpec || groupBy || sort;
|
|
670
|
+
if (hasConfigProps) {
|
|
671
|
+
if (range) {
|
|
672
|
+
this.setRange(range);
|
|
673
|
+
}
|
|
674
|
+
config = {
|
|
675
|
+
...config,
|
|
676
|
+
aggregations: aggregations || this._config.aggregations,
|
|
677
|
+
baseFilterSpec: baseFilterSpec || this._config.baseFilterSpec,
|
|
678
|
+
columns: columns || this._config.columns,
|
|
679
|
+
filterSpec: filterSpec || this._config.filterSpec,
|
|
680
|
+
groupBy: groupBy || this._config.groupBy,
|
|
681
|
+
sort: sort || this._config.sort
|
|
682
|
+
};
|
|
683
|
+
}
|
|
684
|
+
const subscribedMessage = {
|
|
685
|
+
...config,
|
|
686
|
+
type: "subscribed",
|
|
687
|
+
clientViewportId: this.viewport,
|
|
688
|
+
range: __privateGet$3(this, _range$1),
|
|
689
|
+
tableSchema: this.tableSchema
|
|
690
|
+
};
|
|
691
|
+
this.clientCallback?.(subscribedMessage);
|
|
692
|
+
this.emit("subscribed", subscribedMessage);
|
|
693
|
+
if (hasConfigProps) {
|
|
694
|
+
this.config = config;
|
|
695
|
+
} else {
|
|
696
|
+
this.clientCallback({
|
|
697
|
+
clientViewportId: this.viewport,
|
|
698
|
+
mode: "size-only",
|
|
699
|
+
type: "viewport-update",
|
|
700
|
+
size: __privateGet$3(this, _data$2).length
|
|
701
|
+
});
|
|
702
|
+
if (range && !__privateGet$3(this, _range$1).equals(range)) {
|
|
703
|
+
this.range = range;
|
|
704
|
+
} else if (__privateGet$3(this, _range$1) !== vuuUtils.NULL_RANGE) {
|
|
705
|
+
this.sendRowsToClient();
|
|
706
|
+
}
|
|
707
|
+
if (this.range.to !== 0) {
|
|
708
|
+
const pageCount = Math.ceil(
|
|
709
|
+
this.size / (this.range.to - this.range.from)
|
|
710
|
+
);
|
|
711
|
+
this.emit("page-count", pageCount);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
unsubscribe() {
|
|
716
|
+
__privateSet$2(this, _status$2, "unsubscribed");
|
|
717
|
+
this.emit("unsubscribed", this.viewport);
|
|
718
|
+
}
|
|
719
|
+
suspend() {
|
|
720
|
+
if (__privateGet$3(this, _status$2) !== "unsubscribed") {
|
|
721
|
+
info?.(`suspend #${this.viewport}, current status ${__privateGet$3(this, _status$2)}`);
|
|
722
|
+
__privateSet$2(this, _status$2, "suspended");
|
|
723
|
+
this.emit("suspended", this.viewport);
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
resume(callback) {
|
|
727
|
+
const isSuspended = __privateGet$3(this, _status$2) === "suspended";
|
|
728
|
+
info?.(`resume #${this.viewport}, current status ${__privateGet$3(this, _status$2)}`);
|
|
729
|
+
if (callback) {
|
|
730
|
+
this.clientCallback = callback;
|
|
731
|
+
}
|
|
732
|
+
if (isSuspended) {
|
|
733
|
+
__privateSet$2(this, _status$2, "subscribed");
|
|
734
|
+
}
|
|
735
|
+
this.emit("resumed", this.viewport);
|
|
736
|
+
this.sendRowsToClient(true);
|
|
737
|
+
}
|
|
738
|
+
disable() {
|
|
739
|
+
this.emit("disabled", this.viewport);
|
|
740
|
+
}
|
|
741
|
+
enable() {
|
|
742
|
+
this.emit("enabled", this.viewport);
|
|
743
|
+
}
|
|
744
|
+
select(selected) {
|
|
745
|
+
__privateSet$2(this, _selectedRowsCount$2, vuuUtils.selectionCount(selected));
|
|
746
|
+
debug?.(`select ${JSON.stringify(selected)}`);
|
|
747
|
+
this.selectedRows = selected;
|
|
748
|
+
this.setRange(__privateGet$3(this, _range$1), true);
|
|
749
|
+
this.emit("row-selection", selected, __privateGet$3(this, _selectedRowsCount$2));
|
|
750
|
+
}
|
|
751
|
+
getRowKey(keyOrIndex) {
|
|
752
|
+
if (typeof keyOrIndex === "string") {
|
|
753
|
+
return keyOrIndex;
|
|
754
|
+
}
|
|
755
|
+
const row = this.getRowAtIndex(keyOrIndex);
|
|
756
|
+
if (row === void 0) {
|
|
757
|
+
throw Error(`row not found at index ${keyOrIndex}`);
|
|
758
|
+
}
|
|
759
|
+
return row?.[KEY$3];
|
|
760
|
+
}
|
|
761
|
+
openTreeNode(keyOrIndex) {
|
|
762
|
+
const key = this.getRowKey(keyOrIndex);
|
|
763
|
+
this.openTreeNodes.push(key);
|
|
764
|
+
this.processedData = expandGroup(
|
|
765
|
+
this.openTreeNodes,
|
|
766
|
+
__privateGet$3(this, _data$2),
|
|
767
|
+
this._config.groupBy,
|
|
768
|
+
__privateGet$3(this, _columnMap),
|
|
769
|
+
this.groupMap,
|
|
770
|
+
this.processedData
|
|
771
|
+
);
|
|
772
|
+
this.setRange(__privateGet$3(this, _range$1).reset, true);
|
|
773
|
+
}
|
|
774
|
+
closeTreeNode(keyOrIndex) {
|
|
775
|
+
const key = this.getRowKey(keyOrIndex);
|
|
776
|
+
this.openTreeNodes = this.openTreeNodes.filter((value) => value !== key);
|
|
777
|
+
if (this.processedData) {
|
|
778
|
+
this.processedData = collapseGroup(key, this.processedData);
|
|
779
|
+
this.setRange(__privateGet$3(this, _range$1).reset, true);
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
get pageSize() {
|
|
783
|
+
return __privateGet$3(this, _range$1).to - __privateGet$3(this, _range$1).from;
|
|
784
|
+
}
|
|
785
|
+
get links() {
|
|
786
|
+
return __privateGet$3(this, _links);
|
|
787
|
+
}
|
|
788
|
+
set links(links) {
|
|
789
|
+
__privateSet$2(this, _links, links);
|
|
790
|
+
}
|
|
791
|
+
get menu() {
|
|
792
|
+
return this._menu;
|
|
793
|
+
}
|
|
794
|
+
get status() {
|
|
795
|
+
return __privateGet$3(this, _status$2);
|
|
796
|
+
}
|
|
797
|
+
get data() {
|
|
798
|
+
return __privateGet$3(this, _data$2);
|
|
799
|
+
}
|
|
800
|
+
// Only used by the UpdateGenerator
|
|
801
|
+
get currentData() {
|
|
802
|
+
return this.processedData ?? __privateGet$3(this, _data$2);
|
|
803
|
+
}
|
|
804
|
+
get table() {
|
|
805
|
+
return this.tableSchema.table;
|
|
806
|
+
}
|
|
807
|
+
get config() {
|
|
808
|
+
return this._config;
|
|
809
|
+
}
|
|
810
|
+
set config(config) {
|
|
811
|
+
const configChanges = this.applyConfig(config);
|
|
812
|
+
if (configChanges) {
|
|
813
|
+
if (config) {
|
|
814
|
+
const originalConfig = this._config;
|
|
815
|
+
const newConfig = config?.filterSpec?.filter && config?.filterSpec.filterStruct === void 0 ? {
|
|
816
|
+
...config,
|
|
817
|
+
filterSpec: {
|
|
818
|
+
filter: config.filterSpec.filter,
|
|
819
|
+
filterStruct: vuuFilterParser.parseFilter(config.filterSpec.filter)
|
|
820
|
+
}
|
|
821
|
+
} : config;
|
|
822
|
+
this._config = vuuUtils.withConfigDefaults(newConfig);
|
|
823
|
+
let processedData;
|
|
824
|
+
if (vuuUtils.hasFilter(config) || vuuUtils.hasBaseFilter(config)) {
|
|
825
|
+
const {
|
|
826
|
+
filterSpec: { filterStruct }
|
|
827
|
+
} = vuuUtils.combineFilters(this._config);
|
|
828
|
+
if (filterStruct) {
|
|
829
|
+
const fn = vuuFilterParser.filterPredicate(__privateGet$3(this, _columnMap), filterStruct);
|
|
830
|
+
processedData = __privateGet$3(this, _data$2).filter(fn);
|
|
831
|
+
} else {
|
|
832
|
+
throw Error("filter must include filterStruct");
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
if (vuuUtils.hasSort(config)) {
|
|
836
|
+
processedData = sortRows(
|
|
837
|
+
processedData ?? __privateGet$3(this, _data$2),
|
|
838
|
+
config.sort,
|
|
839
|
+
__privateGet$3(this, _columnMap)
|
|
840
|
+
);
|
|
841
|
+
}
|
|
842
|
+
if (this.openTreeNodes.length > 0 && vuuUtils.isGroupByChanged(originalConfig, config)) {
|
|
843
|
+
if (this._config.groupBy.length === 0) {
|
|
844
|
+
this.openTreeNodes.length = 0;
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
if (vuuUtils.hasGroupBy(config)) {
|
|
848
|
+
const [groupedData, groupMap] = groupRows(
|
|
849
|
+
processedData ?? __privateGet$3(this, _data$2),
|
|
850
|
+
config.groupBy,
|
|
851
|
+
__privateGet$3(this, _columnMap)
|
|
852
|
+
);
|
|
853
|
+
this.groupMap = groupMap;
|
|
854
|
+
processedData = groupedData;
|
|
855
|
+
if (this.openTreeNodes.length > 0) {
|
|
856
|
+
processedData = expandGroup(
|
|
857
|
+
this.openTreeNodes,
|
|
858
|
+
__privateGet$3(this, _data$2),
|
|
859
|
+
this._config.groupBy,
|
|
860
|
+
__privateGet$3(this, _columnMap),
|
|
861
|
+
this.groupMap,
|
|
862
|
+
processedData
|
|
863
|
+
);
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
this.processedData = processedData?.map((row, i) => {
|
|
867
|
+
const dolly = row.slice();
|
|
868
|
+
dolly[0] = i;
|
|
869
|
+
dolly[1] = i;
|
|
870
|
+
return dolly;
|
|
871
|
+
});
|
|
872
|
+
}
|
|
873
|
+
if (__privateGet$3(this, _status$2) === "subscribed") {
|
|
874
|
+
this.setRange(__privateGet$3(this, _range$1).reset, true);
|
|
875
|
+
this.emit("config", this._config, this.range, void 0, configChanges);
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
applyConfig(config, preserveExistingConfigAttributes = false) {
|
|
880
|
+
const { noChanges, ...otherChanges } = vuuUtils.isConfigChanged(
|
|
881
|
+
this._config,
|
|
882
|
+
config
|
|
883
|
+
);
|
|
884
|
+
if (noChanges !== true) {
|
|
885
|
+
if (config) {
|
|
886
|
+
const newConfig = config?.filterSpec?.filter && config?.filterSpec.filterStruct === void 0 ? {
|
|
887
|
+
...config,
|
|
888
|
+
filterSpec: {
|
|
889
|
+
filter: config.filterSpec.filter,
|
|
890
|
+
filterStruct: vuuFilterParser.parseFilter(config.filterSpec.filter)
|
|
891
|
+
}
|
|
892
|
+
} : config;
|
|
893
|
+
if (preserveExistingConfigAttributes) {
|
|
894
|
+
this._config = {
|
|
895
|
+
...this._config,
|
|
896
|
+
...config
|
|
897
|
+
};
|
|
898
|
+
} else {
|
|
899
|
+
this._config = vuuUtils.withConfigDefaults(newConfig);
|
|
900
|
+
}
|
|
901
|
+
return otherChanges;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
get columnMap() {
|
|
906
|
+
return __privateGet$3(this, _columnMap);
|
|
907
|
+
}
|
|
908
|
+
get selectedRowsCount() {
|
|
909
|
+
return __privateGet$3(this, _selectedRowsCount$2);
|
|
910
|
+
}
|
|
911
|
+
get size() {
|
|
912
|
+
return this.processedData?.length ?? __privateGet$3(this, _data$2).length;
|
|
913
|
+
}
|
|
914
|
+
get range() {
|
|
915
|
+
return __privateGet$3(this, _range$1);
|
|
916
|
+
}
|
|
917
|
+
set range(range) {
|
|
918
|
+
this.setRange(range);
|
|
919
|
+
}
|
|
920
|
+
getRowAtIndex(rowIndex) {
|
|
921
|
+
return this.processedData?.[rowIndex];
|
|
922
|
+
}
|
|
923
|
+
delete(row) {
|
|
924
|
+
console.log(`delete row ${row.join(",")}`);
|
|
925
|
+
}
|
|
926
|
+
validateDataValue(columnName, value) {
|
|
927
|
+
const columnDescriptor = this.columnDescriptors.find(
|
|
928
|
+
(col) => col.name === columnName
|
|
929
|
+
);
|
|
930
|
+
if (columnDescriptor) {
|
|
931
|
+
switch (columnDescriptor.serverDataType) {
|
|
932
|
+
case "int":
|
|
933
|
+
{
|
|
934
|
+
if (typeof value === "number") {
|
|
935
|
+
if (Math.floor(value) !== value) {
|
|
936
|
+
throw Error(`${columnName} is int but value = ${value}`);
|
|
937
|
+
}
|
|
938
|
+
} else if (typeof value === "string") {
|
|
939
|
+
const numericValue = parseFloat(value);
|
|
940
|
+
if (Math.floor(numericValue) !== numericValue) {
|
|
941
|
+
throw Error(`${columnName} is ${value} is not a valid integer`);
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
break;
|
|
946
|
+
}
|
|
947
|
+
} else {
|
|
948
|
+
throw Error(`Unknown column ${columnName}`);
|
|
949
|
+
}
|
|
950
|
+
}
|
|
951
|
+
setRange(range, forceFullRefresh = false) {
|
|
952
|
+
if (range.from !== __privateGet$3(this, _range$1).from || range.to !== __privateGet$3(this, _range$1).to) {
|
|
953
|
+
const currentPageCount = Math.ceil(
|
|
954
|
+
this.size / (__privateGet$3(this, _range$1).to - __privateGet$3(this, _range$1).from)
|
|
955
|
+
);
|
|
956
|
+
const newPageCount = Math.ceil(this.size / (range.to - range.from));
|
|
957
|
+
__privateSet$2(this, _range$1, range);
|
|
958
|
+
const keysResequenced = __privateGet$3(this, _keys).reset(range);
|
|
959
|
+
this.sendRowsToClient(forceFullRefresh || keysResequenced);
|
|
960
|
+
requestAnimationFrame(() => {
|
|
961
|
+
if (newPageCount !== currentPageCount) {
|
|
962
|
+
this.emit("page-count", newPageCount);
|
|
963
|
+
}
|
|
964
|
+
this.emit("range", range);
|
|
965
|
+
});
|
|
966
|
+
} else if (forceFullRefresh) {
|
|
967
|
+
this.sendRowsToClient(forceFullRefresh);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
sendRowsToClient(forceFullRefresh = false, row) {
|
|
971
|
+
if (row) {
|
|
972
|
+
this.clientCallback?.({
|
|
973
|
+
clientViewportId: this.viewport,
|
|
974
|
+
mode: "update",
|
|
975
|
+
rows: [
|
|
976
|
+
toClientRow$2(row, __privateGet$3(this, _keys), this.selectedRows, this.dataIndices)
|
|
977
|
+
],
|
|
978
|
+
type: "viewport-update"
|
|
979
|
+
});
|
|
980
|
+
} else {
|
|
981
|
+
const rowRange = this.rangeChangeRowset === "delta" && !forceFullRefresh ? vuuUtils.rangeNewItems(this.lastRangeServed, __privateGet$3(this, _range$1)) : __privateGet$3(this, _range$1);
|
|
982
|
+
const data = this.processedData ?? __privateGet$3(this, _data$2);
|
|
983
|
+
const rowsWithinViewport = data.slice(rowRange.from, rowRange.to).map(
|
|
984
|
+
(row2) => toClientRow$2(row2, __privateGet$3(this, _keys), this.selectedRows, this.dataIndices)
|
|
985
|
+
);
|
|
986
|
+
this.clientCallback?.({
|
|
987
|
+
clientViewportId: this.viewport,
|
|
988
|
+
mode: "batch",
|
|
989
|
+
range: __privateGet$3(this, _range$1),
|
|
990
|
+
rows: rowsWithinViewport,
|
|
991
|
+
size: data.length,
|
|
992
|
+
type: "viewport-update"
|
|
993
|
+
});
|
|
994
|
+
this.lastRangeServed = {
|
|
995
|
+
from: __privateGet$3(this, _range$1).from,
|
|
996
|
+
to: __privateGet$3(this, _range$1).to
|
|
997
|
+
// to: Math.min(
|
|
998
|
+
// this.#range.to,
|
|
999
|
+
// this.#range.from + rowsWithinViewport.length,
|
|
1000
|
+
// ),
|
|
1001
|
+
};
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
get columns() {
|
|
1005
|
+
return this._config.columns;
|
|
1006
|
+
}
|
|
1007
|
+
set columns(columns) {
|
|
1008
|
+
const addedColumns = vuuUtils.getAddedItems(this.config.columns, columns);
|
|
1009
|
+
if (addedColumns.length > 0) {
|
|
1010
|
+
const columnsWithoutDescriptors = vuuUtils.getMissingItems(
|
|
1011
|
+
this.columnDescriptors,
|
|
1012
|
+
addedColumns,
|
|
1013
|
+
(col) => col.name
|
|
1014
|
+
);
|
|
1015
|
+
console.log(`columnsWithoutDescriptors`, {
|
|
1016
|
+
columnsWithoutDescriptors
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
__privateSet$2(this, _columnMap, vuuUtils.buildColumnMap(columns));
|
|
1020
|
+
this.dataIndices = buildDataToClientMap(__privateGet$3(this, _columnMap), this.dataMap);
|
|
1021
|
+
this.config = {
|
|
1022
|
+
...this._config,
|
|
1023
|
+
columns
|
|
1024
|
+
};
|
|
1025
|
+
}
|
|
1026
|
+
get aggregations() {
|
|
1027
|
+
return this._config.aggregations;
|
|
1028
|
+
}
|
|
1029
|
+
set aggregations(aggregations) {
|
|
1030
|
+
this._config = {
|
|
1031
|
+
...this._config,
|
|
1032
|
+
aggregations
|
|
1033
|
+
};
|
|
1034
|
+
const targetData = this.processedData ?? __privateGet$3(this, _data$2);
|
|
1035
|
+
const leafData = __privateGet$3(this, _data$2);
|
|
1036
|
+
aggregateData(
|
|
1037
|
+
aggregations,
|
|
1038
|
+
targetData,
|
|
1039
|
+
this._config.groupBy,
|
|
1040
|
+
leafData,
|
|
1041
|
+
__privateGet$3(this, _columnMap),
|
|
1042
|
+
this.groupMap
|
|
1043
|
+
);
|
|
1044
|
+
this.setRange(__privateGet$3(this, _range$1).reset, true);
|
|
1045
|
+
this.emit("config", this._config, this.range);
|
|
1046
|
+
}
|
|
1047
|
+
get sort() {
|
|
1048
|
+
return this._config.sort;
|
|
1049
|
+
}
|
|
1050
|
+
set sort(sort) {
|
|
1051
|
+
debug?.(`sort ${JSON.stringify(sort)}`);
|
|
1052
|
+
this.config = {
|
|
1053
|
+
...this._config,
|
|
1054
|
+
sort
|
|
1055
|
+
};
|
|
1056
|
+
}
|
|
1057
|
+
get baseFilter() {
|
|
1058
|
+
return this._config.baseFilterSpec;
|
|
1059
|
+
}
|
|
1060
|
+
set baseFilter(baseFilter) {
|
|
1061
|
+
debug?.(`baseFilter ${JSON.stringify(baseFilter)}`);
|
|
1062
|
+
this.config = {
|
|
1063
|
+
...this._config,
|
|
1064
|
+
baseFilterSpec: baseFilter
|
|
1065
|
+
};
|
|
1066
|
+
}
|
|
1067
|
+
get filter() {
|
|
1068
|
+
return this._config.filterSpec;
|
|
1069
|
+
}
|
|
1070
|
+
set filter(filter) {
|
|
1071
|
+
debug?.(`filter ${JSON.stringify(filter)}`);
|
|
1072
|
+
this.config = {
|
|
1073
|
+
...this._config,
|
|
1074
|
+
filterSpec: filter
|
|
1075
|
+
};
|
|
1076
|
+
}
|
|
1077
|
+
get groupBy() {
|
|
1078
|
+
return this._config.groupBy;
|
|
1079
|
+
}
|
|
1080
|
+
set groupBy(groupBy) {
|
|
1081
|
+
this.config = {
|
|
1082
|
+
...this._config,
|
|
1083
|
+
groupBy
|
|
1084
|
+
};
|
|
1085
|
+
}
|
|
1086
|
+
get title() {
|
|
1087
|
+
return __privateGet$3(this, _title$1) ?? `${this.table.module} ${this.table.table}`;
|
|
1088
|
+
}
|
|
1089
|
+
set title(title) {
|
|
1090
|
+
__privateSet$2(this, _title$1, title);
|
|
1091
|
+
this.emit("title-changed", this.viewport, title);
|
|
1092
|
+
}
|
|
1093
|
+
get _clientCallback() {
|
|
1094
|
+
return this.clientCallback;
|
|
1095
|
+
}
|
|
1096
|
+
createLink({
|
|
1097
|
+
parentVpId,
|
|
1098
|
+
link: { fromColumn, toColumn }
|
|
1099
|
+
}) {
|
|
1100
|
+
console.log("create link", {
|
|
1101
|
+
parentVpId,
|
|
1102
|
+
fromColumn,
|
|
1103
|
+
toColumn
|
|
1104
|
+
});
|
|
1105
|
+
}
|
|
1106
|
+
removeLink() {
|
|
1107
|
+
console.log("remove link");
|
|
1108
|
+
}
|
|
1109
|
+
applyEdit(rowKey, columnName, value) {
|
|
1110
|
+
console.log(`ArrayDataSource applyEdit ${rowKey} ${columnName} ${value}`);
|
|
1111
|
+
return Promise.resolve(true);
|
|
1112
|
+
}
|
|
1113
|
+
async remoteProcedureCall() {
|
|
1114
|
+
return Promise.reject();
|
|
1115
|
+
}
|
|
1116
|
+
async menuRpcCall(rpcRequest) {
|
|
1117
|
+
return new Promise((resolve) => {
|
|
1118
|
+
if (vuuUtils.isEditCellRequest(rpcRequest)) {
|
|
1119
|
+
const { rowKey, field, value } = rpcRequest;
|
|
1120
|
+
try {
|
|
1121
|
+
this.updateDataItem(rowKey, field, value);
|
|
1122
|
+
resolve({
|
|
1123
|
+
action: {
|
|
1124
|
+
type: "VP_EDIT_SUCCESS"
|
|
1125
|
+
},
|
|
1126
|
+
rpcName: "VP_EDIT_CELL_RPC",
|
|
1127
|
+
type: "VIEW_PORT_MENU_RESP",
|
|
1128
|
+
vpId: this.viewport
|
|
1129
|
+
});
|
|
1130
|
+
} catch (error) {
|
|
1131
|
+
resolve({
|
|
1132
|
+
error: String(error),
|
|
1133
|
+
rpcName: "VP_EDIT_CELL_RPC",
|
|
1134
|
+
type: "VIEW_PORT_MENU_REJ",
|
|
1135
|
+
vpId: this.viewport
|
|
1136
|
+
});
|
|
1137
|
+
}
|
|
1138
|
+
} else {
|
|
1139
|
+
throw Error("menuRpcCall invalid rpcRequest");
|
|
1140
|
+
}
|
|
1141
|
+
});
|
|
1142
|
+
}
|
|
1143
|
+
convertKeysToIndexValues(keys) {
|
|
1144
|
+
if (Array.isArray(keys)) {
|
|
1145
|
+
const indexValues = [];
|
|
1146
|
+
keys.forEach((key) => {
|
|
1147
|
+
const rowIdx = this.indexOfRowWithKey(key);
|
|
1148
|
+
if (rowIdx !== -1) {
|
|
1149
|
+
indexValues.push(rowIdx);
|
|
1150
|
+
}
|
|
1151
|
+
});
|
|
1152
|
+
return indexValues;
|
|
1153
|
+
}
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
_columnMap = new WeakMap();
|
|
1157
|
+
_data$2 = new WeakMap();
|
|
1158
|
+
_keys = new WeakMap();
|
|
1159
|
+
_links = new WeakMap();
|
|
1160
|
+
_range$1 = new WeakMap();
|
|
1161
|
+
_selectedRowsCount$2 = new WeakMap();
|
|
1162
|
+
_status$2 = new WeakMap();
|
|
1163
|
+
_title$1 = new WeakMap();
|
|
1164
|
+
|
|
1165
|
+
var __defProp$2 = Object.defineProperty;
|
|
1166
|
+
var __typeError$2 = (msg) => {
|
|
1167
|
+
throw TypeError(msg);
|
|
1168
|
+
};
|
|
1169
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1170
|
+
var __publicField$2 = (obj, key, value) => __defNormalProp$2(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1171
|
+
var __accessCheck$2 = (obj, member, msg) => member.has(obj) || __typeError$2("Cannot " + msg);
|
|
1172
|
+
var __privateGet$2 = (obj, member, getter) => (__accessCheck$2(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1173
|
+
var __privateAdd$2 = (obj, member, value) => member.has(obj) ? __typeError$2("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1174
|
+
var __privateSet$1 = (obj, member, value, setter) => (__accessCheck$2(obj, member, "write to private field"), member.set(obj, value), value);
|
|
1175
|
+
var __privateWrapper$1 = (obj, member, setter, getter) => ({
|
|
1176
|
+
set _(value) {
|
|
1177
|
+
__privateSet$1(obj, member, value);
|
|
1178
|
+
},
|
|
1179
|
+
get _() {
|
|
1180
|
+
return __privateGet$2(obj, member, getter);
|
|
1181
|
+
}
|
|
1182
|
+
});
|
|
1183
|
+
var _aggregations$1, _config, _data$1, _filter, _groupBy, _range, _selectedRowsCount$1, _size$1, _sort, _status$1, _title;
|
|
1184
|
+
const NULL_SCHEMA$1 = { columns: [], key: "", table: { module: "", table: "" } };
|
|
1185
|
+
const { DEPTH: DEPTH$1, IDX: IDX$1, IS_EXPANDED: IS_EXPANDED$1, IS_LEAF: IS_LEAF$1, KEY: KEY$2, SELECTED: SELECTED$1 } = vuuUtils.metadataKeys;
|
|
1186
|
+
const toClientRow$1 = (row, keys) => {
|
|
1187
|
+
const [rowIndex] = row;
|
|
1188
|
+
const clientRow = row.slice();
|
|
1189
|
+
clientRow[1] = keys.keyFor(rowIndex);
|
|
1190
|
+
return clientRow;
|
|
1191
|
+
};
|
|
1192
|
+
class JsonDataSource extends vuuUtils.EventEmitter {
|
|
1193
|
+
constructor({
|
|
1194
|
+
aggregations,
|
|
1195
|
+
data,
|
|
1196
|
+
filterSpec,
|
|
1197
|
+
groupBy,
|
|
1198
|
+
sort,
|
|
1199
|
+
title,
|
|
1200
|
+
viewport
|
|
1201
|
+
}) {
|
|
1202
|
+
super();
|
|
1203
|
+
__publicField$2(this, "columnDescriptors");
|
|
1204
|
+
__publicField$2(this, "clientCallback");
|
|
1205
|
+
__publicField$2(this, "expandedRows", /* @__PURE__ */ new Set());
|
|
1206
|
+
__publicField$2(this, "visibleRows", []);
|
|
1207
|
+
__privateAdd$2(this, _aggregations$1, []);
|
|
1208
|
+
__privateAdd$2(this, _config, vuuUtils.vanillaConfig);
|
|
1209
|
+
__privateAdd$2(this, _data$1);
|
|
1210
|
+
__privateAdd$2(this, _filter, { filter: "" });
|
|
1211
|
+
__privateAdd$2(this, _groupBy, []);
|
|
1212
|
+
__privateAdd$2(this, _range, vuuUtils.Range(0, 0));
|
|
1213
|
+
__privateAdd$2(this, _selectedRowsCount$1, 0);
|
|
1214
|
+
__privateAdd$2(this, _size$1, 0);
|
|
1215
|
+
__privateAdd$2(this, _sort, { sortDefs: [] });
|
|
1216
|
+
__privateAdd$2(this, _status$1, "initialising");
|
|
1217
|
+
__privateAdd$2(this, _title);
|
|
1218
|
+
__publicField$2(this, "rowCount");
|
|
1219
|
+
__publicField$2(this, "viewport");
|
|
1220
|
+
__publicField$2(this, "keys", new vuuUtils.KeySet(__privateGet$2(this, _range)));
|
|
1221
|
+
if (!data) {
|
|
1222
|
+
throw Error("JsonDataSource constructor called without data");
|
|
1223
|
+
}
|
|
1224
|
+
[this.columnDescriptors, __privateWrapper$1(this, _data$1)._] = vuuUtils.jsonToDataSourceRows(data);
|
|
1225
|
+
this.visibleRows = __privateGet$2(this, _data$1).filter((row) => row[DEPTH$1] === 0).map(
|
|
1226
|
+
(row, index) => [index, index].concat(row.slice(2))
|
|
1227
|
+
);
|
|
1228
|
+
this.viewport = viewport || vuuUtils.uuid();
|
|
1229
|
+
if (aggregations) {
|
|
1230
|
+
__privateSet$1(this, _aggregations$1, aggregations);
|
|
1231
|
+
}
|
|
1232
|
+
if (this.columnDescriptors) {
|
|
1233
|
+
__privateSet$1(this, _config, {
|
|
1234
|
+
...__privateGet$2(this, _config),
|
|
1235
|
+
columns: this.columnDescriptors.map((c) => c.name)
|
|
1236
|
+
});
|
|
1237
|
+
}
|
|
1238
|
+
if (filterSpec) {
|
|
1239
|
+
__privateSet$1(this, _filter, filterSpec);
|
|
1240
|
+
}
|
|
1241
|
+
if (groupBy) {
|
|
1242
|
+
__privateSet$1(this, _groupBy, groupBy);
|
|
1243
|
+
}
|
|
1244
|
+
if (sort) {
|
|
1245
|
+
__privateSet$1(this, _sort, sort);
|
|
1246
|
+
}
|
|
1247
|
+
__privateSet$1(this, _title, title);
|
|
1248
|
+
}
|
|
1249
|
+
async subscribe({
|
|
1250
|
+
viewport = this.viewport ?? vuuUtils.uuid(),
|
|
1251
|
+
columns,
|
|
1252
|
+
aggregations,
|
|
1253
|
+
range,
|
|
1254
|
+
sort,
|
|
1255
|
+
groupBy,
|
|
1256
|
+
filterSpec
|
|
1257
|
+
}, callback) {
|
|
1258
|
+
this.clientCallback = callback;
|
|
1259
|
+
if (aggregations) {
|
|
1260
|
+
__privateSet$1(this, _aggregations$1, aggregations);
|
|
1261
|
+
}
|
|
1262
|
+
if (columns) {
|
|
1263
|
+
__privateSet$1(this, _config, {
|
|
1264
|
+
...__privateGet$2(this, _config),
|
|
1265
|
+
columns
|
|
1266
|
+
});
|
|
1267
|
+
}
|
|
1268
|
+
if (filterSpec) {
|
|
1269
|
+
__privateSet$1(this, _filter, filterSpec);
|
|
1270
|
+
}
|
|
1271
|
+
if (groupBy) {
|
|
1272
|
+
__privateSet$1(this, _groupBy, groupBy);
|
|
1273
|
+
}
|
|
1274
|
+
if (sort) {
|
|
1275
|
+
__privateSet$1(this, _sort, sort);
|
|
1276
|
+
}
|
|
1277
|
+
if (__privateGet$2(this, _status$1) !== "initialising") {
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
this.viewport = viewport;
|
|
1281
|
+
__privateSet$1(this, _status$1, "subscribed");
|
|
1282
|
+
this.clientCallback?.({
|
|
1283
|
+
aggregations: __privateGet$2(this, _aggregations$1),
|
|
1284
|
+
type: "subscribed",
|
|
1285
|
+
clientViewportId: this.viewport,
|
|
1286
|
+
columns: __privateGet$2(this, _config).columns,
|
|
1287
|
+
filterSpec: __privateGet$2(this, _filter),
|
|
1288
|
+
groupBy: __privateGet$2(this, _groupBy),
|
|
1289
|
+
range: __privateGet$2(this, _range),
|
|
1290
|
+
sort: __privateGet$2(this, _sort),
|
|
1291
|
+
tableSchema: NULL_SCHEMA$1
|
|
1292
|
+
});
|
|
1293
|
+
this.clientCallback({
|
|
1294
|
+
clientViewportId: this.viewport,
|
|
1295
|
+
mode: "size-only",
|
|
1296
|
+
type: "viewport-update",
|
|
1297
|
+
size: this.visibleRows.length
|
|
1298
|
+
});
|
|
1299
|
+
if (range && !__privateGet$2(this, _range).equals(range)) {
|
|
1300
|
+
this.range = range;
|
|
1301
|
+
} else if (__privateGet$2(this, _range) !== vuuUtils.NULL_RANGE) {
|
|
1302
|
+
this.sendRowsToClient();
|
|
1303
|
+
}
|
|
1304
|
+
}
|
|
1305
|
+
unsubscribe() {
|
|
1306
|
+
console.log("noop");
|
|
1307
|
+
}
|
|
1308
|
+
suspend() {
|
|
1309
|
+
console.log("noop");
|
|
1310
|
+
return this;
|
|
1311
|
+
}
|
|
1312
|
+
resume() {
|
|
1313
|
+
console.log("noop");
|
|
1314
|
+
return this;
|
|
1315
|
+
}
|
|
1316
|
+
disable() {
|
|
1317
|
+
console.log("noop");
|
|
1318
|
+
return this;
|
|
1319
|
+
}
|
|
1320
|
+
enable() {
|
|
1321
|
+
console.log("noop");
|
|
1322
|
+
return this;
|
|
1323
|
+
}
|
|
1324
|
+
set data(data) {
|
|
1325
|
+
[this.columnDescriptors, __privateWrapper$1(this, _data$1)._] = vuuUtils.jsonToDataSourceRows(data);
|
|
1326
|
+
this.visibleRows = __privateGet$2(this, _data$1).filter((row) => row[DEPTH$1] === 0).map(
|
|
1327
|
+
(row, index) => [index, index].concat(row.slice(2))
|
|
1328
|
+
);
|
|
1329
|
+
requestAnimationFrame(() => {
|
|
1330
|
+
this.sendRowsToClient();
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
select(selected) {
|
|
1334
|
+
const updatedRows = [];
|
|
1335
|
+
for (const row of __privateGet$2(this, _data$1)) {
|
|
1336
|
+
const { [IDX$1]: rowIndex, [SELECTED$1]: sel } = row;
|
|
1337
|
+
const wasSelected = sel === 1;
|
|
1338
|
+
const nowSelected = vuuUtils.isSelected(selected, rowIndex);
|
|
1339
|
+
if (nowSelected !== wasSelected) {
|
|
1340
|
+
const selectedRow = row.slice();
|
|
1341
|
+
selectedRow[SELECTED$1] = nowSelected ? 1 : 0;
|
|
1342
|
+
__privateGet$2(this, _data$1)[rowIndex] = selectedRow;
|
|
1343
|
+
updatedRows.push(selectedRow);
|
|
1344
|
+
}
|
|
1345
|
+
}
|
|
1346
|
+
if (updatedRows.length > 0) {
|
|
1347
|
+
this.clientCallback?.({
|
|
1348
|
+
clientViewportId: this.viewport,
|
|
1349
|
+
mode: "update",
|
|
1350
|
+
type: "viewport-update",
|
|
1351
|
+
rows: updatedRows
|
|
1352
|
+
});
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
getRowKey(keyOrIndex) {
|
|
1356
|
+
if (typeof keyOrIndex === "string") {
|
|
1357
|
+
return keyOrIndex;
|
|
1358
|
+
}
|
|
1359
|
+
const row = this.visibleRows[keyOrIndex];
|
|
1360
|
+
if (row === void 0) {
|
|
1361
|
+
throw Error(`row not found at index ${keyOrIndex}`);
|
|
1362
|
+
}
|
|
1363
|
+
return row?.[KEY$2];
|
|
1364
|
+
}
|
|
1365
|
+
openTreeNode(keyOrIndex) {
|
|
1366
|
+
const key = this.getRowKey(keyOrIndex);
|
|
1367
|
+
this.expandedRows.add(key);
|
|
1368
|
+
this.visibleRows = getVisibleRows$1(__privateGet$2(this, _data$1), this.expandedRows);
|
|
1369
|
+
const { from, to } = __privateGet$2(this, _range);
|
|
1370
|
+
this.clientCallback?.({
|
|
1371
|
+
clientViewportId: this.viewport,
|
|
1372
|
+
mode: "batch",
|
|
1373
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow$1(row, this.keys)),
|
|
1374
|
+
size: this.visibleRows.length,
|
|
1375
|
+
type: "viewport-update"
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
closeTreeNode(keyOrIndex, cascade = false) {
|
|
1379
|
+
const key = this.getRowKey(keyOrIndex);
|
|
1380
|
+
this.expandedRows.delete(key);
|
|
1381
|
+
if (cascade) {
|
|
1382
|
+
for (const rowKey of this.expandedRows.keys()) {
|
|
1383
|
+
if (rowKey.startsWith(key)) {
|
|
1384
|
+
this.expandedRows.delete(rowKey);
|
|
1385
|
+
}
|
|
1386
|
+
}
|
|
1387
|
+
}
|
|
1388
|
+
this.visibleRows = getVisibleRows$1(__privateGet$2(this, _data$1), this.expandedRows);
|
|
1389
|
+
this.sendRowsToClient();
|
|
1390
|
+
}
|
|
1391
|
+
get status() {
|
|
1392
|
+
return __privateGet$2(this, _status$1);
|
|
1393
|
+
}
|
|
1394
|
+
get config() {
|
|
1395
|
+
return __privateGet$2(this, _config);
|
|
1396
|
+
}
|
|
1397
|
+
applyConfig() {
|
|
1398
|
+
return vuuUtils.NO_CONFIG_CHANGES;
|
|
1399
|
+
}
|
|
1400
|
+
get selectedRowsCount() {
|
|
1401
|
+
return __privateGet$2(this, _selectedRowsCount$1);
|
|
1402
|
+
}
|
|
1403
|
+
get size() {
|
|
1404
|
+
return __privateGet$2(this, _size$1);
|
|
1405
|
+
}
|
|
1406
|
+
get range() {
|
|
1407
|
+
return __privateGet$2(this, _range);
|
|
1408
|
+
}
|
|
1409
|
+
set range(range) {
|
|
1410
|
+
__privateSet$1(this, _range, range);
|
|
1411
|
+
this.keys.reset(range);
|
|
1412
|
+
requestAnimationFrame(() => {
|
|
1413
|
+
this.sendRowsToClient();
|
|
1414
|
+
});
|
|
1415
|
+
}
|
|
1416
|
+
sendRowsToClient() {
|
|
1417
|
+
const { from, to } = __privateGet$2(this, _range);
|
|
1418
|
+
this.clientCallback?.({
|
|
1419
|
+
clientViewportId: this.viewport,
|
|
1420
|
+
mode: "batch",
|
|
1421
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow$1(row, this.keys)),
|
|
1422
|
+
size: this.visibleRows.length,
|
|
1423
|
+
type: "viewport-update"
|
|
1424
|
+
});
|
|
1425
|
+
}
|
|
1426
|
+
get columns() {
|
|
1427
|
+
return __privateGet$2(this, _config).columns;
|
|
1428
|
+
}
|
|
1429
|
+
set columns(columns) {
|
|
1430
|
+
__privateSet$1(this, _config, {
|
|
1431
|
+
...__privateGet$2(this, _config),
|
|
1432
|
+
columns
|
|
1433
|
+
});
|
|
1434
|
+
}
|
|
1435
|
+
get aggregations() {
|
|
1436
|
+
return __privateGet$2(this, _aggregations$1);
|
|
1437
|
+
}
|
|
1438
|
+
set aggregations(aggregations) {
|
|
1439
|
+
__privateSet$1(this, _aggregations$1, aggregations);
|
|
1440
|
+
}
|
|
1441
|
+
get sort() {
|
|
1442
|
+
return __privateGet$2(this, _sort);
|
|
1443
|
+
}
|
|
1444
|
+
set sort(sort) {
|
|
1445
|
+
__privateSet$1(this, _sort, sort);
|
|
1446
|
+
}
|
|
1447
|
+
get filter() {
|
|
1448
|
+
return __privateGet$2(this, _filter);
|
|
1449
|
+
}
|
|
1450
|
+
set filter(filter) {
|
|
1451
|
+
__privateSet$1(this, _filter, filter);
|
|
1452
|
+
}
|
|
1453
|
+
get groupBy() {
|
|
1454
|
+
return __privateGet$2(this, _groupBy);
|
|
1455
|
+
}
|
|
1456
|
+
set groupBy(groupBy) {
|
|
1457
|
+
__privateSet$1(this, _groupBy, groupBy);
|
|
1458
|
+
}
|
|
1459
|
+
get title() {
|
|
1460
|
+
return __privateGet$2(this, _title) ?? "";
|
|
1461
|
+
}
|
|
1462
|
+
set title(title) {
|
|
1463
|
+
__privateSet$1(this, _title, title);
|
|
1464
|
+
}
|
|
1465
|
+
createLink({
|
|
1466
|
+
parentVpId,
|
|
1467
|
+
link: { fromColumn, toColumn }
|
|
1468
|
+
}) {
|
|
1469
|
+
console.log("create link", {
|
|
1470
|
+
parentVpId,
|
|
1471
|
+
fromColumn,
|
|
1472
|
+
toColumn
|
|
1473
|
+
});
|
|
1474
|
+
}
|
|
1475
|
+
removeLink() {
|
|
1476
|
+
console.log("remove link");
|
|
1477
|
+
}
|
|
1478
|
+
async remoteProcedureCall() {
|
|
1479
|
+
return Promise.reject();
|
|
1480
|
+
}
|
|
1481
|
+
async menuRpcCall(rpcRequest) {
|
|
1482
|
+
console.log("rmenuRpcCall", {
|
|
1483
|
+
rpcRequest
|
|
1484
|
+
});
|
|
1485
|
+
return void 0;
|
|
1486
|
+
}
|
|
1487
|
+
applyEdit(rowKey, columnName, value) {
|
|
1488
|
+
console.log(`ArrayDataSource applyEdit ${rowKey} ${columnName} ${value}`);
|
|
1489
|
+
return Promise.resolve(true);
|
|
1490
|
+
}
|
|
1491
|
+
getChildRows(rowKey) {
|
|
1492
|
+
const parentRow = __privateGet$2(this, _data$1).find((row) => row[KEY$2] === rowKey);
|
|
1493
|
+
if (parentRow) {
|
|
1494
|
+
const { [IDX$1]: parentIdx, [DEPTH$1]: parentDepth } = parentRow;
|
|
1495
|
+
let rowIdx = parentIdx + 1;
|
|
1496
|
+
const childRows = [];
|
|
1497
|
+
do {
|
|
1498
|
+
const { [DEPTH$1]: depth } = __privateGet$2(this, _data$1)[rowIdx];
|
|
1499
|
+
if (depth === parentDepth + 1) {
|
|
1500
|
+
childRows.push(__privateGet$2(this, _data$1)[rowIdx]);
|
|
1501
|
+
} else if (depth <= parentDepth) {
|
|
1502
|
+
break;
|
|
1503
|
+
}
|
|
1504
|
+
rowIdx += 1;
|
|
1505
|
+
} while (rowIdx < __privateGet$2(this, _data$1).length);
|
|
1506
|
+
return childRows;
|
|
1507
|
+
} else {
|
|
1508
|
+
console.warn(
|
|
1509
|
+
`JsonDataSource getChildRows row not found for key ${rowKey}`
|
|
1510
|
+
);
|
|
1511
|
+
}
|
|
1512
|
+
return [];
|
|
1513
|
+
}
|
|
1514
|
+
getRowsAtDepth(depth, visibleOnly = true) {
|
|
1515
|
+
const rows = visibleOnly ? this.visibleRows : __privateGet$2(this, _data$1);
|
|
1516
|
+
return rows.filter((row) => row[DEPTH$1] === depth);
|
|
1517
|
+
}
|
|
1518
|
+
}
|
|
1519
|
+
_aggregations$1 = new WeakMap();
|
|
1520
|
+
_config = new WeakMap();
|
|
1521
|
+
_data$1 = new WeakMap();
|
|
1522
|
+
_filter = new WeakMap();
|
|
1523
|
+
_groupBy = new WeakMap();
|
|
1524
|
+
_range = new WeakMap();
|
|
1525
|
+
_selectedRowsCount$1 = new WeakMap();
|
|
1526
|
+
_size$1 = new WeakMap();
|
|
1527
|
+
_sort = new WeakMap();
|
|
1528
|
+
_status$1 = new WeakMap();
|
|
1529
|
+
_title = new WeakMap();
|
|
1530
|
+
function getVisibleRows$1(rows, expandedKeys) {
|
|
1531
|
+
const visibleRows = [];
|
|
1532
|
+
const index = { value: 0 };
|
|
1533
|
+
for (let i = 0; i < rows.length; i++) {
|
|
1534
|
+
const row = rows[i];
|
|
1535
|
+
const { [DEPTH$1]: depth, [KEY$2]: key, [IS_LEAF$1]: isLeaf } = row;
|
|
1536
|
+
const isExpanded = expandedKeys.has(key);
|
|
1537
|
+
visibleRows.push(cloneRow$1(row, index, isExpanded));
|
|
1538
|
+
if (!isLeaf && !isExpanded) {
|
|
1539
|
+
do {
|
|
1540
|
+
i += 1;
|
|
1541
|
+
} while (i < rows.length - 1 && rows[i + 1][DEPTH$1] > depth);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
return visibleRows;
|
|
1545
|
+
}
|
|
1546
|
+
const cloneRow$1 = (row, index, isExpanded) => {
|
|
1547
|
+
const dolly = row.slice();
|
|
1548
|
+
dolly[0] = index.value;
|
|
1549
|
+
dolly[1] = index.value;
|
|
1550
|
+
if (isExpanded) {
|
|
1551
|
+
dolly[IS_EXPANDED$1] = true;
|
|
1552
|
+
}
|
|
1553
|
+
index.value += 1;
|
|
1554
|
+
return dolly;
|
|
1555
|
+
};
|
|
1556
|
+
|
|
1557
|
+
var __defProp$1 = Object.defineProperty;
|
|
1558
|
+
var __typeError$1 = (msg) => {
|
|
1559
|
+
throw TypeError(msg);
|
|
1560
|
+
};
|
|
1561
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1562
|
+
var __publicField$1 = (obj, key, value) => __defNormalProp$1(obj, key + "" , value);
|
|
1563
|
+
var __accessCheck$1 = (obj, member, msg) => member.has(obj) || __typeError$1("Cannot " + msg);
|
|
1564
|
+
var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1565
|
+
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1566
|
+
var _iconMap;
|
|
1567
|
+
const { KEY: KEY$1 } = vuuUtils.metadataKeys;
|
|
1568
|
+
class IconProvider {
|
|
1569
|
+
constructor() {
|
|
1570
|
+
__privateAdd$1(this, _iconMap, {});
|
|
1571
|
+
__publicField$1(this, "getIcon", (row) => {
|
|
1572
|
+
const key = row[KEY$1];
|
|
1573
|
+
return __privateGet$1(this, _iconMap)[key];
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
setIcon(key, icon) {
|
|
1577
|
+
__privateGet$1(this, _iconMap)[key] = icon;
|
|
1578
|
+
}
|
|
1579
|
+
}
|
|
1580
|
+
_iconMap = new WeakMap();
|
|
1581
|
+
|
|
1582
|
+
var __defProp = Object.defineProperty;
|
|
1583
|
+
var __typeError = (msg) => {
|
|
1584
|
+
throw TypeError(msg);
|
|
1585
|
+
};
|
|
1586
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
1587
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
1588
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
1589
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
1590
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
1591
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
|
|
1592
|
+
var __privateWrapper = (obj, member, setter, getter) => ({
|
|
1593
|
+
set _(value) {
|
|
1594
|
+
__privateSet(obj, member, value);
|
|
1595
|
+
},
|
|
1596
|
+
get _() {
|
|
1597
|
+
return __privateGet(obj, member, getter);
|
|
1598
|
+
}
|
|
1599
|
+
});
|
|
1600
|
+
var _aggregations, _data, _iconProvider, _selectedRowsCount, _size, _status, _filterSet;
|
|
1601
|
+
const NULL_SCHEMA = { columns: [], key: "", table: { module: "", table: "" } };
|
|
1602
|
+
const { COUNT, DEPTH, IDX, IS_EXPANDED, IS_LEAF, KEY, SELECTED } = vuuUtils.metadataKeys;
|
|
1603
|
+
const toClientRow = (row, keys) => {
|
|
1604
|
+
const [rowIndex] = row;
|
|
1605
|
+
const clientRow = row.slice();
|
|
1606
|
+
clientRow[1] = keys.keyFor(rowIndex);
|
|
1607
|
+
return clientRow;
|
|
1608
|
+
};
|
|
1609
|
+
class TreeDataSource extends vuuUtils.BaseDataSource {
|
|
1610
|
+
constructor({ data, ...props }) {
|
|
1611
|
+
super(props);
|
|
1612
|
+
__publicField(this, "columnDescriptors");
|
|
1613
|
+
__publicField(this, "clientCallback");
|
|
1614
|
+
__publicField(this, "expandedRows", /* @__PURE__ */ new Set());
|
|
1615
|
+
__publicField(this, "visibleRows", []);
|
|
1616
|
+
__publicField(this, "visibleRowIndex", {});
|
|
1617
|
+
__privateAdd(this, _aggregations, []);
|
|
1618
|
+
__privateAdd(this, _data);
|
|
1619
|
+
__privateAdd(this, _iconProvider);
|
|
1620
|
+
__privateAdd(this, _selectedRowsCount, 0);
|
|
1621
|
+
__privateAdd(this, _size, 0);
|
|
1622
|
+
__privateAdd(this, _status, "initialising");
|
|
1623
|
+
__privateAdd(this, _filterSet);
|
|
1624
|
+
__publicField(this, "rowCount");
|
|
1625
|
+
__publicField(this, "keys", new vuuUtils.KeySet(this._range));
|
|
1626
|
+
__publicField(this, "indexOfRowWithKey", (key) => __privateGet(this, _data).findIndex((row) => row[KEY] === key));
|
|
1627
|
+
if (!data) {
|
|
1628
|
+
throw Error("TreeDataSource constructor called without data");
|
|
1629
|
+
}
|
|
1630
|
+
__privateSet(this, _iconProvider, new IconProvider());
|
|
1631
|
+
[this.columnDescriptors, __privateWrapper(this, _data)._] = vuuUtils.treeToDataSourceRows(
|
|
1632
|
+
data,
|
|
1633
|
+
__privateGet(this, _iconProvider)
|
|
1634
|
+
);
|
|
1635
|
+
if (this.columnDescriptors) {
|
|
1636
|
+
const columns = this.columnDescriptors.map((c) => c.name);
|
|
1637
|
+
this._config = {
|
|
1638
|
+
...this._config,
|
|
1639
|
+
columns,
|
|
1640
|
+
groupBy: columns.slice(1)
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
async subscribe({
|
|
1645
|
+
aggregations,
|
|
1646
|
+
columns,
|
|
1647
|
+
range,
|
|
1648
|
+
revealSelected,
|
|
1649
|
+
selectedKeyValues,
|
|
1650
|
+
viewport = this.viewport ?? vuuUtils.uuid()
|
|
1651
|
+
}, callback) {
|
|
1652
|
+
this.clientCallback = callback;
|
|
1653
|
+
if (aggregations) {
|
|
1654
|
+
__privateSet(this, _aggregations, aggregations);
|
|
1655
|
+
}
|
|
1656
|
+
if (columns) {
|
|
1657
|
+
this._config = {
|
|
1658
|
+
...this._config,
|
|
1659
|
+
columns
|
|
1660
|
+
};
|
|
1661
|
+
}
|
|
1662
|
+
if (__privateGet(this, _status) !== "initialising") {
|
|
1663
|
+
return;
|
|
1664
|
+
}
|
|
1665
|
+
this.viewport = viewport;
|
|
1666
|
+
__privateSet(this, _status, "subscribed");
|
|
1667
|
+
__privateSet(this, _selectedRowsCount, selectedKeyValues?.length ?? 0);
|
|
1668
|
+
if (selectedKeyValues) {
|
|
1669
|
+
this.applySelectedKeyValues(selectedKeyValues, revealSelected);
|
|
1670
|
+
}
|
|
1671
|
+
[this.visibleRows, this.visibleRowIndex] = getVisibleRows(
|
|
1672
|
+
__privateGet(this, _data),
|
|
1673
|
+
this.expandedRows
|
|
1674
|
+
);
|
|
1675
|
+
this.clientCallback?.({
|
|
1676
|
+
aggregations: __privateGet(this, _aggregations),
|
|
1677
|
+
type: "subscribed",
|
|
1678
|
+
clientViewportId: this.viewport,
|
|
1679
|
+
columns: this.columns,
|
|
1680
|
+
filterSpec: this.filter,
|
|
1681
|
+
groupBy: this._config.groupBy,
|
|
1682
|
+
range: this.range,
|
|
1683
|
+
sort: this.sort,
|
|
1684
|
+
tableSchema: NULL_SCHEMA
|
|
1685
|
+
});
|
|
1686
|
+
this.clientCallback({
|
|
1687
|
+
clientViewportId: this.viewport,
|
|
1688
|
+
mode: "size-only",
|
|
1689
|
+
type: "viewport-update",
|
|
1690
|
+
size: this.visibleRows.length
|
|
1691
|
+
});
|
|
1692
|
+
if (range && !this._range.equals(range)) {
|
|
1693
|
+
this.range = range;
|
|
1694
|
+
} else if (this._range !== vuuUtils.NULL_RANGE) {
|
|
1695
|
+
this.sendRowsToClient();
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
unsubscribe() {
|
|
1699
|
+
console.log("noop");
|
|
1700
|
+
}
|
|
1701
|
+
suspend() {
|
|
1702
|
+
console.log("noop");
|
|
1703
|
+
return this;
|
|
1704
|
+
}
|
|
1705
|
+
resume() {
|
|
1706
|
+
console.log("noop");
|
|
1707
|
+
return this;
|
|
1708
|
+
}
|
|
1709
|
+
disable() {
|
|
1710
|
+
console.log("noop");
|
|
1711
|
+
return this;
|
|
1712
|
+
}
|
|
1713
|
+
enable() {
|
|
1714
|
+
console.log("noop");
|
|
1715
|
+
return this;
|
|
1716
|
+
}
|
|
1717
|
+
set data(data) {
|
|
1718
|
+
[this.columnDescriptors, __privateWrapper(this, _data)._] = vuuUtils.treeToDataSourceRows(data);
|
|
1719
|
+
requestAnimationFrame(() => {
|
|
1720
|
+
this.sendRowsToClient();
|
|
1721
|
+
});
|
|
1722
|
+
}
|
|
1723
|
+
get filter() {
|
|
1724
|
+
return this._config.filterSpec;
|
|
1725
|
+
}
|
|
1726
|
+
set filter(filter) {
|
|
1727
|
+
this._config = {
|
|
1728
|
+
...this._config,
|
|
1729
|
+
filterSpec: filter
|
|
1730
|
+
};
|
|
1731
|
+
if (filter.filter) {
|
|
1732
|
+
this.applyFilter(filter);
|
|
1733
|
+
} else {
|
|
1734
|
+
__privateSet(this, _filterSet, void 0);
|
|
1735
|
+
}
|
|
1736
|
+
[this.visibleRows, this.visibleRowIndex] = getVisibleRows(
|
|
1737
|
+
__privateGet(this, _data),
|
|
1738
|
+
this.expandedRows,
|
|
1739
|
+
__privateGet(this, _filterSet)
|
|
1740
|
+
);
|
|
1741
|
+
const { from, to } = this.range;
|
|
1742
|
+
this.clientCallback?.({
|
|
1743
|
+
clientViewportId: this.viewport,
|
|
1744
|
+
mode: "batch",
|
|
1745
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow(row, this.keys)),
|
|
1746
|
+
size: this.visibleRows.length,
|
|
1747
|
+
type: "viewport-update"
|
|
1748
|
+
});
|
|
1749
|
+
}
|
|
1750
|
+
applyFilter({ filter: filterQuery, filterStruct }) {
|
|
1751
|
+
const filter = filterStruct ?? vuuFilterParser.parseFilter(filterQuery);
|
|
1752
|
+
if (vuuUtils.isSingleValueFilter(filter)) {
|
|
1753
|
+
const filterSet = [];
|
|
1754
|
+
const regex = new RegExp(`${filter.value}`, "i");
|
|
1755
|
+
for (const row of __privateGet(this, _data)) {
|
|
1756
|
+
const { [KEY]: key, [IDX]: idx } = row;
|
|
1757
|
+
if (regex.test(vuuUtils.lastPathSegment(key, "|"))) {
|
|
1758
|
+
filterSet.push(idx);
|
|
1759
|
+
}
|
|
1760
|
+
}
|
|
1761
|
+
__privateSet(this, _filterSet, filterSet);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
/**
|
|
1765
|
+
* used to apply an initial selection. These may not necessarily be
|
|
1766
|
+
* visible. If revealOnSelect is in force, expand nodes as necessary
|
|
1767
|
+
* to ensure selected nodes are visible
|
|
1768
|
+
*/
|
|
1769
|
+
applySelectedKeyValues(keys, revealSelected = false) {
|
|
1770
|
+
keys.forEach((key) => {
|
|
1771
|
+
const rowIdx = this.indexOfRowWithKey(key);
|
|
1772
|
+
const row = __privateGet(this, _data)[rowIdx];
|
|
1773
|
+
row[SELECTED] = 1;
|
|
1774
|
+
if (revealSelected && row[DEPTH] !== 1) {
|
|
1775
|
+
const keys2 = key.slice(6).split("|").slice(0, -1);
|
|
1776
|
+
let path = "$root";
|
|
1777
|
+
do {
|
|
1778
|
+
path = `${path}|${keys2.shift()}`;
|
|
1779
|
+
this.expandedRows.add(path);
|
|
1780
|
+
} while (keys2.length);
|
|
1781
|
+
}
|
|
1782
|
+
});
|
|
1783
|
+
}
|
|
1784
|
+
// Incoming Selection references visibleRow indices
|
|
1785
|
+
select(selected) {
|
|
1786
|
+
const updatedRows = [];
|
|
1787
|
+
for (const row of this.visibleRows) {
|
|
1788
|
+
const { [IDX]: rowIndex, [SELECTED]: sel } = row;
|
|
1789
|
+
const wasSelected = sel === 1;
|
|
1790
|
+
const nowSelected = vuuUtils.isSelected(selected, rowIndex);
|
|
1791
|
+
if (nowSelected !== wasSelected) {
|
|
1792
|
+
const selectedRow = row.slice();
|
|
1793
|
+
const selectedValue = nowSelected ? 1 : 0;
|
|
1794
|
+
selectedRow[SELECTED] = selectedValue;
|
|
1795
|
+
const dataRowIdx = this.visibleRowIndex[rowIndex];
|
|
1796
|
+
this.visibleRows[rowIndex] = selectedRow;
|
|
1797
|
+
__privateGet(this, _data)[dataRowIdx][SELECTED] = selectedValue;
|
|
1798
|
+
updatedRows.push(selectedRow);
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
if (updatedRows.length > 0) {
|
|
1802
|
+
this.clientCallback?.({
|
|
1803
|
+
clientViewportId: this.viewport,
|
|
1804
|
+
mode: "update",
|
|
1805
|
+
type: "viewport-update",
|
|
1806
|
+
rows: updatedRows
|
|
1807
|
+
});
|
|
1808
|
+
}
|
|
1809
|
+
}
|
|
1810
|
+
getRowKey(keyOrIndex) {
|
|
1811
|
+
if (typeof keyOrIndex === "string") {
|
|
1812
|
+
return keyOrIndex;
|
|
1813
|
+
}
|
|
1814
|
+
const row = this.getRowAtIndex(keyOrIndex);
|
|
1815
|
+
if (row === void 0) {
|
|
1816
|
+
throw Error(`row not found at index ${keyOrIndex}`);
|
|
1817
|
+
}
|
|
1818
|
+
return row[KEY];
|
|
1819
|
+
}
|
|
1820
|
+
openTreeNode(keyOrIndex) {
|
|
1821
|
+
const key = this.getRowKey(keyOrIndex);
|
|
1822
|
+
this.expandedRows.add(key);
|
|
1823
|
+
[this.visibleRows, this.visibleRowIndex] = getVisibleRows(
|
|
1824
|
+
__privateGet(this, _data),
|
|
1825
|
+
this.expandedRows
|
|
1826
|
+
);
|
|
1827
|
+
const { from, to } = this._range;
|
|
1828
|
+
this.clientCallback?.({
|
|
1829
|
+
clientViewportId: this.viewport,
|
|
1830
|
+
mode: "batch",
|
|
1831
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow(row, this.keys)),
|
|
1832
|
+
size: this.visibleRows.length,
|
|
1833
|
+
type: "viewport-update"
|
|
1834
|
+
});
|
|
1835
|
+
}
|
|
1836
|
+
closeTreeNode(keyOrIndex, cascade = false) {
|
|
1837
|
+
const key = this.getRowKey(keyOrIndex);
|
|
1838
|
+
this.expandedRows.delete(key);
|
|
1839
|
+
if (cascade) {
|
|
1840
|
+
for (const rowKey of this.expandedRows.keys()) {
|
|
1841
|
+
if (rowKey.startsWith(key)) {
|
|
1842
|
+
this.expandedRows.delete(rowKey);
|
|
1843
|
+
}
|
|
1844
|
+
}
|
|
1845
|
+
}
|
|
1846
|
+
[this.visibleRows, this.visibleRowIndex] = getVisibleRows(
|
|
1847
|
+
__privateGet(this, _data),
|
|
1848
|
+
this.expandedRows
|
|
1849
|
+
);
|
|
1850
|
+
this.sendRowsToClient();
|
|
1851
|
+
}
|
|
1852
|
+
get status() {
|
|
1853
|
+
return __privateGet(this, _status);
|
|
1854
|
+
}
|
|
1855
|
+
get selectedRowsCount() {
|
|
1856
|
+
return __privateGet(this, _selectedRowsCount);
|
|
1857
|
+
}
|
|
1858
|
+
get size() {
|
|
1859
|
+
return __privateGet(this, _size);
|
|
1860
|
+
}
|
|
1861
|
+
rangeRequest(range) {
|
|
1862
|
+
this.keys.reset(range);
|
|
1863
|
+
requestAnimationFrame(() => {
|
|
1864
|
+
this.sendRowsToClient();
|
|
1865
|
+
});
|
|
1866
|
+
}
|
|
1867
|
+
sendRowsToClient() {
|
|
1868
|
+
const { from, to } = this._range;
|
|
1869
|
+
this.clientCallback?.({
|
|
1870
|
+
clientViewportId: this.viewport,
|
|
1871
|
+
mode: "batch",
|
|
1872
|
+
rows: this.visibleRows.slice(from, to).map((row) => toClientRow(row, this.keys)),
|
|
1873
|
+
size: this.visibleRows.length,
|
|
1874
|
+
type: "viewport-update"
|
|
1875
|
+
});
|
|
1876
|
+
}
|
|
1877
|
+
createLink({
|
|
1878
|
+
parentVpId,
|
|
1879
|
+
link: { fromColumn, toColumn }
|
|
1880
|
+
}) {
|
|
1881
|
+
console.log("create link", {
|
|
1882
|
+
parentVpId,
|
|
1883
|
+
fromColumn,
|
|
1884
|
+
toColumn
|
|
1885
|
+
});
|
|
1886
|
+
}
|
|
1887
|
+
removeLink() {
|
|
1888
|
+
console.log("remove link");
|
|
1889
|
+
}
|
|
1890
|
+
async remoteProcedureCall() {
|
|
1891
|
+
return Promise.reject();
|
|
1892
|
+
}
|
|
1893
|
+
async menuRpcCall(rpcRequest) {
|
|
1894
|
+
console.log("rmenuRpcCall", {
|
|
1895
|
+
rpcRequest
|
|
1896
|
+
});
|
|
1897
|
+
return void 0;
|
|
1898
|
+
}
|
|
1899
|
+
applyEdit(rowKey, columnName, value) {
|
|
1900
|
+
console.log(`ArrayDataSource applyEdit ${rowKey} ${columnName} ${value}`);
|
|
1901
|
+
return Promise.resolve(true);
|
|
1902
|
+
}
|
|
1903
|
+
getChildRows(rowKey) {
|
|
1904
|
+
const parentRow = __privateGet(this, _data).find((row) => row[KEY] === rowKey);
|
|
1905
|
+
if (parentRow) {
|
|
1906
|
+
const { [IDX]: parentIdx, [DEPTH]: parentDepth } = parentRow;
|
|
1907
|
+
let rowIdx = parentIdx + 1;
|
|
1908
|
+
const childRows = [];
|
|
1909
|
+
do {
|
|
1910
|
+
const { [DEPTH]: depth } = __privateGet(this, _data)[rowIdx];
|
|
1911
|
+
if (depth === parentDepth + 1) {
|
|
1912
|
+
childRows.push(__privateGet(this, _data)[rowIdx]);
|
|
1913
|
+
} else if (depth <= parentDepth) {
|
|
1914
|
+
break;
|
|
1915
|
+
}
|
|
1916
|
+
rowIdx += 1;
|
|
1917
|
+
} while (rowIdx < __privateGet(this, _data).length);
|
|
1918
|
+
return childRows;
|
|
1919
|
+
} else {
|
|
1920
|
+
console.warn(
|
|
1921
|
+
`JsonDataSource getChildRows row not found for key ${rowKey}`
|
|
1922
|
+
);
|
|
1923
|
+
}
|
|
1924
|
+
return [];
|
|
1925
|
+
}
|
|
1926
|
+
getRowsAtDepth(depth, visibleOnly = true) {
|
|
1927
|
+
const rows = visibleOnly ? this.visibleRows : __privateGet(this, _data);
|
|
1928
|
+
return rows.filter((row) => row[DEPTH] === depth);
|
|
1929
|
+
}
|
|
1930
|
+
getRowAtIndex(rowIdx) {
|
|
1931
|
+
return this.visibleRows[rowIdx];
|
|
1932
|
+
}
|
|
1933
|
+
}
|
|
1934
|
+
_aggregations = new WeakMap();
|
|
1935
|
+
_data = new WeakMap();
|
|
1936
|
+
_iconProvider = new WeakMap();
|
|
1937
|
+
_selectedRowsCount = new WeakMap();
|
|
1938
|
+
_size = new WeakMap();
|
|
1939
|
+
_status = new WeakMap();
|
|
1940
|
+
_filterSet = new WeakMap();
|
|
1941
|
+
function getVisibleRows(rows, expandedKeys, filterset) {
|
|
1942
|
+
const visibleRows = [];
|
|
1943
|
+
const visibleRowIndex = {};
|
|
1944
|
+
const data = filterset ?? rows;
|
|
1945
|
+
for (let i = 0, index = 0; i < data.length; i++) {
|
|
1946
|
+
const idx = filterset ? filterset[i] : i;
|
|
1947
|
+
const row = rows[idx];
|
|
1948
|
+
const {
|
|
1949
|
+
[COUNT]: count,
|
|
1950
|
+
[DEPTH]: depth,
|
|
1951
|
+
[KEY]: key,
|
|
1952
|
+
[IS_LEAF]: isLeaf
|
|
1953
|
+
} = row;
|
|
1954
|
+
if (filterset) {
|
|
1955
|
+
const previousRow = visibleRows.at(-1);
|
|
1956
|
+
if (vuuUtils.missingAncestor(row, previousRow)) {
|
|
1957
|
+
let currentRow = row;
|
|
1958
|
+
const missingRows = [];
|
|
1959
|
+
while (currentRow) {
|
|
1960
|
+
currentRow = vuuUtils.getParentRow(rows, currentRow);
|
|
1961
|
+
if (currentRow) {
|
|
1962
|
+
missingRows.unshift(currentRow);
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
missingRows.forEach((row2) => {
|
|
1966
|
+
visibleRows.push(cloneRow(row2, index++, true));
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
visibleRows.push(cloneRow(row, index++, true));
|
|
1970
|
+
visibleRowIndex[index] = i;
|
|
1971
|
+
} else {
|
|
1972
|
+
const isExpanded = expandedKeys.has(key);
|
|
1973
|
+
visibleRows.push(cloneRow(row, index, isExpanded));
|
|
1974
|
+
visibleRowIndex[index++] = i;
|
|
1975
|
+
const skipNonVisibleRows = !isLeaf && !isExpanded && count > 0;
|
|
1976
|
+
if (skipNonVisibleRows) {
|
|
1977
|
+
do {
|
|
1978
|
+
i += 1;
|
|
1979
|
+
} while (i < rows.length - 1 && rows[i + 1][DEPTH] > depth);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
return [visibleRows, visibleRowIndex];
|
|
1984
|
+
}
|
|
1985
|
+
const cloneRow = (row, index, isExpanded) => {
|
|
1986
|
+
const dolly = row.slice();
|
|
1987
|
+
dolly[0] = index;
|
|
1988
|
+
dolly[1] = index;
|
|
1989
|
+
if (isExpanded) {
|
|
1990
|
+
dolly[IS_EXPANDED] = true;
|
|
1991
|
+
}
|
|
1992
|
+
return dolly;
|
|
1993
|
+
};
|
|
1994
|
+
|
|
1995
|
+
exports.ArrayDataSource = ArrayDataSource;
|
|
1996
|
+
exports.JsonDataSource = JsonDataSource;
|
|
1997
|
+
exports.TreeDataSource = TreeDataSource;
|
|
12
1998
|
//# sourceMappingURL=index.js.map
|