@vuu-ui/vuu-data-local 0.13.9 → 0.13.10

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/cjs/array-data-source/aggregate-utils.js +237 -0
  2. package/cjs/array-data-source/aggregate-utils.js.map +1 -0
  3. package/cjs/array-data-source/array-data-source.js +669 -0
  4. package/cjs/array-data-source/array-data-source.js.map +1 -0
  5. package/cjs/array-data-source/array-data-utils.js +52 -0
  6. package/cjs/array-data-source/array-data-utils.js.map +1 -0
  7. package/cjs/array-data-source/group-utils.js +181 -0
  8. package/cjs/array-data-source/group-utils.js.map +1 -0
  9. package/cjs/array-data-source/sort-utils.js +54 -0
  10. package/cjs/array-data-source/sort-utils.js.map +1 -0
  11. package/cjs/index.js +6 -1992
  12. package/cjs/index.js.map +1 -1
  13. package/cjs/json-data-source/JsonDataSource.js +398 -0
  14. package/cjs/json-data-source/JsonDataSource.js.map +1 -0
  15. package/cjs/tree-data-source/IconProvider.js +31 -0
  16. package/cjs/tree-data-source/IconProvider.js.map +1 -0
  17. package/cjs/tree-data-source/TreeDataSource.js +421 -0
  18. package/cjs/tree-data-source/TreeDataSource.js.map +1 -0
  19. package/esm/array-data-source/aggregate-utils.js +235 -0
  20. package/esm/array-data-source/aggregate-utils.js.map +1 -0
  21. package/esm/array-data-source/array-data-source.js +667 -0
  22. package/esm/array-data-source/array-data-source.js.map +1 -0
  23. package/esm/array-data-source/array-data-utils.js +49 -0
  24. package/esm/array-data-source/array-data-utils.js.map +1 -0
  25. package/esm/array-data-source/group-utils.js +177 -0
  26. package/esm/array-data-source/group-utils.js.map +1 -0
  27. package/esm/array-data-source/sort-utils.js +52 -0
  28. package/esm/array-data-source/sort-utils.js.map +1 -0
  29. package/esm/index.js +3 -1993
  30. package/esm/index.js.map +1 -1
  31. package/esm/json-data-source/JsonDataSource.js +396 -0
  32. package/esm/json-data-source/JsonDataSource.js.map +1 -0
  33. package/esm/tree-data-source/IconProvider.js +29 -0
  34. package/esm/tree-data-source/IconProvider.js.map +1 -0
  35. package/esm/tree-data-source/TreeDataSource.js +419 -0
  36. package/esm/tree-data-source/TreeDataSource.js.map +1 -0
  37. package/package.json +7 -7
