@vuu-ui/vuu-data-local 3.0.0 → 3.1.0-beta.2

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 (46) hide show
  1. package/package.json +17 -13
  2. package/src/array-data-source/aggregate-utils.js +121 -0
  3. package/src/array-data-source/array-data-source.js +689 -0
  4. package/src/array-data-source/array-data-utils.js +41 -0
  5. package/src/array-data-source/group-utils.js +138 -0
  6. package/src/array-data-source/sort-utils.js +56 -0
  7. package/src/index.js +3 -0
  8. package/src/json-data-source/JsonDataSource.js +319 -0
  9. package/src/tree-data-source/IconProvider.js +11 -0
  10. package/src/tree-data-source/TreeDataSource.js +353 -0
  11. package/cjs/array-data-source/aggregate-utils.js +0 -237
  12. package/cjs/array-data-source/aggregate-utils.js.map +0 -1
  13. package/cjs/array-data-source/array-data-source.js +0 -944
  14. package/cjs/array-data-source/array-data-source.js.map +0 -1
  15. package/cjs/array-data-source/array-data-utils.js +0 -62
  16. package/cjs/array-data-source/array-data-utils.js.map +0 -1
  17. package/cjs/array-data-source/group-utils.js +0 -187
  18. package/cjs/array-data-source/group-utils.js.map +0 -1
  19. package/cjs/array-data-source/sort-utils.js +0 -73
  20. package/cjs/array-data-source/sort-utils.js.map +0 -1
  21. package/cjs/index.js +0 -12
  22. package/cjs/index.js.map +0 -1
  23. package/cjs/json-data-source/JsonDataSource.js +0 -404
  24. package/cjs/json-data-source/JsonDataSource.js.map +0 -1
  25. package/cjs/tree-data-source/IconProvider.js +0 -28
  26. package/cjs/tree-data-source/IconProvider.js.map +0 -1
  27. package/cjs/tree-data-source/TreeDataSource.js +0 -434
  28. package/cjs/tree-data-source/TreeDataSource.js.map +0 -1
  29. package/esm/array-data-source/aggregate-utils.js +0 -235
  30. package/esm/array-data-source/aggregate-utils.js.map +0 -1
  31. package/esm/array-data-source/array-data-source.js +0 -942
  32. package/esm/array-data-source/array-data-source.js.map +0 -1
  33. package/esm/array-data-source/array-data-utils.js +0 -59
  34. package/esm/array-data-source/array-data-utils.js.map +0 -1
  35. package/esm/array-data-source/group-utils.js +0 -183
  36. package/esm/array-data-source/group-utils.js.map +0 -1
  37. package/esm/array-data-source/sort-utils.js +0 -69
  38. package/esm/array-data-source/sort-utils.js.map +0 -1
  39. package/esm/index.js +0 -4
  40. package/esm/index.js.map +0 -1
  41. package/esm/json-data-source/JsonDataSource.js +0 -402
  42. package/esm/json-data-source/JsonDataSource.js.map +0 -1
  43. package/esm/tree-data-source/IconProvider.js +0 -26
  44. package/esm/tree-data-source/IconProvider.js.map +0 -1
  45. package/esm/tree-data-source/TreeDataSource.js +0 -432
  46. package/esm/tree-data-source/TreeDataSource.js.map +0 -1
