@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;
@@ -369,8 +369,15 @@ export class DataSource extends EventTarget {
369
369
  return null == index || index > length ? length : index < 0 ? 0 : index;
370
370
  }
371
371
  _mapViewInsertIndexToRawInsertIndex(rawRecords, viewIndex) {
372
- if (viewIndex >= this.records.length) return rawRecords.length;
373
- if (viewIndex <= 0) return 0;
372
+ if (0 === this.records.length) return rawRecords.length;
373
+ if (viewIndex <= 0) {
374
+ const firstVisibleRecord = this.records[0], rawIndex = rawRecords.indexOf(firstVisibleRecord);
375
+ return rawIndex >= 0 ? rawIndex : 0;
376
+ }
377
+ if (viewIndex >= this.records.length) {
378
+ const lastVisibleRecord = this.records[this.records.length - 1], rawIndex = rawRecords.indexOf(lastVisibleRecord);
379
+ return rawIndex >= 0 ? rawIndex + 1 : rawRecords.length;
380
+ }
374
381
  const prevRecord = this.records[viewIndex - 1], rawIndex = rawRecords.indexOf(prevRecord);
375
382
  return rawIndex >= 0 ? rawIndex + 1 : rawRecords.length;
376
383
  }
@@ -402,8 +409,8 @@ export class DataSource extends EventTarget {
402
409
  const rawRecords = this._getRawRecordsArray();
403
410
  if (!rawRecords) return;
404
411
  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),
412
+ rawRecords.splice(rawInsertIndex, 0, record), syncToOriginalRecords && this._hasFilterInEffect() && this.markForceVisibleRecord(record),
413
+ this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
407
414
  (null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, 1);
408
415
  }
409
416
  addRecords(recordArr, index, syncToOriginalRecords = !1) {
@@ -429,8 +436,8 @@ export class DataSource extends EventTarget {
429
436
  const rawRecords = this._getRawRecordsArray();
430
437
  if (!rawRecords || !Array.isArray(recordArr) || 0 === recordArr.length) return;
431
438
  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),
439
+ if (rawRecords.splice(rawInsertIndex, 0, ...recordArr), syncToOriginalRecords && this._hasFilterInEffect()) for (let i = 0; i < recordArr.length; i++) this.markForceVisibleRecord(recordArr[i]);
440
+ this.beforeChangedRecordsMap.clear(), this.sortedIndexMap.clear(), this.updateFilterRules(null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules),
434
441
  (null === (_c = this.dataSourceObj) || void 0 === _c ? void 0 : _c.added) && this.dataSourceObj.added(rawInsertIndex, recordArr.length);
435
442
  }
436
443
  addRecordForSorted(record) {
@@ -603,23 +610,31 @@ export class DataSource extends EventTarget {
603
610
  setSortedIndexMap(field, filedMap) {
604
611
  this.sortedIndexMap.set(field, filedMap);
605
612
  }
613
+ markForceVisibleRecord(record) {
614
+ !record || "object" != typeof record && "function" != typeof record || (this._forceVisibleRecords || (this._forceVisibleRecords = new WeakSet),
615
+ this._forceVisibleRecords.add(record));
616
+ }
617
+ clearForceVisibleRecords() {
618
+ this._forceVisibleRecords = void 0;
619
+ }
606
620
  clearFilteredChildren(record) {
607
621
  var _a, _b;
608
622
  record.filteredChildren = void 0;
609
623
  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]);
610
624
  }
611
625
  filterRecord(record) {
612
- var _a, _b, _c;
626
+ var _a, _b, _c, _d;
627
+ if (null === (_a = this._forceVisibleRecords) || void 0 === _a ? void 0 : _a.has(record)) return !0;
613
628
  let isReserved = !0;
614
- for (let i = 0; i < (null === (_a = this.dataConfig.filterRules) || void 0 === _a ? void 0 : _a.length); i++) {
615
- const filterRule = null === (_b = this.dataConfig) || void 0 === _b ? void 0 : _b.filterRules[i];
629
+ for (let i = 0; i < (null === (_b = this.dataConfig.filterRules) || void 0 === _b ? void 0 : _b.length); i++) {
630
+ const filterRule = null === (_c = this.dataConfig) || void 0 === _c ? void 0 : _c.filterRules[i];
616
631
  if (filterRule.filterKey) {
617
632
  const filterValue = record[filterRule.filterKey];
618
633
  if (-1 === filterRule.filteredValues.indexOf(filterValue)) {
619
634
  isReserved = !1;
620
635
  break;
621
636
  }
622
- } else if (!(null === (_c = filterRule.filterFunc) || void 0 === _c ? void 0 : _c.call(filterRule, record))) {
637
+ } else if (!(null === (_d = filterRule.filterFunc) || void 0 === _d ? void 0 : _d.call(filterRule, record))) {
623
638
  isReserved = !1;
624
639
  break;
625
640
  }