@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/cjs/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/cjs/data/DataSource.js
CHANGED
|
@@ -382,38 +382,82 @@ class DataSource extends EventTarget_1.EventTarget {
|
|
|
382
382
|
Array.isArray(indexed) || this.records.splice(indexed, 1, record);
|
|
383
383
|
}
|
|
384
384
|
}
|
|
385
|
-
|
|
385
|
+
_getRawRecordsArray() {
|
|
386
386
|
var _a;
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
387
|
+
const rawRecords = null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.records;
|
|
388
|
+
return Array.isArray(rawRecords) ? rawRecords : null;
|
|
389
|
+
}
|
|
390
|
+
_hasFilterInEffect() {
|
|
391
|
+
var _a, _b, _c, _d, _e;
|
|
392
|
+
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;
|
|
393
|
+
}
|
|
394
|
+
_normalizeInsertIndex(index, length) {
|
|
395
|
+
return null == index || index > length ? length : index < 0 ? 0 : index;
|
|
396
|
+
}
|
|
397
|
+
_mapViewInsertIndexToRawInsertIndex(rawRecords, viewIndex) {
|
|
398
|
+
if (viewIndex >= this.records.length) return rawRecords.length;
|
|
399
|
+
if (viewIndex <= 0) return 0;
|
|
400
|
+
const prevRecord = this.records[viewIndex - 1], rawIndex = rawRecords.indexOf(prevRecord);
|
|
401
|
+
return rawIndex >= 0 ? rawIndex + 1 : rawRecords.length;
|
|
402
|
+
}
|
|
403
|
+
_resetIndexingFromViewRecords() {
|
|
404
|
+
if (this._sourceLength = this.records.length, this.currentIndexedData = Array.from({
|
|
405
|
+
length: this._sourceLength
|
|
406
|
+
}, ((_, i) => i)), "tree" === this.rowHierarchyType && this.initTreeHierarchyState(),
|
|
407
|
+
this.userPagination) return this.pagination.totalCount = this._sourceLength, void this.updatePagerData();
|
|
408
|
+
this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
409
|
+
this.updatePagerData();
|
|
410
|
+
}
|
|
411
|
+
addRecord(record, index, syncToOriginalRecords = !1) {
|
|
412
|
+
var _a, _b, _c;
|
|
413
|
+
if (!syncToOriginalRecords) {
|
|
414
|
+
if (Array.isArray(this.records)) {
|
|
415
|
+
this.records.splice(index, 0, record), this.adjustBeforeChangedRecordsMap(index, 1),
|
|
416
|
+
this.currentIndexedData.push(this.currentIndexedData.length), this._sourceLength += 1;
|
|
417
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) this.fieldAggregators[i].push(record);
|
|
418
|
+
if ("tree" === this.rowHierarchyType && this.initTreeHierarchyState(), this.userPagination) {
|
|
419
|
+
this.pagination.totalCount = this._sourceLength;
|
|
420
|
+
const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
|
|
421
|
+
index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
|
|
422
|
+
} else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
423
|
+
this.updatePagerData();
|
|
424
|
+
(null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, 1);
|
|
425
|
+
}
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const rawRecords = this._getRawRecordsArray();
|
|
429
|
+
if (!rawRecords) return;
|
|
430
|
+
const viewInsertIndex = this._normalizeInsertIndex(index, this.records.length), rawInsertIndex = this._hasFilterInEffect() ? this._mapViewInsertIndexToRawInsertIndex(rawRecords, viewInsertIndex) : this._normalizeInsertIndex(viewInsertIndex, rawRecords.length);
|
|
431
|
+
rawRecords.splice(rawInsertIndex, 0, record), this.beforeChangedRecordsMap.clear(),
|
|
432
|
+
this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
|
|
433
|
+
(null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, 1);
|
|
434
|
+
}
|
|
435
|
+
addRecords(recordArr, index, syncToOriginalRecords = !1) {
|
|
436
|
+
var _a, _b, _c;
|
|
437
|
+
if (!syncToOriginalRecords) {
|
|
438
|
+
if (Array.isArray(this.records)) {
|
|
439
|
+
if (Array.isArray(recordArr)) {
|
|
440
|
+
this.records.splice(index, 0, ...recordArr), this.adjustBeforeChangedRecordsMap(index, recordArr.length);
|
|
441
|
+
for (let i = 0; i < recordArr.length; i++) this.currentIndexedData.push(this.currentIndexedData.length);
|
|
442
|
+
this._sourceLength += recordArr.length;
|
|
443
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) for (let j = 0; j < recordArr.length; j++) this.fieldAggregators[i].push(recordArr[j]);
|
|
444
|
+
}
|
|
445
|
+
if (this.userPagination) {
|
|
446
|
+
this.pagination.totalCount = this._sourceLength;
|
|
447
|
+
const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
|
|
448
|
+
index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
|
|
449
|
+
} else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
450
|
+
this.updatePagerData();
|
|
451
|
+
(null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, recordArr.length);
|
|
408
452
|
}
|
|
409
|
-
|
|
410
|
-
this.pagination.totalCount = this._sourceLength;
|
|
411
|
-
const {perPageCount: perPageCount, currentPage: currentPage} = this.pagination;
|
|
412
|
-
index < perPageCount * (currentPage || 0) + perPageCount && this.updatePagerData();
|
|
413
|
-
} else this.pagination.perPageCount = this._sourceLength, this.pagination.totalCount = this._sourceLength,
|
|
414
|
-
this.updatePagerData();
|
|
415
|
-
(null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.added) && this.dataSourceObj.added(index, recordArr.length);
|
|
453
|
+
return;
|
|
416
454
|
}
|
|
455
|
+
const rawRecords = this._getRawRecordsArray();
|
|
456
|
+
if (!rawRecords || !Array.isArray(recordArr) || 0 === recordArr.length) return;
|
|
457
|
+
const viewInsertIndex = this._normalizeInsertIndex(index, this.records.length), rawInsertIndex = this._hasFilterInEffect() ? this._mapViewInsertIndexToRawInsertIndex(rawRecords, viewInsertIndex) : this._normalizeInsertIndex(viewInsertIndex, rawRecords.length);
|
|
458
|
+
rawRecords.splice(rawInsertIndex, 0, ...recordArr), this.beforeChangedRecordsMap.clear(),
|
|
459
|
+
this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
|
|
460
|
+
(null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, recordArr.length);
|
|
417
461
|
}
|
|
418
462
|
addRecordForSorted(record) {
|
|
419
463
|
Array.isArray(this.records) && (this.beforeChangedRecordsMap.clear(), this.records.push(record),
|
|
@@ -442,23 +486,38 @@ class DataSource extends EventTarget_1.EventTarget {
|
|
|
442
486
|
this.beforeChangedRecordsMap.delete(key.toString()), this.beforeChangedRecordsMap.set((key + delta).toString(), record);
|
|
443
487
|
}
|
|
444
488
|
}
|
|
445
|
-
deleteRecords(recordIndexs) {
|
|
446
|
-
var _a;
|
|
447
|
-
if (
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
489
|
+
deleteRecords(recordIndexs, syncToOriginalRecords = !1) {
|
|
490
|
+
var _a, _b, _c;
|
|
491
|
+
if (!syncToOriginalRecords) {
|
|
492
|
+
if (Array.isArray(this.records)) {
|
|
493
|
+
const realDeletedRecordIndexs = [], recordIndexsMaxToMin = recordIndexs.sort(((a, b) => b - a));
|
|
494
|
+
for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
|
|
495
|
+
const recordIndex = recordIndexsMaxToMin[index];
|
|
496
|
+
if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
|
|
497
|
+
this.adjustBeforeChangedRecordsMap(recordIndex, 1, "delete"), realDeletedRecordIndexs.push(recordIndex);
|
|
498
|
+
const deletedRecord = this.records[recordIndex];
|
|
499
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) this.fieldAggregators[i].deleteRecord(deletedRecord);
|
|
500
|
+
this.records.splice(recordIndex, 1), this.currentIndexedData.pop(), this._sourceLength -= 1;
|
|
501
|
+
}
|
|
502
|
+
return this.userPagination || (this.pagination.perPageCount = this._sourceLength,
|
|
503
|
+
this.pagination.totalCount = this._sourceLength), this.updatePagerData(), (null === (_a = this.dataSourceObj) || void 0 === _a ? void 0 : _a.deleted) && this.dataSourceObj.deleted(realDeletedRecordIndexs),
|
|
504
|
+
realDeletedRecordIndexs;
|
|
456
505
|
}
|
|
457
|
-
return
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
506
|
+
return [];
|
|
507
|
+
}
|
|
508
|
+
const rawRecords = this._getRawRecordsArray();
|
|
509
|
+
if (!rawRecords || !Array.isArray(this.records)) return [];
|
|
510
|
+
const realDeletedRecordIndexs = [], recordIndexsMaxToMin = recordIndexs.slice().sort(((a, b) => b - a)), rawDeletedIndexs = [];
|
|
511
|
+
for (let index = 0; index < recordIndexsMaxToMin.length; index++) {
|
|
512
|
+
const viewIndex = recordIndexsMaxToMin[index];
|
|
513
|
+
if (viewIndex >= this.records.length || viewIndex < 0) continue;
|
|
514
|
+
const deletedRecord = this.records[viewIndex], rawIndex = rawRecords.indexOf(deletedRecord);
|
|
515
|
+
rawIndex >= 0 && (rawRecords.splice(rawIndex, 1), rawDeletedIndexs.push(rawIndex)),
|
|
516
|
+
realDeletedRecordIndexs.push(viewIndex);
|
|
517
|
+
}
|
|
518
|
+
return this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
|
|
519
|
+
(null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.deleted) && this.dataSourceObj.deleted(rawDeletedIndexs),
|
|
520
|
+
realDeletedRecordIndexs;
|
|
462
521
|
}
|
|
463
522
|
deleteRecordsForSorted(recordIndexs) {
|
|
464
523
|
if (Array.isArray(this.records)) {
|
|
@@ -473,20 +532,38 @@ class DataSource extends EventTarget_1.EventTarget {
|
|
|
473
532
|
this.pagination.totalCount = this._sourceLength), this.beforeChangedRecordsMap.clear();
|
|
474
533
|
}
|
|
475
534
|
}
|
|
476
|
-
updateRecords(records, recordIndexs) {
|
|
477
|
-
|
|
535
|
+
updateRecords(records, recordIndexs, syncToOriginalRecords = !1) {
|
|
536
|
+
var _a;
|
|
537
|
+
if (!syncToOriginalRecords) {
|
|
538
|
+
const realDeletedRecordIndexs = [];
|
|
539
|
+
for (let index = 0; index < recordIndexs.length; index++) {
|
|
540
|
+
const recordIndex = recordIndexs[index];
|
|
541
|
+
if (Array.isArray(recordIndex)) this.beforeChangedRecordsMap.delete(recordIndex.toString()),
|
|
542
|
+
realDeletedRecordIndexs.push(recordIndex), recordIndex.slice(0, -1).reduce(((acc, key) => (void 0 === acc[key] && (acc[key] = {}),
|
|
543
|
+
acc[key].children)), this.records)[recordIndex[recordIndex.length - 1]] = records[index]; else {
|
|
544
|
+
if (recordIndex >= this._sourceLength || recordIndex < 0) continue;
|
|
545
|
+
this.beforeChangedRecordsMap.delete(recordIndex.toString()), realDeletedRecordIndexs.push(recordIndex);
|
|
546
|
+
for (let i = 0; i < this.fieldAggregators.length; i++) this.fieldAggregators[i].updateRecord(this.records[recordIndex], records[index]);
|
|
547
|
+
this.records[recordIndex] = records[index];
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
return this.userPagination && this.updatePagerData(), realDeletedRecordIndexs;
|
|
551
|
+
}
|
|
552
|
+
const rawRecords = this._getRawRecordsArray();
|
|
553
|
+
if (!rawRecords || !Array.isArray(this.records)) return [];
|
|
554
|
+
const realUpdatedIndexs = [];
|
|
478
555
|
for (let index = 0; index < recordIndexs.length; index++) {
|
|
479
556
|
const recordIndex = recordIndexs[index];
|
|
480
557
|
if (Array.isArray(recordIndex)) this.beforeChangedRecordsMap.delete(recordIndex.toString()),
|
|
481
|
-
|
|
482
|
-
acc[key].children)),
|
|
483
|
-
if (recordIndex >= this.
|
|
484
|
-
this.
|
|
485
|
-
|
|
486
|
-
this.records[recordIndex] = records[index];
|
|
558
|
+
realUpdatedIndexs.push(recordIndex), recordIndex.slice(0, -1).reduce(((acc, key) => (void 0 === acc[key] && (acc[key] = {}),
|
|
559
|
+
acc[key].children)), rawRecords)[recordIndex[recordIndex.length - 1]] = records[index]; else {
|
|
560
|
+
if (recordIndex >= this.records.length || recordIndex < 0) continue;
|
|
561
|
+
const oldRecord = this.records[recordIndex], rawIndex = rawRecords.indexOf(oldRecord);
|
|
562
|
+
rawIndex >= 0 && (rawRecords[rawIndex] = records[index]), realUpdatedIndexs.push(recordIndex);
|
|
487
563
|
}
|
|
488
564
|
}
|
|
489
|
-
return this.
|
|
565
|
+
return this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_a = this.dataConfig) || void 0 === _a ? void 0 : _a.filterRules),
|
|
566
|
+
realUpdatedIndexs;
|
|
490
567
|
}
|
|
491
568
|
updateRecordsForSorted(records, recordIndexs) {
|
|
492
569
|
const realDeletedRecordIndexs = [];
|