@@ -1,944 +0,0 @@
1
- 'use strict';
2
-
3
- var vuuFilterParser = require('@vuu-ui/vuu-filter-parser');
4
- var vuuUtils = require('@vuu-ui/vuu-utils');
5
- var aggregateUtils = require('./aggregate-utils.js');
6
- var arrayDataUtils = require('./array-data-utils.js');
7
- var groupUtils = require('./group-utils.js');
8
- var sortUtils = require('./sort-utils.js');
9
-
10
- var __defProp = Object.defineProperty;
11
- var __typeError = (msg) => {
12
- throw TypeError(msg);
13
- };
14
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
16
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
17
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
18
- 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);
19
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
20
- var _columnMap, _data, _freezeTimestamp, _keys, _links, _maxRangeEnd, _range, _status, _title;
21
- const { debug, info } = vuuUtils.logger("ArrayDataSource");
22
- const { KEY } = vuuUtils.metadataKeys;
23
- const toDataSourceRow = (indexOfKeyColumn, index) => (data, idx) => {
24
- const key = `${data[indexOfKeyColumn]}`;
25
- index?.set(key, idx);
26
- return [
27
- idx,
28
- idx,
29
- true,
30
- false,
31
- 1,
32
- 0,
33
- key,
34
- 0,
35
- 0,
36
- // ts
37
- false,
38
- // isNew
39
- ...data
40
- ];
41
- };
42
- const buildTableSchema = (columns, keyColumn) => {
43
- const schema = {
44
- columns: columns.map(vuuUtils.toSchemaColumn),
45
- key: keyColumn ?? columns[0].name,
46
- table: { module: "", table: "Array" }
47
- };
48
- return schema;
49
- };
50
- class ArrayDataSource extends vuuUtils.EventEmitter {
51
- constructor({
52
- aggregations,
53
- baseFilterSpec,
54
- // different from RemoteDataSource
55
- columnDescriptors,
56
- data,
57
- dataMap,
58
- filterSpec,
59
- groupBy,
60
- keyColumn,
61
- rangeChangeRowset = "delta",
62
- sort,
63
- title,
64
- viewport
65
- }) {
66
- super();
67
- __publicField(this, "clientCallback");
68
- __publicField(this, "columnDescriptors");
69
- /** sorted offsets of data within raw data, reflecting sort order
70
- * of columns specified by client.
71
- */
72
- __publicField(this, "dataIndices");
73
- /** Map reflecting positions of data items in raw data */
74
- __publicField(this, "dataMap");
75
- __publicField(this, "groupMap");
76
- /** the index of key field within raw data row */
77
- __publicField(this, "key");
78
- __publicField(this, "lastRangeServed", { from: 0, to: 0 });
79
- __publicField(this, "rangeChangeRowset");
80
- __publicField(this, "openTreeNodes", []);
81
- // Experimental. There are some config changes - first concrete example is baseFilter applied to
82
- // 'freeze' data, that should not immediately affect the displayed data, therefore not cause
83
- // range reset.
84
- __publicField(this, "preserveScrollPositionAcrossConfigChange", false);
85
- /** Map reflecting positions of columns in client data sent to user */
86
- __privateAdd(this, _columnMap);
87
- __publicField(this, "_config", vuuUtils.vanillaConfig);
88
- __privateAdd(this, _data);
89
- __privateAdd(this, _freezeTimestamp);
90
- __privateAdd(this, _keys, new vuuUtils.KeySet(vuuUtils.NULL_RANGE));
91
- __privateAdd(this, _links);
92
- __privateAdd(this, _maxRangeEnd, Number.MAX_SAFE_INTEGER);
93
- __privateAdd(this, _range, vuuUtils.Range(0, 0));
94
- __privateAdd(this, _status, "initialising");
95
- __privateAdd(this, _title);
96
- __publicField(this, "_menu");
97
- __publicField(this, "selectedRows", /* @__PURE__ */ new Set());
98
- __publicField(this, "index", /* @__PURE__ */ new Map());
99
- __publicField(this, "tableSchema");
100
- __publicField(this, "viewport");
101
- __publicField(this, "processedData");
102
- __publicField(this, "insert", (row) => {
103
- const dataSourceRow = toDataSourceRow(this.key, this.index)(row, this.size);
104
- __privateGet(this, _data).push(
105
- dataSourceRow
106
- );
107
- const { from, to } = __privateGet(this, _range);
108
- const [rowIdx] = dataSourceRow;
109
- const isSorted = vuuUtils.hasSort(this.config);
110
- const isFiltered = vuuUtils.hasFilter(this.config) || vuuUtils.hasBaseFilter(this.config);
111
- if (isSorted && isFiltered) {
112
- const meetsFilterCriteria = this.getFilterPredicate();
113
- if (meetsFilterCriteria(dataSourceRow)) {
114
- this.insertIntoSortedData(dataSourceRow);
115
- }
116
- } else if (isSorted) {
117
- this.insertIntoSortedData(dataSourceRow);
118
- } else if (isFiltered) {
119
- const meetsFilterCriteria = this.getFilterPredicate();
120
- if (meetsFilterCriteria(dataSourceRow)) {
121
- this.processedData?.push(dataSourceRow);
122
- this.sendSizeUpdateToClient();
123
- if (rowIdx >= from && rowIdx < to) {
124
- this.sendRowsToClient();
125
- }
126
- this.emit("resize", __privateGet(this, _data).length);
127
- }
128
- } else {
129
- this.sendSizeUpdateToClient();
130
- if (rowIdx >= from && rowIdx < to) {
131
- this.sendRowsToClient();
132
- }
133
- this.emit("resize", this.size);
134
- }
135
- });
136
- __publicField(this, "updateDataItem", (keyValue, columnName, value) => {
137
- this.validateDataValue(columnName, value);
138
- const colIndex = __privateGet(this, _columnMap)[columnName];
139
- const dataColIndex = this.dataMap?.[columnName];
140
- const dataIndex = this.indexOfRowWithKey(keyValue);
141
- if (dataIndex !== -1 && dataColIndex !== void 0) {
142
- const dataSourceRow = __privateGet(this, _data)[dataIndex];
143
- dataSourceRow[colIndex] = value;
144
- const { from, to } = __privateGet(this, _range);
145
- const [rowIdx] = dataSourceRow;
146
- if (rowIdx >= from && rowIdx < to) {
147
- this.sendRowsToClient(false, dataSourceRow);
148
- }
149
- }
150
- });
151
- __publicField(this, "indexOfRowWithKey", (key) => __privateGet(this, _data).findIndex((row) => row[KEY] === key));
152
- __publicField(this, "update", (row, columnName) => {
153
- const keyValue = row[this.key];
154
- const dataColIndex = this.dataMap?.[columnName];
155
- return this.updateDataItem(keyValue, columnName, row[dataColIndex]);
156
- });
157
- __publicField(this, "updateRow", (row, _columnName) => {
158
- const keyValue = row[this.key];
159
- const dataIndex = __privateGet(this, _data).findIndex((row2) => row2[KEY] === keyValue);
160
- if (dataIndex !== -1) {
161
- const dataSourceRow = toDataSourceRow(this.key)(row, dataIndex);
162
- __privateGet(this, _data)[dataIndex] = dataSourceRow;
163
- const { from, to } = __privateGet(this, _range);
164
- const isFiltered = vuuUtils.hasFilter(this.config) || vuuUtils.hasBaseFilter(this.config);
165
- const isSorted = vuuUtils.hasSort(this.config);
166
- if (isFiltered) {
167
- const meetsFilterCriteria = this.getFilterPredicate();
168
- if (meetsFilterCriteria(dataSourceRow) && this.processedData) {
169
- const dataIndex2 = this.processedData.findIndex(
170
- (row2) => row2[KEY] === keyValue
171
- );
172
- if (dataIndex2 !== -1) {
173
- const existingRow = this.processedData[dataIndex2];
174
- const newFilteredRow = existingRow.slice(0, 10).concat(dataSourceRow.slice(10));
175
- this.processedData[dataIndex2] = newFilteredRow;
176
- if (dataIndex2 >= from && dataIndex2 < to) {
177
- this.sendRowsToClient(false, newFilteredRow);
178
- }
179
- }
180
- } else if (this.processedData) {
181
- const dataIndex2 = this.processedData.findIndex(
182
- (row2) => row2[KEY] === keyValue
183
- );
184
- if (dataIndex2 !== -1) {
185
- console.log("dataRow no longer in filter set");
186
- }
187
- }
188
- } else if (isSorted) {
189
- if (this.processedData) {
190
- const dataIndex2 = this.processedData.findIndex(
191
- (row2) => row2[KEY] === keyValue
192
- );
193
- if (dataIndex2 !== -1) {
194
- const existingRow = this.processedData[dataIndex2];
195
- const newSortedRow = existingRow.slice(0, 10).concat(dataSourceRow.slice(10));
196
- this.processedData[dataIndex2] = newSortedRow;
197
- if (dataIndex2 >= from && dataIndex2 < to) {
198
- this.sendRowsToClient(false, newSortedRow);
199
- }
200
- }
201
- }
202
- } else {
203
- if (dataIndex >= from && dataIndex < to) {
204
- this.sendRowsToClient(false, dataSourceRow);
205
- }
206
- }
207
- }
208
- });
209
- __publicField(this, "handleDeleteFromTable", async (key) => {
210
- const dataIndex = __privateGet(this, _data).findIndex((row) => row[KEY] === key);
211
- if (dataIndex === -1) {
212
- return "row not found";
213
- }
214
- let doomedIndex = void 0;
215
- if (this.processedData) {
216
- for (let i = 0; i < this.processedData.length; i++) {
217
- if (this.processedData[i][KEY] === key) {
218
- doomedIndex = i;
219
- } else if (doomedIndex !== void 0) {
220
- this.processedData[i][0] -= 1;
221
- }
222
- }
223
- if (doomedIndex !== void 0) {
224
- this.processedData.splice(doomedIndex, 1);
225
- }
226
- }
227
- __privateGet(this, _data).splice(dataIndex, 1);
228
- for (let i = dataIndex; i < __privateGet(this, _data).length; i++) {
229
- __privateGet(this, _data)[i][0] -= 1;
230
- }
231
- this.sendSizeUpdateToClient();
232
- const { from, to } = __privateGet(this, _range);
233
- const deletedIndex = doomedIndex ?? dataIndex;
234
- if (deletedIndex >= from && deletedIndex < to) {
235
- __privateGet(this, _keys).reset(this.rangeWithBufferWithinMaxRangeEnd);
236
- this.sendRowsToClient(true);
237
- }
238
- this.emit("resize", this.size);
239
- return true;
240
- });
241
- if (!data || !columnDescriptors) {
242
- throw Error(
243
- "ArrayDataSource constructor called without data or without columnDescriptors"
244
- );
245
- }
246
- this.columnDescriptors = columnDescriptors;
247
- this.dataMap = dataMap;
248
- this.key = keyColumn ? this.columnDescriptors.findIndex((col) => col.name === keyColumn) : 0;
249
- this.rangeChangeRowset = rangeChangeRowset;
250
- this.tableSchema = buildTableSchema(columnDescriptors, keyColumn);
251
- this.viewport = viewport || vuuUtils.uuid();
252
- __privateSet(this, _title, title);
253
- const columns = columnDescriptors.map((col) => col.name);
254
- __privateSet(this, _columnMap, vuuUtils.buildColumnMap(columns));
255
- this.dataIndices = arrayDataUtils.buildDataToClientMap(__privateGet(this, _columnMap), this.dataMap);
256
- __privateSet(this, _data, data.map(
257
- toDataSourceRow(this.key, this.index)
258
- ));
259
- this.config = {
260
- ...this._config,
261
- aggregations: aggregations || this._config.aggregations,
262
- baseFilterSpec,
263
- columns,
264
- filterSpec: filterSpec || this._config.filterSpec,
265
- groupBy: groupBy || this._config.groupBy,
266
- sort: sort || this._config.sort
267
- };
268
- debug?.(`columnMap: ${JSON.stringify(__privateGet(this, _columnMap))}`);
269
- }
270
- async subscribe({
271
- viewport = this.viewport ?? (this.viewport = vuuUtils.uuid()),
272
- columns,
273
- aggregations,
274
- baseFilterSpec,
275
- range,
276
- sort,
277
- groupBy,
278
- filterSpec
279
- }, callback) {
280
- this.clientCallback = callback;
281
- this.viewport = viewport;
282
- __privateSet(this, _status, "subscribed");
283
- this.lastRangeServed = { from: 0, to: 0 };
284
- if (this.tableSchema.rangeLimits) {
285
- __privateSet(this, _maxRangeEnd, this.tableSchema.rangeLimits.maxRangeEnd);
286
- }
287
- let config = this._config;
288
- const hasConfigProps = aggregations || columns || filterSpec || groupBy || sort;
289
- if (hasConfigProps) {
290
- config = {
291
- ...config,
292
- aggregations: aggregations || this._config.aggregations,
293
- baseFilterSpec: baseFilterSpec || this._config.baseFilterSpec,
294
- columns: columns || this._config.columns,
295
- filterSpec: filterSpec || this._config.filterSpec,
296
- groupBy: groupBy || this._config.groupBy,
297
- sort: sort || this._config.sort
298
- };
299
- }
300
- const subscribedMessage = {
301
- ...config,
302
- type: "subscribed",
303
- clientViewportId: this.viewport,
304
- range: __privateGet(this, _range),
305
- tableSchema: this.tableSchema
306
- };
307
- this.clientCallback?.(subscribedMessage);
308
- this.emit("subscribed", subscribedMessage);
309
- if (hasConfigProps) {
310
- this.config = config;
311
- } else {
312
- this.sendSizeUpdateToClient();
313
- this.emit(
314
- "resize",
315
- this.processedData ? this.processedData.length : __privateGet(this, _data).length,
316
- __privateGet(this, _maxRangeEnd)
317
- );
318
- if (range && !__privateGet(this, _range).equals(range)) {
319
- this.range = range;
320
- } else if (__privateGet(this, _range) !== vuuUtils.NULL_RANGE) {
321
- this.sendRowsToClient();
322
- }
323
- if (this.range.to !== 0) {
324
- const pageCount = Math.ceil(
325
- this.size / (this.range.to - this.range.from)
326
- );
327
- this.emit("page-count", pageCount);
328
- }
329
- }
330
- }
331
- unsubscribe() {
332
- __privateSet(this, _status, "unsubscribed");
333
- this.emit("unsubscribed", this.viewport);
334
- this.removeAllListeners();
335
- this.clientCallback = void 0;
336
- }
337
- suspend() {
338
- console.log("[ArrayDataSource] suspend");
339
- if (__privateGet(this, _status) !== "unsubscribed") {
340
- info?.(`suspend #${this.viewport}, current status ${__privateGet(this, _status)}`);
341
- __privateSet(this, _status, "suspended");
342
- this.emit("suspended", this.viewport);
343
- }
344
- }
345
- resume(callback) {
346
- const isSuspended = __privateGet(this, _status) === "suspended";
347
- info?.(`resume #${this.viewport}, current status ${__privateGet(this, _status)}`);
348
- if (callback) {
349
- this.clientCallback = callback;
350
- }
351
- if (isSuspended) {
352
- __privateSet(this, _status, "subscribed");
353
- }
354
- this.emit("resumed", this.viewport);
355
- if (this.selectedRows.size > 0) {
356
- if (this.selectedRows.has("*")) {
357
- this.emit("row-selection", this.size);
358
- } else {
359
- this.emit("row-selection", this.selectedRows.size);
360
- }
361
- }
362
- this.sendRowsToClient(true);
363
- }
364
- disable() {
365
- this.emit("disabled", this.viewport);
366
- }
367
- enable() {
368
- this.emit("enabled", this.viewport);
369
- }
370
- select(selectRequest) {
371
- switch (selectRequest.type) {
372
- case "SELECT_ROW": {
373
- const { preserveExistingSelection, rowKey } = selectRequest;
374
- if (!preserveExistingSelection) {
375
- this.selectedRows.clear();
376
- }
377
- this.selectedRows.add(rowKey);
378
- break;
379
- }
380
- case "DESELECT_ROW": {
381
- const { preserveExistingSelection, rowKey } = selectRequest;
382
- if (!preserveExistingSelection) {
383
- this.selectedRows.clear();
384
- } else if (this.selectedRows.has("*")) {
385
- this.selectedRows.clear();
386
- for (const key of this.index.keys()) {
387
- if (key !== rowKey) {
388
- this.selectedRows.add(key);
389
- }
390
- }
391
- } else {
392
- this.selectedRows.delete(rowKey);
393
- }
394
- break;
395
- }
396
- case "SELECT_ROW_RANGE": {
397
- const { preserveExistingSelection, fromRowKey, toRowKey } = selectRequest;
398
- if (!preserveExistingSelection) {
399
- this.selectedRows.clear();
400
- }
401
- const fromIdx = this.index.get(fromRowKey);
402
- const toIdx = this.index.get(toRowKey);
403
- if (typeof fromIdx === "number" && typeof toIdx === "number") {
404
- for (let i = fromIdx; i <= toIdx; i++) {
405
- const { [KEY]: rowKey } = __privateGet(this, _data)[i];
406
- this.selectedRows.add(rowKey);
407
- }
408
- }
409
- break;
410
- }
411
- case "SELECT_ALL": {
412
- this.selectedRows.clear();
413
- this.selectedRows.add("*");
414
- break;
415
- }
416
- case "DESELECT_ALL": {
417
- this.selectedRows.clear();
418
- break;
419
- }
420
- }
421
- this.setRange(__privateGet(this, _range), true);
422
- this.emit(
423
- "row-selection",
424
- selectRequest.type === "SELECT_ALL" ? this.size : this.selectedRows.size
425
- );
426
- }
427
- getRowKey(keyOrIndex) {
428
- if (typeof keyOrIndex === "string") {
429
- return keyOrIndex;
430
- }
431
- const row = this.getRowAtIndex(keyOrIndex);
432
- if (row === void 0) {
433
- throw Error(`row not found at index ${keyOrIndex}`);
434
- }
435
- return row?.[KEY];
436
- }
437
- openTreeNode(keyOrIndex) {
438
- const key = this.getRowKey(keyOrIndex);
439
- this.openTreeNodes.push(key);
440
- this.processedData = groupUtils.expandGroup(
441
- this.openTreeNodes,
442
- __privateGet(this, _data),
443
- this._config.groupBy,
444
- __privateGet(this, _columnMap),
445
- this.groupMap,
446
- this.processedData
447
- );
448
- this.setRange(__privateGet(this, _range).reset, true);
449
- }
450
- closeTreeNode(keyOrIndex) {
451
- const key = this.getRowKey(keyOrIndex);
452
- this.openTreeNodes = this.openTreeNodes.filter((value) => value !== key);
453
- if (this.processedData) {
454
- this.processedData = groupUtils.collapseGroup(key, this.processedData);
455
- this.setRange(__privateGet(this, _range).reset, true);
456
- }
457
- }
458
- get pageSize() {
459
- return __privateGet(this, _range).to - __privateGet(this, _range).from;
460
- }
461
- get links() {
462
- return __privateGet(this, _links);
463
- }
464
- set links(links) {
465
- __privateSet(this, _links, links);
466
- if (links) {
467
- this._clientCallback?.({
468
- clientViewportId: this.viewport,
469
- type: "vuu-links",
470
- links
471
- });
472
- }
473
- }
474
- get menu() {
475
- return this._menu;
476
- }
477
- get status() {
478
- return __privateGet(this, _status);
479
- }
480
- get data() {
481
- return __privateGet(this, _data);
482
- }
483
- // Only used by the UpdateGenerator
484
- get currentData() {
485
- return this.processedData ?? __privateGet(this, _data);
486
- }
487
- get table() {
488
- return this.tableSchema.table;
489
- }
490
- get columns() {
491
- return this._config.columns;
492
- }
493
- set columns(columns) {
494
- }
495
- get config() {
496
- return this._config;
497
- }
498
- set config(config) {
499
- const originalConfig = this._config;
500
- const configChanges = this.applyConfig(config);
501
- if (configChanges) {
502
- if (config) {
503
- const newConfig = config?.filterSpec?.filter && config?.filterSpec.filterStruct === void 0 ? {
504
- ...config,
505
- filterSpec: {
506
- filter: config.filterSpec.filter,
507
- filterStruct: vuuFilterParser.parseFilter(config.filterSpec.filter)
508
- }
509
- } : config;
510
- this._config = vuuUtils.withConfigDefaults(newConfig);
511
- let processedData;
512
- if (vuuUtils.hasFilter(config) || vuuUtils.hasBaseFilter(config)) {
513
- const fn = this.getFilterPredicate();
514
- processedData = __privateGet(this, _data).filter(fn);
515
- }
516
- if (configChanges.columnsChanged) {
517
- this.processNewColumns(originalConfig.columns, config.columns);
518
- }
519
- if (vuuUtils.hasSort(config)) {
520
- processedData = sortUtils.sortRows(
521
- processedData ?? __privateGet(this, _data),
522
- config.sort,
523
- __privateGet(this, _columnMap)
524
- );
525
- }
526
- if (this.openTreeNodes.length > 0 && vuuUtils.isGroupByChanged(originalConfig, config)) {
527
- if (this._config.groupBy.length === 0) {
528
- this.openTreeNodes.length = 0;
529
- }
530
- }
531
- if (vuuUtils.hasGroupBy(config)) {
532
- const [groupedData, groupMap] = groupUtils.groupRows(
533
- processedData ?? __privateGet(this, _data),
534
- config.groupBy,
535
- __privateGet(this, _columnMap)
536
- );
537
- this.groupMap = groupMap;
538
- processedData = groupedData;
539
- if (this.openTreeNodes.length > 0) {
540
- processedData = groupUtils.expandGroup(
541
- this.openTreeNodes,
542
- __privateGet(this, _data),
543
- this._config.groupBy,
544
- __privateGet(this, _columnMap),
545
- this.groupMap,
546
- processedData
547
- );
548
- }
549
- }
550
- if (processedData) {
551
- this.processedData = this.indexProcessedData(processedData);
552
- } else {
553
- this.processedData = void 0;
554
- }
555
- }
556
- if (configChanges.filterChanged || configChanges.baseFilterChanged || configChanges.groupByChanged) {
557
- requestAnimationFrame(() => {
558
- this.emit("resize", this.size);
559
- });
560
- }
561
- if (__privateGet(this, _status) === "subscribed") {
562
- requestAnimationFrame(() => {
563
- this.sendSizeUpdateToClient();
564
- if (this.preserveScrollPositionAcrossConfigChange) {
565
- this.preserveScrollPositionAcrossConfigChange = false;
566
- } else {
567
- this.setRange(__privateGet(this, _range).reset, true);
568
- }
569
- this.emit(
570
- "config",
571
- this._config,
572
- this.range,
573
- void 0,
574
- configChanges
575
- );
576
- });
577
- }
578
- }
579
- }
580
- processNewColumns(originalColumns, columns) {
581
- const addedColumns = vuuUtils.getAddedItems(originalColumns, columns);
582
- if (addedColumns.length > 0) ;
583
- __privateSet(this, _columnMap, vuuUtils.buildColumnMap(columns));
584
- this.dataIndices = arrayDataUtils.buildDataToClientMap(__privateGet(this, _columnMap), this.dataMap);
585
- }
586
- indexProcessedData(data) {
587
- return data?.map((row, i) => {
588
- const dolly = row.slice();
589
- dolly[0] = i;
590
- dolly[1] = i;
591
- return dolly;
592
- });
593
- }
594
- getFilterPredicate() {
595
- const {
596
- filterSpec: { filterStruct }
597
- } = vuuUtils.combineFilters(this._config);
598
- if (filterStruct) {
599
- return vuuFilterParser.filterPredicate(__privateGet(this, _columnMap), filterStruct);
600
- } else {
601
- throw Error("filter must include filterStruct");
602
- }
603
- }
604
- applyConfig(config, preserveExistingConfigAttributes = false) {
605
- const { noChanges, ...otherChanges } = vuuUtils.isConfigChanged(
606
- this._config,
607
- config
608
- );
609
- if (noChanges !== true) {
610
- if (config) {
611
- const newConfig = config?.filterSpec?.filter && config?.filterSpec.filterStruct === void 0 ? {
612
- ...config,
613
- filterSpec: {
614
- filter: config.filterSpec.filter,
615
- filterStruct: vuuFilterParser.parseFilter(config.filterSpec.filter)
616
- }
617
- } : config;
618
- if (preserveExistingConfigAttributes) {
619
- this._config = {
620
- ...this._config,
621
- ...config
622
- };
623
- } else {
624
- this._config = vuuUtils.withConfigDefaults(newConfig);
625
- }
626
- return otherChanges;
627
- }
628
- }
629
- }
630
- get columnMap() {
631
- return __privateGet(this, _columnMap);
632
- }
633
- get selectedRowsCount() {
634
- return this.selectedRows.size;
635
- }
636
- get size() {
637
- return this.processedData?.length ?? __privateGet(this, _data).length;
638
- }
639
- get maxRangeEnd() {
640
- return __privateGet(this, _maxRangeEnd);
641
- }
642
- get range() {
643
- return __privateGet(this, _range);
644
- }
645
- set range(range) {
646
- this.setRange(range);
647
- }
648
- delete(row) {
649
- console.log(`delete row ${row.join(",")}`);
650
- }
651
- insertIntoSortedData(row) {
652
- const indexedSortDefs = this.config.sort.sortDefs.map(
653
- ({ column, sortType }) => [this.columnMap[column], sortType]
654
- );
655
- if (this.processedData) {
656
- const comparator = sortUtils.sortComparator(indexedSortDefs);
657
- const insertPos = sortUtils.binarySearch(this.processedData, row, comparator);
658
- this.sendSizeUpdateToClient();
659
- if (insertPos === -1) {
660
- this.processedData?.unshift(row);
661
- if (this.processedData) {
662
- this.processedData = this.indexProcessedData(this.processedData);
663
- }
664
- if (insertPos <= __privateGet(this, _range).to) {
665
- this.sendRowsToClient(true);
666
- }
667
- if (this.processedData) {
668
- this.emit("resize", this.processedData.length);
669
- }
670
- } else {
671
- if (this.processedData) {
672
- this.emit("resize", this.processedData.length);
673
- }
674
- }
675
- }
676
- }
677
- validateDataValue(columnName, value) {
678
- const columnDescriptor = this.columnDescriptors.find(
679
- (col) => col.name === columnName
680
- );
681
- if (columnDescriptor) {
682
- switch (columnDescriptor.serverDataType) {
683
- case "int":
684
- {
685
- if (typeof value === "number") {
686
- if (Math.floor(value) !== value) {
687
- throw Error(`${columnName} is int but value = ${value}`);
688
- }
689
- } else if (typeof value === "string") {
690
- const numericValue = parseFloat(value);
691
- if (Math.floor(numericValue) !== numericValue) {
692
- throw Error(`${columnName} is ${value} is not a valid integer`);
693
- }
694
- }
695
- }
696
- break;
697
- }
698
- } else {
699
- throw Error(`Unknown column ${columnName}`);
700
- }
701
- }
702
- getRowByKey(key) {
703
- const data = this.processedData ?? __privateGet(this, _data);
704
- return data.find((row) => row[KEY] === key);
705
- }
706
- getRowAtIndex(rowIndex) {
707
- return (this.processedData ?? __privateGet(this, _data))[rowIndex];
708
- }
709
- setRange(range, forceFullRefresh = false) {
710
- this.constrainRangeToMaxRangeEnd(range);
711
- if (range.from !== __privateGet(this, _range).from || range.to !== __privateGet(this, _range).to) {
712
- const currentPageCount = Math.ceil(
713
- this.size / (__privateGet(this, _range).to - __privateGet(this, _range).from)
714
- );
715
- const newPageCount = Math.ceil(this.size / (range.to - range.from));
716
- __privateSet(this, _range, range);
717
- const keysResequenced = __privateGet(this, _keys).reset(
718
- this.rangeWithBufferWithinMaxRangeEnd
719
- );
720
- this.sendRowsToClient(forceFullRefresh || keysResequenced);
721
- requestAnimationFrame(() => {
722
- if (newPageCount !== currentPageCount) {
723
- this.emit("page-count", newPageCount);
724
- }
725
- this.emit("range", range);
726
- });
727
- } else if (forceFullRefresh) {
728
- this.sendRowsToClient(forceFullRefresh);
729
- }
730
- }
731
- constrainRangeToMaxRangeEnd(range) {
732
- if (__privateGet(this, _maxRangeEnd) === Number.MAX_SAFE_INTEGER) {
733
- return;
734
- }
735
- const pageSize = Math.max(0, range.to - range.from);
736
- if (range.from >= __privateGet(this, _maxRangeEnd)) {
737
- range.from = Math.max(0, __privateGet(this, _maxRangeEnd) - pageSize);
738
- range.to = __privateGet(this, _maxRangeEnd);
739
- } else if (range.to > __privateGet(this, _maxRangeEnd)) {
740
- range.to = __privateGet(this, _maxRangeEnd);
741
- }
742
- }
743
- get rangeWithBufferWithinMaxRangeEnd() {
744
- const withBuffer = __privateGet(this, _range).withBuffer;
745
- return __privateGet(this, _maxRangeEnd) === Number.MAX_SAFE_INTEGER ? withBuffer : {
746
- from: withBuffer.from,
747
- to: Math.min(withBuffer.to, __privateGet(this, _maxRangeEnd))
748
- };
749
- }
750
- sendSizeUpdateToClient() {
751
- this.clientCallback?.({
752
- clientViewportId: this.viewport,
753
- mode: "size-only",
754
- type: "viewport-update",
755
- size: this.processedData ? this.processedData.length : __privateGet(this, _data).length
756
- });
757
- }
758
- sendRowsToClient(forceFullRefresh = false, row) {
759
- if (row) {
760
- this.clientCallback?.({
761
- clientViewportId: this.viewport,
762
- mode: "update",
763
- rows: [
764
- arrayDataUtils.toClientRow(row, __privateGet(this, _keys), this.selectedRows, this.dataIndices)
765
- ],
766
- type: "viewport-update"
767
- });
768
- } else {
769
- const rowRange = this.rangeChangeRowset === "delta" && !forceFullRefresh ? vuuUtils.rangeNewItems(
770
- this.lastRangeServed,
771
- this.rangeWithBufferWithinMaxRangeEnd
772
- ) : this.rangeWithBufferWithinMaxRangeEnd;
773
- const data = this.processedData ?? __privateGet(this, _data);
774
- const rowsWithinViewport = data.slice(rowRange.from, rowRange.to).map(
775
- (row2) => arrayDataUtils.toClientRow(row2, __privateGet(this, _keys), this.selectedRows, this.dataIndices)
776
- );
777
- this.clientCallback?.({
778
- clientViewportId: this.viewport,
779
- mode: "batch",
780
- range: __privateGet(this, _range),
781
- rows: rowsWithinViewport,
782
- size: data.length,
783
- type: "viewport-update"
784
- });
785
- this.lastRangeServed = {
786
- from: __privateGet(this, _range).from,
787
- // to: this.#range.to,
788
- to: Math.min(
789
- __privateGet(this, _range).to,
790
- __privateGet(this, _range).from + rowsWithinViewport.length
791
- )
792
- };
793
- }
794
- }
795
- get aggregations() {
796
- return this._config.aggregations;
797
- }
798
- set aggregations(aggregations) {
799
- this._config = {
800
- ...this._config,
801
- aggregations
802
- };
803
- const targetData = this.processedData ?? __privateGet(this, _data);
804
- const leafData = __privateGet(this, _data);
805
- aggregateUtils.aggregateData(
806
- aggregations,
807
- targetData,
808
- this._config.groupBy,
809
- leafData,
810
- __privateGet(this, _columnMap),
811
- this.groupMap
812
- );
813
- this.setRange(__privateGet(this, _range).reset, true);
814
- this.emit("config", this._config, this.range);
815
- }
816
- get sort() {
817
- return this._config.sort;
818
- }
819
- set sort(sort) {
820
- debug?.(`sort ${JSON.stringify(sort)}`);
821
- this.config = {
822
- ...this._config,
823
- sort
824
- };
825
- }
826
- get baseFilter() {
827
- return this._config.baseFilterSpec;
828
- }
829
- set baseFilter(baseFilter) {
830
- debug?.(`baseFilter ${JSON.stringify(baseFilter)}`);
831
- this.config = {
832
- ...this._config,
833
- baseFilterSpec: baseFilter
834
- };
835
- }
836
- get filter() {
837
- return this._config.filterSpec;
838
- }
839
- set filter(filter) {
840
- debug?.(`filter ${JSON.stringify(filter)}`);
841
- this.config = {
842
- ...this._config,
843
- filterSpec: filter
844
- };
845
- }
846
- setFilter(filter) {
847
- const dataSourceFilter = {
848
- filter: vuuUtils.filterAsQuery(filter),
849
- filterStruct: filter
850
- };
851
- this.filter = dataSourceFilter;
852
- }
853
- clearFilter() {
854
- this.filter = { filter: "" };
855
- }
856
- get groupBy() {
857
- return this._config.groupBy;
858
- }
859
- set groupBy(groupBy) {
860
- this.config = {
861
- ...this._config,
862
- groupBy
863
- };
864
- }
865
- get title() {
866
- return __privateGet(this, _title) ?? `${this.table.module} ${this.table.table}`;
867
- }
868
- set title(title) {
869
- __privateSet(this, _title, title);
870
- this.emit("title-changed", this.viewport, title);
871
- }
872
- get _clientCallback() {
873
- return this.clientCallback;
874
- }
875
- createLink({
876
- parentVpId,
877
- link: { fromColumn, toColumn }
878
- }) {
879
- console.log("create link", {
880
- parentVpId,
881
- fromColumn,
882
- toColumn
883
- });
884
- }
885
- removeLink() {
886
- console.log("remove link");
887
- }
888
- async remoteProcedureCall() {
889
- return Promise.reject();
890
- }
891
- async menuRpcCall(rpcRequest) {
892
- console.log({ rpcRequest });
893
- return new Promise(() => {
894
- });
895
- }
896
- // All in BaseDataSource
897
- freeze() {
898
- if (!this.isFrozen) {
899
- __privateSet(this, _freezeTimestamp, Date.now());
900
- this.emit("freeze", true, __privateGet(this, _freezeTimestamp));
901
- this.preserveScrollPositionAcrossConfigChange = true;
902
- this.baseFilter = {
903
- filter: `vuuCreatedTimestamp < ${__privateGet(this, _freezeTimestamp)}`
904
- };
905
- } else {
906
- throw Error(
907
- "[BaseDataSource] cannot freeze, dataSource is already frozen"
908
- );
909
- }
910
- }
911
- unfreeze() {
912
- if (this.isFrozen) {
913
- const freezeTimestamp = __privateGet(this, _freezeTimestamp);
914
- __privateSet(this, _freezeTimestamp, void 0);
915
- this.emit("freeze", false, freezeTimestamp);
916
- this.preserveScrollPositionAcrossConfigChange = true;
917
- this.baseFilter = {
918
- filter: ""
919
- };
920
- } else {
921
- throw Error(
922
- "[BaseDataSource] cannot freeze, dataSource is already frozen"
923
- );
924
- }
925
- }
926
- get freezeTimestamp() {
927
- return __privateGet(this, _freezeTimestamp);
928
- }
929
- get isFrozen() {
930
- return typeof __privateGet(this, _freezeTimestamp) === "number";
931
- }
932
- }
933
- _columnMap = new WeakMap();
934
- _data = new WeakMap();
935
- _freezeTimestamp = new WeakMap();
936
- _keys = new WeakMap();
937
- _links = new WeakMap();
938
- _maxRangeEnd = new WeakMap();
939
- _range = new WeakMap();
940
- _status = new WeakMap();
941
- _title = new WeakMap();
942
-
943
- exports.ArrayDataSource = ArrayDataSource;
944
- //# sourceMappingURL=array-data-source.js.map