@vuu-ui/vuu-data-local 2.1.17 → 2.1.19-beta.1

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