@visactor/vtable 1.22.11-alpha.5 → 1.22.11-alpha.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/core/BaseTable.js +1 -1
- package/cjs/core/BaseTable.js.map +1 -1
- package/cjs/core/record-helper.js +39 -23
- package/cjs/core/record-helper.js.map +1 -1
- package/cjs/data/DataSource.d.ts +9 -4
- package/cjs/data/DataSource.js +131 -54
- package/cjs/data/DataSource.js.map +1 -1
- package/cjs/index.d.ts +1 -1
- package/cjs/index.js +1 -1
- package/cjs/index.js.map +1 -1
- package/cjs/themes/theme-define.js +6 -0
- package/cjs/themes/theme-define.js.map +1 -1
- package/cjs/ts-types/table-engine.d.ts +1 -0
- package/cjs/ts-types/table-engine.js.map +1 -1
- package/cjs/vrender.js.map +1 -1
- package/dist/vtable.js +311 -104
- package/dist/vtable.min.js +2 -2
- package/es/core/BaseTable.js +1 -1
- package/es/core/BaseTable.js.map +1 -1
- package/es/core/record-helper.js +39 -23
- package/es/core/record-helper.js.map +1 -1
- package/es/data/DataSource.d.ts +9 -4
- package/es/data/DataSource.js +130 -53
- package/es/data/DataSource.js.map +1 -1
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/index.js.map +1 -1
- package/es/themes/theme-define.js +6 -0
- package/es/themes/theme-define.js.map +1 -1
- package/es/ts-types/table-engine.d.ts +1 -0
- package/es/ts-types/table-engine.js.map +1 -1
- package/es/vrender.js.map +1 -1
- package/package.json +4 -4
package/es/data/DataSource.d.ts
CHANGED
|
@@ -89,14 +89,19 @@ export declare class DataSource extends EventTarget implements DataSourceAPI {
|
|
|
89
89
|
changeFieldValueByRecordIndex(value: FieldData, recordIndex: number | number[], field: FieldDef, table?: BaseTableAPI): FieldData;
|
|
90
90
|
cacheBeforeChangedRecord(dataIndex: number | number[], table?: BaseTableAPI): void;
|
|
91
91
|
setRecord(record: any, index: number): void;
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
private _getRawRecordsArray;
|
|
93
|
+
private _hasFilterInEffect;
|
|
94
|
+
private _normalizeInsertIndex;
|
|
95
|
+
private _mapViewInsertIndexToRawInsertIndex;
|
|
96
|
+
private _resetIndexingFromViewRecords;
|
|
97
|
+
addRecord(record: any, index: number, syncToOriginalRecords?: boolean): void;
|
|
98
|
+
addRecords(recordArr: any, index: number, syncToOriginalRecords?: boolean): void;
|
|
94
99
|
addRecordForSorted(record: any): void;
|
|
95
100
|
addRecordsForSorted(recordArr: any): void;
|
|
96
101
|
adjustBeforeChangedRecordsMap(insertIndex: number, insertCount: number, type?: 'add' | 'delete'): void;
|
|
97
|
-
deleteRecords(recordIndexs: number[]): number[];
|
|
102
|
+
deleteRecords(recordIndexs: number[], syncToOriginalRecords?: boolean): number[];
|
|
98
103
|
deleteRecordsForSorted(recordIndexs: number[]): void;
|
|
99
|
-
updateRecords(records: any[], recordIndexs: (number | number[])[]): (number | number[])[];
|
|
104
|
+
updateRecords(records: any[], recordIndexs: (number | number[])[], syncToOriginalRecords?: boolean): (number | number[])[];
|
|
100
105
|
updateRecordsForSorted(records: any[], recordIndexs: number[]): void;
|
|
101
106
|
sort(states: Array<SortState>): void;
|
|
102
107
|
setSortedIndexMap(field: FieldDef, filedMap: ISortedMapItem): void;
|
package/es/data/DataSource.js
CHANGED
|
@@ -356,38 +356,82 @@ export class DataSource extends EventTarget {
|
|
|
356
356
|
Array.isArray(indexed) || this.records.splice(indexed, 1, record);
|
|
357
357
|
}
|
|
358
358
|
}
|
|
359
|
-
|
|
359
|
+
_getRawRecordsArray() {
|
|
360
360
|
var _a;
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
361
|
+
const rawRecords = null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.records;
|
|
362
|
+
return Array.isArray(rawRecords) ? rawRecords : null;
|
|
363
|
+
}
|
|
364
|
+
_hasFilterInEffect() {
|
|
365
|
+
var _a, _b, _c, _d, _e;
|
|
366
|
+
return (null !== (_c = null === (_b = null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules) || void 0 === _b ? void 0 : _b.length) && void 0 !== _c ? _c : 0) >= 1 || (null !== (_e = null === (_d = this.lastFilterRules) || void 0 === _d ? void 0 : _d.length) && void 0 !== _e ? _e : 0) >= 1;
|
|
367
|
+
}
|
|
368
|
+
_normalizeInsertIndex(index, length) {
|
|
369
|
+
return null == index || index > length ? length : index < 0 ? 0 : index;
|
|
370
|
+
}
|
|
371
|
+
_mapViewInsertIndexToRawInsertIndex(rawRecords, viewIndex) {
|
|
372
|
+
if (viewIndex >= this.records.length) return rawRecords.length;
|
|
373
|
+
if (viewIndex <= 0) return 0;
|
|
374
|
+
const prevRecord = this.records[viewIndex - 1], rawIndex = rawRecords.indexOf(prevRecord);
|
|
375
|
+
return rawIndex >= 0 ? rawIndex + 1 : rawRecords.length;
|
|
376
|
+
}
|
|
377
|
+
_resetIndexingFromViewRecords() {
|
|
378
|
+
if (this._sourceLength = this.records.length, this.currentIndexedData = Array.from({
|
|
379
|
+
length: this._sourceLength
|
|
380
|
+
}, ((_, i) => i)), "tree" === this.rowHierarchyType && this.initTreeHierarchyState(),
|
|
381
|
+
this.userPagination) return this.pagination.totalCount = this._sourceLength, void this.updatePagerData();
|
|
382
|
+
this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
383
|
+
this.updatePagerData();
|
|
384
|
+
}
|
|
385
|
+
addRecord(record, index, syncToOriginalRecords = !1) {
|
|
386
|
+
var _a, _b, _c;
|
|
387
|
+
if (!syncToOriginalRecords) {
|
|
388
|
+
if (Array.isArray(this.records)) {
|
|
389
|
+
this.records.splice(index, 0, record), this.adjustBeforeChangedRecordsMap(index, 1),
|
|
390
|
+
this.currentIndexedData.push(this.currentIndexedData.length), this._sourceLength += 1;
|
|
391
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) this.fieldAggregators[i].push(record);
|
|
392
|
+
if ("tree" === this.rowHierarchyType && this.initTreeHierarchyState(), this.userPagination) {
|
|
393
|
+
this.pagination.totalCount = this._sourceLength;
|
|
394
|
+
const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
|
|
395
|
+
index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
|
|
396
|
+
} else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
397
|
+
this.updatePagerData();
|
|
398
|
+
(null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, 1);
|
|
382
399
|
}
|
|
383
|
-
|
|
384
|
-
this.pagination.totalCount = this._sourceLength;
|
|
385
|
-
const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
|
|
386
|
-
index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
|
|
387
|
-
} else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
388
|
-
this.updatePagerData();
|
|
389
|
-
(null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, recordArr.length);
|
|
400
|
+
return;
|
|
390
401
|
}
|
|
402
|
+
const rawRecords = this._getRawRecordsArray();
|
|
403
|
+
if (!rawRecords) return;
|
|
404
|
+
const viewInsertIndex = this._normalizeInsertIndex(index, this.records.length), rawInsertIndex = this._hasFilterInEffect() ? this._mapViewInsertIndexToRawInsertIndex(rawRecords, viewInsertIndex) : this._normalizeInsertIndex(viewInsertIndex, rawRecords.length);
|
|
405
|
+
rawRecords.splice(rawInsertIndex, 0, record), this.beforeChangedRecordsMap.clear(),
|
|
406
|
+
this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
|
|
407
|
+
(null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, 1);
|
|
408
|
+
}
|
|
409
|
+
addRecords(recordArr, index, syncToOriginalRecords = !1) {
|
|
410
|
+
var _a, _b, _c;
|
|
411
|
+
if (!syncToOriginalRecords) {
|
|
412
|
+
if (Array.isArray(this.records)) {
|
|
413
|
+
if (Array.isArray(recordArr)) {
|
|
414
|
+
this.records.splice(index, 0, ...recordArr), this.adjustBeforeChangedRecordsMap(index, recordArr.length);
|
|
415
|
+
for (let i = 0; i < recordArr.length; i++) this.currentIndexedData.push(this.currentIndexedData.length);
|
|
416
|
+
this._sourceLength += recordArr.length;
|
|
417
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) for (let j = 0; j < recordArr.length; j++) this.fieldAggregators[i].push(recordArr[j]);
|
|
418
|
+
}
|
|
419
|
+
if (this.userPagination) {
|
|
420
|
+
this.pagination.totalCount = this._sourceLength;
|
|
421
|
+
const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
|
|
422
|
+
index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
|
|
423
|
+
} else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
424
|
+
this.updatePagerData();
|
|
425
|
+
(null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, recordArr.length);
|
|
426
|
+
}
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
const rawRecords = this._getRawRecordsArray();
|
|
430
|
+
if (!rawRecords || !Array.isArray(recordArr) || 0 === recordArr.length) return;
|
|
431
|
+
const viewInsertIndex = this._normalizeInsertIndex(index, this.records.length), rawInsertIndex = this._hasFilterInEffect() ? this._mapViewInsertIndexToRawInsertIndex(rawRecords, viewInsertIndex) : this._normalizeInsertIndex(viewInsertIndex, rawRecords.length);
|
|
432
|
+
rawRecords.splice(rawInsertIndex, 0, ...recordArr), this.beforeChangedRecordsMap.clear(),
|
|
433
|
+
this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
|
|
434
|
+
(null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, recordArr.length);
|
|
391
435
|
}
|
|
392
436
|
addRecordForSorted(record) {
|
|
393
437
|
Array.isArray(this.records) && (this.beforeChangedRecordsMap.clear(), this.records.push(record),
|
|
@@ -416,23 +460,38 @@ export class DataSource extends EventTarget {
|
|
|
416
460
|
this.beforeChangedRecordsMap.delete(key.toString()), this.beforeChangedRecordsMap.set((key + delta).toString(), record);
|
|
417
461
|
}
|
|
418
462
|
}
|
|
419
|
-
deleteRecords(recordIndexs) {
|
|
420
|
-
var _a;
|
|
421
|
-
if (
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
463
|
+
deleteRecords(recordIndexs, syncToOriginalRecords = !1) {
|
|
464
|
+
var _a, _b, _c;
|
|
465
|
+
if (!syncToOriginalRecords) {
|
|
466
|
+
if (Array.isArray(this.records)) {
|
|
467
|
+
const realDeletedRecordIndexs = [], recordIndexsMaxToMin = recordIndexs.sort(((a, b) => b - a));
|
|
468
|
+
for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
|
|
469
|
+
const recordIndex = recordIndexsMaxToMin[index];
|
|
470
|
+
if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
|
|
471
|
+
this.adjustBeforeChangedRecordsMap(recordIndex, 1, "delete"), realDeletedRecordIndexs.push(recordIndex);
|
|
472
|
+
const deletedRecord = this.records[recordIndex];
|
|
473
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) this.fieldAggregators[i].deleteRecord(deletedRecord);
|
|
474
|
+
this.records.splice(recordIndex, 1), this.currentIndexedData.pop(), this._sourceLength -= 1;
|
|
475
|
+
}
|
|
476
|
+
return this.userPagination || (this.pagination.perPageCount = this._sourceLength,
|
|
477
|
+
this.pagination.totalCount = this._sourceLength), this.updatePagerData(), (null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.deleted) && this.dataSourceObj.deleted(realDeletedRecordIndexs),
|
|
478
|
+
realDeletedRecordIndexs;
|
|
430
479
|
}
|
|
431
|
-
return
|
|
432
|
-
this.pagination.totalCount = this._sourceLength), this.updatePagerData(), (null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.deleted) && this.dataSourceObj.deleted(realDeletedRecordIndexs),
|
|
433
|
-
realDeletedRecordIndexs;
|
|
480
|
+
return [];
|
|
434
481
|
}
|
|
435
|
-
|
|
482
|
+
const rawRecords = this._getRawRecordsArray();
|
|
483
|
+
if (!rawRecords || !Array.isArray(this.records)) return [];
|
|
484
|
+
const realDeletedRecordIndexs = [], recordIndexsMaxToMin = recordIndexs.slice().sort(((a, b) => b - a)), rawDeletedIndexs = [];
|
|
485
|
+
for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
|
|
486
|
+
const viewIndex = recordIndexsMaxToMin[index];
|
|
487
|
+
if (viewIndex >= this.records.length || viewIndex < 0) continue;
|
|
488
|
+
const deletedRecord = this.records[viewIndex], rawIndex = rawRecords.indexOf(deletedRecord);
|
|
489
|
+
rawIndex >= 0 && (rawRecords.splice(rawIndex, 1), rawDeletedIndexs.push(rawIndex)),
|
|
490
|
+
realDeletedRecordIndexs.push(viewIndex);
|
|
491
|
+
}
|
|
492
|
+
return this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
|
|
493
|
+
(null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.deleted) && this.dataSourceObj.deleted(rawDeletedIndexs),
|
|
494
|
+
realDeletedRecordIndexs;
|
|
436
495
|
}
|
|
437
496
|
deleteRecordsForSorted(recordIndexs) {
|
|
438
497
|
if (Array.isArray(this.records)) {
|
|
@@ -447,20 +506,38 @@ export class DataSource extends EventTarget {
|
|
|
447
506
|
this.pagination.totalCount = this._sourceLength), this.beforeChangedRecordsMap.clear();
|
|
448
507
|
}
|
|
449
508
|
}
|
|
450
|
-
updateRecords(records, recordIndexs) {
|
|
451
|
-
|
|
509
|
+
updateRecords(records, recordIndexs, syncToOriginalRecords = !1) {
|
|
510
|
+
var _a;
|
|
511
|
+
if (!syncToOriginalRecords) {
|
|
512
|
+
const realDeletedRecordIndexs = [];
|
|
513
|
+
for (let index = 0; index < recordIndexs.length; index++) {
|
|
514
|
+
const recordIndex = recordIndexs[index];
|
|
515
|
+
if (Array.isArray(recordIndex)) this.beforeChangedRecordsMap.delete(recordIndex.toString()),
|
|
516
|
+
realDeletedRecordIndexs.push(recordIndex), recordIndex.slice(0, -1).reduce(((acc, key) => (void 0 === acc[key] && (acc[key] = {}),
|
|
517
|
+
acc[key].children)), this.records)[recordIndex[recordIndex.length - 1]] = records[index]; else {
|
|
518
|
+
if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
|
|
519
|
+
this.beforeChangedRecordsMap.delete(recordIndex.toString()), realDeletedRecordIndexs.push(recordIndex);
|
|
520
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) this.fieldAggregators[i].updateRecord(this.records[recordIndex], records[index]);
|
|
521
|
+
this.records[recordIndex] = records[index];
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
return this.userPagination && this.updatePagerData(), realDeletedRecordIndexs;
|
|
525
|
+
}
|
|
526
|
+
const rawRecords = this._getRawRecordsArray();
|
|
527
|
+
if (!rawRecords || !Array.isArray(this.records)) return [];
|
|
528
|
+
const realUpdatedIndexs = [];
|
|
452
529
|
for (let index = 0; index < recordIndexs.length; index++) {
|
|
453
530
|
const recordIndex = recordIndexs[index];
|
|
454
531
|
if (Array.isArray(recordIndex)) this.beforeChangedRecordsMap.delete(recordIndex.toString()),
|
|
455
|
-
|
|
456
|
-
acc[key].children)),
|
|
457
|
-
if (recordIndex >= this.
|
|
458
|
-
this.
|
|
459
|
-
|
|
460
|
-
this.records[recordIndex] = records[index];
|
|
532
|
+
realUpdatedIndexs.push(recordIndex), recordIndex.slice(0, -1).reduce(((acc, key) => (void 0 === acc[key] && (acc[key] = {}),
|
|
533
|
+
acc[key].children)), rawRecords)[recordIndex[recordIndex.length - 1]] = records[index]; else {
|
|
534
|
+
if (recordIndex >= this.records.length || recordIndex < 0) continue;
|
|
535
|
+
const oldRecord = this.records[recordIndex], rawIndex = rawRecords.indexOf(oldRecord);
|
|
536
|
+
rawIndex >= 0 && (rawRecords[rawIndex] = records[index]), realUpdatedIndexs.push(recordIndex);
|
|
461
537
|
}
|
|
462
538
|
}
|
|
463
|
-
return this.
|
|
539
|
+
return this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules),
|
|
540
|
+
realUpdatedIndexs;
|
|
464
541
|
}
|
|
465
542
|
updateRecordsForSorted(records, recordIndexs) {
|
|
466
543
|
const realDeletedRecordIndexs = [];
|