@visactor/vtable 1.22.11-alpha.7 → 1.22.11-alpha.9

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.
@@ -33,6 +33,7 @@ export declare class DataSource extends EventTarget implements DataSourceAPI {
33
33
  private _sourceLength;
34
34
  private _source;
35
35
  protected sortedIndexMap: Map<FieldDef, ISortedMapItem>;
36
+ private _forceVisibleRecords?;
36
37
  private lastSortStates;
37
38
  currentIndexedData: (number | number[])[] | null;
38
39
  protected userPagination: IPagination;
@@ -105,6 +106,8 @@ export declare class DataSource extends EventTarget implements DataSourceAPI {
105
106
  updateRecordsForSorted(records: any[], recordIndexs: number[]): void;
106
107
  sort(states: Array<SortState>): void;
107
108
  setSortedIndexMap(field: FieldDef, filedMap: ISortedMapItem): void;
109
+ markForceVisibleRecord(record: any): void;
110
+ clearForceVisibleRecords(): void;
108
111
  private clearFilteredChildren;
109
112
  private filterRecord;
110
113
  updateFilterRulesForSorted(filterRules?: FilterRules): void;
@@ -395,8 +395,15 @@ class DataSource extends EventTarget_1.EventTarget {
395
395
  return null == index || index > length ? length : index < 0 ? 0 : index;
396
396
  }
397
397
  _mapViewInsertIndexToRawInsertIndex(rawRecords, viewIndex) {
398
- if (viewIndex >= this.records.length) return rawRecords.length;
399
- if (viewIndex <= 0) return 0;
398
+ if (0 === this.records.length) return rawRecords.length;
399
+ if (viewIndex <= 0) {
400
+ const firstVisibleRecord = this.records[0], rawIndex = rawRecords.indexOf(firstVisibleRecord);
401
+ return rawIndex >= 0 ? rawIndex : 0;
402
+ }
403
+ if (viewIndex >= this.records.length) {
404
+ const lastVisibleRecord = this.records[this.records.length - 1], rawIndex = rawRecords.indexOf(lastVisibleRecord);
405
+ return rawIndex >= 0 ? rawIndex + 1 : rawRecords.length;
406
+ }
400
407
  const prevRecord = this.records[viewIndex - 1], rawIndex = rawRecords.indexOf(prevRecord);
401
408
  return rawIndex >= 0 ? rawIndex + 1 : rawRecords.length;
402
409
  }
@@ -428,8 +435,8 @@ class DataSource extends EventTarget_1.EventTarget {
428
435
  const rawRecords = this._getRawRecordsArray();
429
436
  if (!rawRecords) return;
430
437
  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),
438
+ rawRecords.splice(rawInsertIndex, 0, record), syncToOriginalRecords && this._hasFilterInEffect() && this.markForceVisibleRecord(record),
439
+ this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
433
440
  (null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, 1);
434
441
  }
435
442
  addRecords(recordArr, index, syncToOriginalRecords = !1) {
@@ -455,8 +462,8 @@ class DataSource extends EventTarget_1.EventTarget {
455
462
  const rawRecords = this._getRawRecordsArray();
456
463
  if (!rawRecords || !Array.isArray(recordArr) || 0 === recordArr.length) return;
457
464
  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),
465
+ if (rawRecords.splice(rawInsertIndex, 0, ...recordArr), syncToOriginalRecords && this._hasFilterInEffect()) for (let i = 0; i < recordArr.length; i++) this.markForceVisibleRecord(recordArr[i]);
466
+ this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
460
467
  (null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, recordArr.length);
461
468
  }
462
469
  addRecordForSorted(record) {
@@ -629,23 +636,31 @@ class DataSource extends EventTarget_1.EventTarget {
629
636
  setSortedIndexMap(field, filedMap) {
630
637
  this.sortedIndexMap.set(field, filedMap);
631
638
  }
639
+ markForceVisibleRecord(record) {
640
+ !record || "object" != typeof record && "function" != typeof record || (this._forceVisibleRecords || (this._forceVisibleRecords = new WeakSet),
641
+ this._forceVisibleRecords.add(record));
642
+ }
643
+ clearForceVisibleRecords() {
644
+ this._forceVisibleRecords = void 0;
645
+ }
632
646
  clearFilteredChildren(record) {
633
647
  var _a, _b;
634
648
  record.filteredChildren = void 0;
635
649
  for (let i = 0; i < (null !== (_b = null === (_a = record.children) || void 0 === _a ? void 0 : _a.length) && void 0 !== _b ? _b : 0); i++) this.clearFilteredChildren(record.children[i]);
636
650
  }
637
651
  filterRecord(record) {
638
- var _a, _b, _c;
652
+ var _a, _b, _c, _d;
653
+ if (null === (_a = this._forceVisibleRecords) || void 0 === _a ? void 0 : _a.has(record)) return !0;
639
654
  let isReserved = !0;
640
- for (let i = 0; i < (null === (_a = this.dataConfig.filterRules) || void 0 === _a ? void 0 : _a.length); i++) {
641
- const filterRule = null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules[i];
655
+ for (let i = 0; i < (null === (_b = this.dataConfig.filterRules) || void 0 === _b ? void 0 : _b.length); i++) {
656
+ const filterRule = null === (_c = this.dataConfig) || void 0 === _c ? void 0 : _c.filterRules[i];
642
657
  if (filterRule.filterKey) {
643
658
  const filterValue = record[filterRule.filterKey];
644
659
  if (-1 === filterRule.filteredValues.indexOf(filterValue)) {
645
660
  isReserved = !1;
646
661
  break;
647
662
  }
648
- } else if (!(null === (_c = filterRule.filterFunc) || void 0 === _c ? void 0 : _c.call(filterRule, record))) {
663
+ } else if (!(null === (_d = filterRule.filterFunc) || void 0 === _d ? void 0 : _d.call(filterRule, record))) {
649
664
  isReserved = !1;
650
665
  break;
651
666
  }