@@ -0,0 +1,669 @@
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, _keys, _links, _range, _selectedRowsCount, _status, _title;
21
+ const { debug, info } = vuuUtils.logger("ArrayDataSource");
22
+ const { KEY } = vuuUtils.metadataKeys;
23
+ const toDataSourceRow = (key) => (data, index) => {
24
+ return [index, index, true, false, 1, 0, String(data[key]), 0, ...data];
25
+ };
26
+ const buildTableSchema = (columns, keyColumn) => {
27
+ const schema = {
28
+ columns: columns.map(({ name, serverDataType = "string" }) => ({
29
+ name,
30
+ serverDataType
31
+ })),
32
+ key: keyColumn ?? columns[0].name,
33
+ table: { module: "", table: "Array" }
34
+ };
35
+ return schema;
36
+ };
37
+ class ArrayDataSource extends vuuUtils.EventEmitter {
38
+ constructor({
39
+ aggregations,
40
+ baseFilterSpec,
41
+ // different from RemoteDataSource
42
+ columnDescriptors,
43
+ data,
44
+ dataMap,
45
+ filterSpec,
46
+ groupBy,
47
+ keyColumn,
48
+ rangeChangeRowset = "delta",
49
+ sort,
50
+ title,
51
+ viewport
52
+ }) {
53
+ super();
54
+ __publicField(this, "clientCallback");
55
+ __publicField(this, "columnDescriptors");
56
+ /** sorted offsets of data within raw data, reflecting sort order
57
+ * of columns specified by client.
58
+ */
59
+ __publicField(this, "dataIndices");
60
+ /** Map reflecting positions of data items in raw data */
61
+ __publicField(this, "dataMap");
62
+ __publicField(this, "groupMap");
63
+ /** the index of key field within raw data row */
64
+ __publicField(this, "key");
65
+ __publicField(this, "lastRangeServed", { from: 0, to: 0 });
66
+ __publicField(this, "rangeChangeRowset");
67
+ __publicField(this, "openTreeNodes", []);
68
+ /** Map reflecting positions of columns in client data sent to user */
69
+ __privateAdd(this, _columnMap);
70
+ __publicField(this, "_config", vuuUtils.vanillaConfig);
71
+ __privateAdd(this, _data);
72
+ __privateAdd(this, _keys, new vuuUtils.KeySet(vuuUtils.NULL_RANGE));
73
+ __privateAdd(this, _links);
74
+ __privateAdd(this, _range, vuuUtils.Range(0, 0));
75
+ __privateAdd(this, _selectedRowsCount, 0);
76
+ __privateAdd(this, _status, "initialising");
77
+ __privateAdd(this, _title);
78
+ __publicField(this, "_menu");
79
+ __publicField(this, "selectedRows", []);
80
+ __publicField(this, "tableSchema");
81
+ __publicField(this, "viewport");
82
+ __publicField(this, "processedData");
83
+ __publicField(this, "insert", (row) => {
84
+ const dataSourceRow = toDataSourceRow(this.key)(row, this.size);
85
+ __privateGet(this, _data).push(dataSourceRow);
86
+ const { from, to } = __privateGet(this, _range);
87
+ const [rowIdx] = dataSourceRow;
88
+ if (rowIdx >= from && rowIdx < to) {
89
+ this.sendRowsToClient();
90
+ }
91
+ });
92
+ __publicField(this, "updateDataItem", (keyValue, columnName, value) => {
93
+ this.validateDataValue(columnName, value);
94
+ const colIndex = __privateGet(this, _columnMap)[columnName];
95
+ const dataColIndex = this.dataMap?.[columnName];
96
+ const dataIndex = this.indexOfRowWithKey(keyValue);
97
+ if (dataIndex !== -1 && dataColIndex !== void 0) {
98
+ const dataSourceRow = __privateGet(this, _data)[dataIndex];
99
+ dataSourceRow[colIndex] = value;
100
+ const { from, to } = __privateGet(this, _range);
101
+ const [rowIdx] = dataSourceRow;
102
+ if (rowIdx >= from && rowIdx < to) {
103
+ this.sendRowsToClient(false, dataSourceRow);
104
+ }
105
+ }
106
+ });
107
+ __publicField(this, "indexOfRowWithKey", (key) => __privateGet(this, _data).findIndex((row) => row[KEY] === key));
108
+ __publicField(this, "update", (row, columnName) => {
109
+ const keyValue = row[this.key];
110
+ const dataColIndex = this.dataMap?.[columnName];
111
+ return this.updateDataItem(keyValue, columnName, row[dataColIndex]);
112
+ });
113
+ __publicField(this, "updateRow", (row) => {
114
+ const keyValue = row[this.key];
115
+ const dataIndex = __privateGet(this, _data).findIndex((row2) => row2[KEY] === keyValue);
116
+ if (dataIndex !== -1) {
117
+ const dataSourceRow = toDataSourceRow(this.key)(row, dataIndex);
118
+ __privateGet(this, _data)[dataIndex] = dataSourceRow;
119
+ const { from, to } = __privateGet(this, _range);
120
+ if (dataIndex >= from && dataIndex < to) {
121
+ this.sendRowsToClient(false, dataSourceRow);
122
+ }
123
+ }
124
+ });
125
+ if (!data || !columnDescriptors) {
126
+ throw Error(
127
+ "ArrayDataSource constructor called without data or without columnDescriptors"
128
+ );
129
+ }
130
+ this.columnDescriptors = columnDescriptors;
131
+ this.dataMap = dataMap;
132
+ this.key = keyColumn ? this.columnDescriptors.findIndex((col) => col.name === keyColumn) : 0;
133
+ this.rangeChangeRowset = rangeChangeRowset;
134
+ this.tableSchema = buildTableSchema(columnDescriptors, keyColumn);
135
+ this.viewport = viewport || vuuUtils.uuid();
136
+ __privateSet(this, _title, title);
137
+ const columns = columnDescriptors.map((col) => col.name);
138
+ __privateSet(this, _columnMap, vuuUtils.buildColumnMap(columns));
139
+ this.dataIndices = arrayDataUtils.buildDataToClientMap(__privateGet(this, _columnMap), this.dataMap);
140
+ __privateSet(this, _data, data.map(toDataSourceRow(this.key)));
141
+ this.config = {
142
+ ...this._config,
143
+ aggregations: aggregations || this._config.aggregations,
144
+ baseFilterSpec,
145
+ columns,
146
+ filterSpec: filterSpec || this._config.filterSpec,
147
+ groupBy: groupBy || this._config.groupBy,
148
+ sort: sort || this._config.sort
149
+ };
150
+ debug?.(`columnMap: ${JSON.stringify(__privateGet(this, _columnMap))}`);
151
+ }
152
+ async subscribe({
153
+ viewport = this.viewport ?? (this.viewport = vuuUtils.uuid()),
154
+ columns,
155
+ aggregations,
156
+ baseFilterSpec,
157
+ range,
158
+ selectedIndexValues,
159
+ selectedKeyValues,
160
+ sort,
161
+ groupBy,
162
+ filterSpec
163
+ }, callback) {
164
+ console.log(`%cArrayDataSource subscribe`, "color: red;font-weight:bold;");
165
+ this.clientCallback = callback;
166
+ this.viewport = viewport;
167
+ __privateSet(this, _status, "subscribed");
168
+ this.selectedRows = selectedIndexValues ?? this.convertKeysToIndexValues(selectedKeyValues) ?? [];
169
+ __privateSet(this, _selectedRowsCount, vuuUtils.selectionCount(this.selectedRows));
170
+ this.lastRangeServed = { from: 0, to: 0 };
171
+ let config = this._config;
172
+ const hasConfigProps = aggregations || columns || filterSpec || groupBy || sort;
173
+ if (hasConfigProps) {
174
+ if (range) {
175
+ this.setRange(range);
176
+ }
177
+ config = {
178
+ ...config,
179
+ aggregations: aggregations || this._config.aggregations,
180
+ baseFilterSpec: baseFilterSpec || this._config.baseFilterSpec,
181
+ columns: columns || this._config.columns,
182
+ filterSpec: filterSpec || this._config.filterSpec,
183
+ groupBy: groupBy || this._config.groupBy,
184
+ sort: sort || this._config.sort
185
+ };
186
+ }
187
+ const subscribedMessage = {
188
+ ...config,
189
+ type: "subscribed",
190
+ clientViewportId: this.viewport,
191
+ range: __privateGet(this, _range),
192
+ tableSchema: this.tableSchema
193
+ };
194
+ this.clientCallback?.(subscribedMessage);
195
+ this.emit("subscribed", subscribedMessage);
196
+ if (hasConfigProps) {
197
+ this.config = config;
198
+ } else {
199
+ this.clientCallback({
200
+ clientViewportId: this.viewport,
201
+ mode: "size-only",
202
+ type: "viewport-update",
203
+ size: __privateGet(this, _data).length
204
+ });
205
+ if (range && !__privateGet(this, _range).equals(range)) {
206
+ this.range = range;
207
+ } else if (__privateGet(this, _range) !== vuuUtils.NULL_RANGE) {
208
+ this.sendRowsToClient();
209
+ }
210
+ if (this.range.to !== 0) {
211
+ const pageCount = Math.ceil(
212
+ this.size / (this.range.to - this.range.from)
213
+ );
214
+ this.emit("page-count", pageCount);
215
+ }
216
+ }
217
+ }
218
+ unsubscribe() {
219
+ __privateSet(this, _status, "unsubscribed");
220
+ this.emit("unsubscribed", this.viewport);
221
+ }
222
+ suspend() {
223
+ if (__privateGet(this, _status) !== "unsubscribed") {
224
+ info?.(`suspend #${this.viewport}, current status ${__privateGet(this, _status)}`);
225
+ __privateSet(this, _status, "suspended");
226
+ this.emit("suspended", this.viewport);
227
+ }
228
+ }
229
+ resume(callback) {
230
+ const isSuspended = __privateGet(this, _status) === "suspended";
231
+ info?.(`resume #${this.viewport}, current status ${__privateGet(this, _status)}`);
232
+ if (callback) {
233
+ this.clientCallback = callback;
234
+ }
235
+ if (isSuspended) {
236
+ __privateSet(this, _status, "subscribed");
237
+ }
238
+ this.emit("resumed", this.viewport);
239
+ this.sendRowsToClient(true);
240
+ }
241
+ disable() {
242
+ this.emit("disabled", this.viewport);
243
+ }
244
+ enable() {
245
+ this.emit("enabled", this.viewport);
246
+ }
247
+ select(selected) {
248
+ __privateSet(this, _selectedRowsCount, vuuUtils.selectionCount(selected));
249
+ debug?.(`select ${JSON.stringify(selected)}`);
250
+ this.selectedRows = selected;
251
+ this.setRange(__privateGet(this, _range), true);
252
+ this.emit("row-selection", selected, __privateGet(this, _selectedRowsCount));
253
+ }
254
+ getRowKey(keyOrIndex) {
255
+ if (typeof keyOrIndex === "string") {
256
+ return keyOrIndex;
257
+ }
258
+ const row = this.getRowAtIndex(keyOrIndex);
259
+ if (row === void 0) {
260
+ throw Error(`row not found at index ${keyOrIndex}`);
261
+ }
262
+ return row?.[KEY];
263
+ }
264
+ openTreeNode(keyOrIndex) {
265
+ const key = this.getRowKey(keyOrIndex);
266
+ this.openTreeNodes.push(key);
267
+ this.processedData = groupUtils.expandGroup(
268
+ this.openTreeNodes,
269
+ __privateGet(this, _data),
270
+ this._config.groupBy,
271
+ __privateGet(this, _columnMap),
272
+ this.groupMap,
273
+ this.processedData
274
+ );
275
+ this.setRange(__privateGet(this, _range).reset, true);
276
+ }
277
+ closeTreeNode(keyOrIndex) {
278
+ const key = this.getRowKey(keyOrIndex);
279
+ this.openTreeNodes = this.openTreeNodes.filter((value) => value !== key);
280
+ if (this.processedData) {
281
+ this.processedData = groupUtils.collapseGroup(key, this.processedData);
282
+ this.setRange(__privateGet(this, _range).reset, true);
283
+ }
284
+ }
285
+ get pageSize() {
286
+ return __privateGet(this, _range).to - __privateGet(this, _range).from;
287
+ }
288
+ get links() {
289
+ return __privateGet(this, _links);
290
+ }
291
+ set links(links) {
292
+ __privateSet(this, _links, links);
293
+ }
294
+ get menu() {
295
+ return this._menu;
296
+ }
297
+ get status() {
298
+ return __privateGet(this, _status);
299
+ }
300
+ get data() {
301
+ return __privateGet(this, _data);
302
+ }
303
+ // Only used by the UpdateGenerator
304
+ get currentData() {
305
+ return this.processedData ?? __privateGet(this, _data);
306
+ }
307
+ get table() {
308
+ return this.tableSchema.table;
309
+ }
310
+ get config() {
311
+ return this._config;
312
+ }
313
+ set config(config) {
314
+ const configChanges = this.applyConfig(config);
315
+ if (configChanges) {
316
+ if (config) {
317
+ const originalConfig = this._config;
318
+ const newConfig = config?.filterSpec?.filter && config?.filterSpec.filterStruct === void 0 ? {
319
+ ...config,
320
+ filterSpec: {
321
+ filter: config.filterSpec.filter,
322
+ filterStruct: vuuFilterParser.parseFilter(config.filterSpec.filter)
323
+ }
324
+ } : config;
325
+ this._config = vuuUtils.withConfigDefaults(newConfig);
326
+ let processedData;
327
+ if (vuuUtils.hasFilter(config) || vuuUtils.hasBaseFilter(config)) {
328
+ const {
329
+ filterSpec: { filterStruct }
330
+ } = vuuUtils.combineFilters(this._config);
331
+ if (filterStruct) {
332
+ const fn = vuuFilterParser.filterPredicate(__privateGet(this, _columnMap), filterStruct);
333
+ processedData = __privateGet(this, _data).filter(fn);
334
+ } else {
335
+ throw Error("filter must include filterStruct");
336
+ }
337
+ }
338
+ if (vuuUtils.hasSort(config)) {
339
+ processedData = sortUtils.sortRows(
340
+ processedData ?? __privateGet(this, _data),
341
+ config.sort,
342
+ __privateGet(this, _columnMap)
343
+ );
344
+ }
345
+ if (this.openTreeNodes.length > 0 && vuuUtils.isGroupByChanged(originalConfig, config)) {
346
+ if (this._config.groupBy.length === 0) {
347
+ this.openTreeNodes.length = 0;
348
+ }
349
+ }
350
+ if (vuuUtils.hasGroupBy(config)) {
351
+ const [groupedData, groupMap] = groupUtils.groupRows(
352
+ processedData ?? __privateGet(this, _data),
353
+ config.groupBy,
354
+ __privateGet(this, _columnMap)
355
+ );
356
+ this.groupMap = groupMap;
357
+ processedData = groupedData;
358
+ if (this.openTreeNodes.length > 0) {
359
+ processedData = groupUtils.expandGroup(
360
+ this.openTreeNodes,
361
+ __privateGet(this, _data),
362
+ this._config.groupBy,
363
+ __privateGet(this, _columnMap),
364
+ this.groupMap,
365
+ processedData
366
+ );
367
+ }
368
+ }
369
+ this.processedData = processedData?.map((row, i) => {
370
+ const dolly = row.slice();
371
+ dolly[0] = i;
372
+ dolly[1] = i;
373
+ return dolly;
374
+ });
375
+ }
376
+ if (__privateGet(this, _status) === "subscribed") {
377
+ this.setRange(__privateGet(this, _range).reset, true);
378
+ this.emit("config", this._config, this.range, void 0, configChanges);
379
+ }
380
+ }
381
+ }
382
+ applyConfig(config, preserveExistingConfigAttributes = false) {
383
+ const { noChanges, ...otherChanges } = vuuUtils.isConfigChanged(
384
+ this._config,
385
+ config
386
+ );
387
+ if (noChanges !== true) {
388
+ if (config) {
389
+ const newConfig = config?.filterSpec?.filter && config?.filterSpec.filterStruct === void 0 ? {
390
+ ...config,
391
+ filterSpec: {
392
+ filter: config.filterSpec.filter,
393
+ filterStruct: vuuFilterParser.parseFilter(config.filterSpec.filter)
394
+ }
395
+ } : config;
396
+ if (preserveExistingConfigAttributes) {
397
+ this._config = {
398
+ ...this._config,
399
+ ...config
400
+ };
401
+ } else {
402
+ this._config = vuuUtils.withConfigDefaults(newConfig);
403
+ }
404
+ return otherChanges;
405
+ }
406
+ }
407
+ }
408
+ get columnMap() {
409
+ return __privateGet(this, _columnMap);
410
+ }
411
+ get selectedRowsCount() {
412
+ return __privateGet(this, _selectedRowsCount);
413
+ }
414
+ get size() {
415
+ return this.processedData?.length ?? __privateGet(this, _data).length;
416
+ }
417
+ get range() {
418
+ return __privateGet(this, _range);
419
+ }
420
+ set range(range) {
421
+ this.setRange(range);
422
+ }
423
+ getRowAtIndex(rowIndex) {
424
+ return this.processedData?.[rowIndex];
425
+ }
426
+ delete(row) {
427
+ console.log(`delete row ${row.join(",")}`);
428
+ }
429
+ validateDataValue(columnName, value) {
430
+ const columnDescriptor = this.columnDescriptors.find(
431
+ (col) => col.name === columnName
432
+ );
433
+ if (columnDescriptor) {
434
+ switch (columnDescriptor.serverDataType) {
435
+ case "int":
436
+ {
437
+ if (typeof value === "number") {
438
+ if (Math.floor(value) !== value) {
439
+ throw Error(`${columnName} is int but value = ${value}`);
440
+ }
441
+ } else if (typeof value === "string") {
442
+ const numericValue = parseFloat(value);
443
+ if (Math.floor(numericValue) !== numericValue) {
444
+ throw Error(`${columnName} is ${value} is not a valid integer`);
445
+ }
446
+ }
447
+ }
448
+ break;
449
+ }
450
+ } else {
451
+ throw Error(`Unknown column ${columnName}`);
452
+ }
453
+ }
454
+ setRange(range, forceFullRefresh = false) {
455
+ if (range.from !== __privateGet(this, _range).from || range.to !== __privateGet(this, _range).to) {
456
+ const currentPageCount = Math.ceil(
457
+ this.size / (__privateGet(this, _range).to - __privateGet(this, _range).from)
458
+ );
459
+ const newPageCount = Math.ceil(this.size / (range.to - range.from));
460
+ __privateSet(this, _range, range);
461
+ const keysResequenced = __privateGet(this, _keys).reset(range);
462
+ this.sendRowsToClient(forceFullRefresh || keysResequenced);
463
+ requestAnimationFrame(() => {
464
+ if (newPageCount !== currentPageCount) {
465
+ this.emit("page-count", newPageCount);
466
+ }
467
+ this.emit("range", range);
468
+ });
469
+ } else if (forceFullRefresh) {
470
+ this.sendRowsToClient(forceFullRefresh);
471
+ }
472
+ }
473
+ sendRowsToClient(forceFullRefresh = false, row) {
474
+ if (row) {
475
+ this.clientCallback?.({
476
+ clientViewportId: this.viewport,
477
+ mode: "update",
478
+ rows: [
479
+ arrayDataUtils.toClientRow(row, __privateGet(this, _keys), this.selectedRows, this.dataIndices)
480
+ ],
481
+ type: "viewport-update"
482
+ });
483
+ } else {
484
+ const rowRange = this.rangeChangeRowset === "delta" && !forceFullRefresh ? vuuUtils.rangeNewItems(this.lastRangeServed, __privateGet(this, _range)) : __privateGet(this, _range);
485
+ const data = this.processedData ?? __privateGet(this, _data);
486
+ const rowsWithinViewport = data.slice(rowRange.from, rowRange.to).map(
487
+ (row2) => arrayDataUtils.toClientRow(row2, __privateGet(this, _keys), this.selectedRows, this.dataIndices)
488
+ );
489
+ this.clientCallback?.({
490
+ clientViewportId: this.viewport,
491
+ mode: "batch",
492
+ range: __privateGet(this, _range),
493
+ rows: rowsWithinViewport,
494
+ size: data.length,
495
+ type: "viewport-update"
496
+ });
497
+ this.lastRangeServed = {
498
+ from: __privateGet(this, _range).from,
499
+ to: __privateGet(this, _range).to
500
+ // to: Math.min(
501
+ // this.#range.to,
502
+ // this.#range.from + rowsWithinViewport.length,
503
+ // ),
504
+ };
505
+ }
506
+ }
507
+ get columns() {
508
+ return this._config.columns;
509
+ }
510
+ set columns(columns) {
511
+ const addedColumns = vuuUtils.getAddedItems(this.config.columns, columns);
512
+ if (addedColumns.length > 0) {
513
+ const columnsWithoutDescriptors = vuuUtils.getMissingItems(
514
+ this.columnDescriptors,
515
+ addedColumns,
516
+ (col) => col.name
517
+ );
518
+ console.log(`columnsWithoutDescriptors`, {
519
+ columnsWithoutDescriptors
520
+ });
521
+ }
522
+ __privateSet(this, _columnMap, vuuUtils.buildColumnMap(columns));
523
+ this.dataIndices = arrayDataUtils.buildDataToClientMap(__privateGet(this, _columnMap), this.dataMap);
524
+ this.config = {
525
+ ...this._config,
526
+ columns
527
+ };
528
+ }
529
+ get aggregations() {
530
+ return this._config.aggregations;
531
+ }
532
+ set aggregations(aggregations) {
533
+ this._config = {
534
+ ...this._config,
535
+ aggregations
536
+ };
537
+ const targetData = this.processedData ?? __privateGet(this, _data);
538
+ const leafData = __privateGet(this, _data);
539
+ aggregateUtils.aggregateData(
540
+ aggregations,
541
+ targetData,
542
+ this._config.groupBy,
543
+ leafData,
544
+ __privateGet(this, _columnMap),
545
+ this.groupMap
546
+ );
547
+ this.setRange(__privateGet(this, _range).reset, true);
548
+ this.emit("config", this._config, this.range);
549
+ }
550
+ get sort() {
551
+ return this._config.sort;
552
+ }
553
+ set sort(sort) {
554
+ debug?.(`sort ${JSON.stringify(sort)}`);
555
+ this.config = {
556
+ ...this._config,
557
+ sort
558
+ };
559
+ }
560
+ get baseFilter() {
561
+ return this._config.baseFilterSpec;
562
+ }
563
+ set baseFilter(baseFilter) {
564
+ debug?.(`baseFilter ${JSON.stringify(baseFilter)}`);
565
+ this.config = {
566
+ ...this._config,
567
+ baseFilterSpec: baseFilter
568
+ };
569
+ }
570
+ get filter() {
571
+ return this._config.filterSpec;
572
+ }
573
+ set filter(filter) {
574
+ debug?.(`filter ${JSON.stringify(filter)}`);
575
+ this.config = {
576
+ ...this._config,
577
+ filterSpec: filter
578
+ };
579
+ }
580
+ get groupBy() {
581
+ return this._config.groupBy;
582
+ }
583
+ set groupBy(groupBy) {
584
+ this.config = {
585
+ ...this._config,
586
+ groupBy
587
+ };
588
+ }
589
+ get title() {
590
+ return __privateGet(this, _title) ?? `${this.table.module} ${this.table.table}`;
591
+ }
592
+ set title(title) {
593
+ __privateSet(this, _title, title);
594
+ this.emit("title-changed", this.viewport, title);
595
+ }
596
+ get _clientCallback() {
597
+ return this.clientCallback;
598
+ }
599
+ createLink({
600
+ parentVpId,
601
+ link: { fromColumn, toColumn }
602
+ }) {
603
+ console.log("create link", {
604
+ parentVpId,
605
+ fromColumn,
606
+ toColumn
607
+ });
608
+ }
609
+ removeLink() {
610
+ console.log("remove link");
611
+ }
612
+ applyEdit(rowKey, columnName, value) {
613
+ console.log(`ArrayDataSource applyEdit ${rowKey} ${columnName} ${value}`);
614
+ return Promise.resolve(true);
615
+ }
616
+ async remoteProcedureCall() {
617
+ return Promise.reject();
618
+ }
619
+ async menuRpcCall(rpcRequest) {
620
+ return new Promise((resolve) => {
621
+ if (vuuUtils.isEditCellRequest(rpcRequest)) {
622
+ const { rowKey, field, value } = rpcRequest;
623
+ try {
624
+ this.updateDataItem(rowKey, field, value);
625
+ resolve({
626
+ action: {
627
+ type: "VP_EDIT_SUCCESS"
628
+ },
629
+ rpcName: "VP_EDIT_CELL_RPC",
630
+ type: "VIEW_PORT_MENU_RESP",
631
+ vpId: this.viewport
632
+ });
633
+ } catch (error) {
634
+ resolve({
635
+ error: String(error),
636
+ rpcName: "VP_EDIT_CELL_RPC",
637
+ type: "VIEW_PORT_MENU_REJ",
638
+ vpId: this.viewport
639
+ });
640
+ }
641
+ } else {
642
+ throw Error("menuRpcCall invalid rpcRequest");
643
+ }
644
+ });
645
+ }
646
+ convertKeysToIndexValues(keys) {
647
+ if (Array.isArray(keys)) {
648
+ const indexValues = [];
649
+ keys.forEach((key) => {
650
+ const rowIdx = this.indexOfRowWithKey(key);
651
+ if (rowIdx !== -1) {
652
+ indexValues.push(rowIdx);
653
+ }
654
+ });
655
+ return indexValues;
656
+ }
657
+ }
658
+ }
659
+ _columnMap = new WeakMap();
660
+ _data = new WeakMap();
661
+ _keys = new WeakMap();
662
+ _links = new WeakMap();
663
+ _range = new WeakMap();
664
+ _selectedRowsCount = new WeakMap();
665
+ _status = new WeakMap();
666
+ _title = new WeakMap();
667
+
668
+ exports.ArrayDataSource = ArrayDataSource;
669
+ //# sourceMappingURL=array-data-source.js.map