@infinite-table/infinite-react 9.4.0 → 9.4.1

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/index.d.ts CHANGED
@@ -59,7 +59,12 @@ declare class DeepMap<KeyType, ValueType> {
59
59
  private map;
60
60
  private length;
61
61
  private revision;
62
+ private mutations;
62
63
  private emptyKey;
64
+ /**
65
+ * Increases on every set, delete and clear, so derived data can be cached until the map changes
66
+ */
67
+ get version(): number;
63
68
  static clone<KeyType, ValueType>(map: DeepMap<KeyType, ValueType>): DeepMap<KeyType, ValueType>;
64
69
  constructor(initial?: [KeyType[], ValueType][]);
65
70
  fill(initial?: [KeyType[], ValueType][]): void;
@@ -2454,6 +2459,10 @@ type RowSelectionStateConfig<T> = {
2454
2459
  * The count of all the rows - for lazy load, after the (remote) filter
2455
2460
  */
2456
2461
  totalCount: number;
2462
+ /**
2463
+ * Lazy load with grouping: the count of all the (leaf) rows, after the filter, when the server sends it
2464
+ */
2465
+ lazyGroupedRowCount?: number;
2457
2466
  /**
2458
2467
  * Lazy load: the count of all the rows without the filter, when the server sends it
2459
2468
  */
@@ -2489,6 +2498,14 @@ declare class RowSelectionState<T = any> {
2489
2498
  selectedCount: number;
2490
2499
  deselectedCount: number;
2491
2500
  }>;
2501
+ /**
2502
+ * Lazy load: the selected (true) and deselected (false) entries, in one map,
2503
+ * for the given versions of the selection maps
2504
+ */
2505
+ private lazyEntries;
2506
+ private lazyLoadedRows;
2507
+ private lazyChildrenLoaded;
2508
+ private lazyRowCounts;
2492
2509
  getConfig: GetRowSelectionStateConfig<T>;
2493
2510
  getGroupKeysForPrimaryKey(pk: any): any[];
2494
2511
  getGroupDeepMap(): DeepMap<any, DeepMapGroupValueType<T, any>> | undefined;
@@ -2518,6 +2535,32 @@ declare class RowSelectionState<T = any> {
2518
2535
  * its loaded groups - so the rows of the groups hidden by the filter or not loaded yet
2519
2536
  */
2520
2537
  getLazyHiddenRowsCount(groupKeys: any[]): number;
2538
+ private getLazyEntries;
2539
+ /**
2540
+ * Lazy load: the count of the rows inside the group, as the server sent it
2541
+ */
2542
+ private getLazyRowCount;
2543
+ private computeLazyRowCount;
2544
+ /**
2545
+ * Lazy load: whether the server sent all the direct children of the group
2546
+ */
2547
+ private areLazyChildrenLoaded;
2548
+ private computeLazyChildrenLoaded;
2549
+ /**
2550
+ * Lazy load, at the last group level (or the root, without grouping): the primary keys
2551
+ * of the loaded rows, and whether they are all the rows of the group
2552
+ */
2553
+ private getLazyLoadedRows;
2554
+ /**
2555
+ * Lazy load, with the counts after the filter: whether the row or group of a selection entry
2556
+ * is known to be filtered out - its parent has all the children loaded, and it's not among them
2557
+ */
2558
+ private isLazyEntryFilteredOut;
2559
+ /**
2560
+ * Lazy load: counts the explicit selection entries inside the group, at any depth, by their own selection,
2561
+ * whether their rows are loaded or not. The other rows of the group take its selection.
2562
+ */
2563
+ private getLazySelectionCountFor;
2521
2564
  getGroupCount(groupKeys: any[]): number;
2522
2565
  getGroupKeysDirectlyInsideGroup(groupKeys: any[]): any[][];
2523
2566
  getAllPrimaryKeysInsideGroup(groupKeys: any[]): any[];
@@ -3220,6 +3263,7 @@ type LazyRowInfoGroup<DataType> = {
3220
3263
  cache: boolean;
3221
3264
  totalCount: number;
3222
3265
  totalCountUnfiltered?: number;
3266
+ totalChildrenCount?: number;
3223
3267
  totalChildrenCountUnfiltered?: number;
3224
3268
  error?: string;
3225
3269
  };
package/index.dev.js CHANGED
@@ -316,6 +316,7 @@ var DeepMap = class _DeepMap {
316
316
  this.map = /* @__PURE__ */ new Map();
317
317
  this.length = 0;
318
318
  this.revision = 0;
319
+ this.mutations = 0;
319
320
  this.emptyKey = Symbol("emptyKey");
320
321
  this.visit = (fn) => {
321
322
  this.map.forEach((_, k) => this.visitKey(k, this.map, [], fn, false));
@@ -383,6 +384,12 @@ var DeepMap = class _DeepMap {
383
384
  };
384
385
  this.fill(initial);
385
386
  }
387
+ /**
388
+ * Increases on every set, delete and clear, so derived data can be cached until the map changes
389
+ */
390
+ get version() {
391
+ return this.mutations;
392
+ }
386
393
  static clone(map2) {
387
394
  const clone = new _DeepMap();
388
395
  map2.visit((pair, keys) => {
@@ -627,6 +634,7 @@ var DeepMap = class _DeepMap {
627
634
  }
628
635
  set(keys, value) {
629
636
  let currentMap = this.map;
637
+ this.mutations++;
630
638
  if (!keys.length) {
631
639
  keys = [this.emptyKey];
632
640
  }
@@ -688,9 +696,11 @@ var DeepMap = class _DeepMap {
688
696
  clearMap(this.map);
689
697
  this.length = 0;
690
698
  this.revision = 0;
699
+ this.mutations++;
691
700
  }
692
701
  delete(keys) {
693
702
  let currentMap = this.map;
703
+ this.mutations++;
694
704
  if (!keys.length) {
695
705
  keys = [this.emptyKey];
696
706
  } else {
@@ -15029,6 +15039,12 @@ function DEFAULT_TO_KEY(value) {
15029
15039
  return value;
15030
15040
  }
15031
15041
 
15042
+ // src/utils/groupAndPivot/notLoadedYet.ts
15043
+ var NOT_LOADED_YET_KEY_PREFIX = "____not_loaded_yet____";
15044
+ function isNotLoadedYetKey(key) {
15045
+ return typeof key === "string" && key.startsWith(NOT_LOADED_YET_KEY_PREFIX);
15046
+ }
15047
+
15032
15048
  // src/utils/groupAndPivot/sharedValueGetterParamsFlyweightObject.ts
15033
15049
  var sharedValueGetterParamsFlyweightObject = Object.seal({
15034
15050
  data: null,
@@ -15037,7 +15053,6 @@ var sharedValueGetterParamsFlyweightObject = Object.seal({
15037
15053
 
15038
15054
  // src/utils/groupAndPivot/index.ts
15039
15055
  var LAZY_ROOT_KEY_FOR_GROUPS = "____root____";
15040
- var NOT_LOADED_YET_KEY_PREFIX = "____not_loaded_yet____";
15041
15056
  function returnFalse() {
15042
15057
  return false;
15043
15058
  }
@@ -16794,6 +16809,15 @@ var RowSelectionState = class _RowSelectionState {
16794
16809
  // TODO make it easy to share the cache with another instance
16795
16810
  this.selectionCache = new DeepMap();
16796
16811
  this.selectionCountCache = new DeepMap();
16812
+ /**
16813
+ * Lazy load: the selected (true) and deselected (false) entries, in one map,
16814
+ * for the given versions of the selection maps
16815
+ */
16816
+ this.lazyEntries = null;
16817
+ // the caches below depend on the config, so they only live until the next xcache()
16818
+ this.lazyLoadedRows = null;
16819
+ this.lazyChildrenLoaded = null;
16820
+ this.lazyRowCounts = null;
16797
16821
  this.mapSet = (name, key) => {
16798
16822
  if (!Array.isArray(key)) {
16799
16823
  if (this.onlyUsePrimaryKeys) {
@@ -16914,6 +16938,174 @@ var RowSelectionState = class _RowSelectionState {
16914
16938
  });
16915
16939
  return Math.max(unfilteredCount - childrenCount, 0);
16916
16940
  }
16941
+ getLazyEntries() {
16942
+ const version = `${this.selectedMap.version}:${this.deselectedMap.version}`;
16943
+ if (this.lazyEntries?.version !== version) {
16944
+ const entries = new DeepMap();
16945
+ this.selectedMap.getKeysStartingWith([]).forEach((keys) => entries.set(keys, true));
16946
+ this.deselectedMap.getKeysStartingWith([]).forEach((keys) => entries.set(keys, false));
16947
+ this.lazyEntries = { version, entries };
16948
+ }
16949
+ return this.lazyEntries.entries;
16950
+ }
16951
+ /**
16952
+ * Lazy load: the count of the rows inside the group, as the server sent it
16953
+ */
16954
+ getLazyRowCount(groupKeys) {
16955
+ this.lazyRowCounts = this.lazyRowCounts ?? new DeepMap();
16956
+ const cached = this.lazyRowCounts.get(groupKeys);
16957
+ if (cached !== void 0) {
16958
+ return cached ?? void 0;
16959
+ }
16960
+ const result = this.computeLazyRowCount(groupKeys);
16961
+ this.lazyRowCounts.set(groupKeys, result ?? null);
16962
+ return result;
16963
+ }
16964
+ computeLazyRowCount(groupKeys) {
16965
+ const config = this.getConfig();
16966
+ const groupByLength = this.getGroupByLength();
16967
+ const unfilteredCount = this.getLazyUnfilteredCount(groupKeys);
16968
+ if (unfilteredCount !== void 0) {
16969
+ return unfilteredCount;
16970
+ }
16971
+ if (!groupKeys.length && !groupByLength) {
16972
+ return config.totalCount;
16973
+ }
16974
+ const group2 = groupKeys.length ? config.groupDeepMap?.get(groupKeys) : void 0;
16975
+ const count = groupKeys.length ? group2?.totalChildrenCount : config.lazyGroupedRowCount;
16976
+ if (count != null) {
16977
+ return count;
16978
+ }
16979
+ if (groupKeys.length === groupByLength) {
16980
+ return group2?.childrenAvailable ? group2.items.length : void 0;
16981
+ }
16982
+ const childKeys = config.groupDeepMap?.getKeysStartingWith(groupKeys, {
16983
+ excludeSelf: true,
16984
+ depthLimit: 1
16985
+ }) ?? [];
16986
+ if (!childKeys.length) {
16987
+ return void 0;
16988
+ }
16989
+ return childKeys.reduce(
16990
+ (sum2, keys) => sum2 + (isNotLoadedYetKey(keys[keys.length - 1]) ? 1 : this.getLazyRowCount(keys) ?? 1),
16991
+ 0
16992
+ );
16993
+ }
16994
+ /**
16995
+ * Lazy load: whether the server sent all the direct children of the group
16996
+ */
16997
+ areLazyChildrenLoaded(groupKeys) {
16998
+ this.lazyChildrenLoaded = this.lazyChildrenLoaded ?? new DeepMap();
16999
+ const cached = this.lazyChildrenLoaded.get(groupKeys);
17000
+ if (cached !== void 0) {
17001
+ return cached;
17002
+ }
17003
+ const result = this.computeLazyChildrenLoaded(groupKeys);
17004
+ this.lazyChildrenLoaded.set(groupKeys, result);
17005
+ return result;
17006
+ }
17007
+ computeLazyChildrenLoaded(groupKeys) {
17008
+ const { groupDeepMap } = this.getConfig();
17009
+ const group2 = groupKeys.length ? groupDeepMap?.get(groupKeys) : void 0;
17010
+ if (groupKeys.length && !group2?.childrenAvailable) {
17011
+ return false;
17012
+ }
17013
+ if (groupKeys.length === this.getGroupByLength()) {
17014
+ return this.getLazyLoadedRows(groupKeys).complete;
17015
+ }
17016
+ return (groupDeepMap?.getKeysStartingWith(groupKeys, {
17017
+ excludeSelf: true,
17018
+ depthLimit: 1
17019
+ }) ?? []).every((keys) => !isNotLoadedYetKey(keys[keys.length - 1]));
17020
+ }
17021
+ /**
17022
+ * Lazy load, at the last group level (or the root, without grouping): the primary keys
17023
+ * of the loaded rows, and whether they are all the rows of the group
17024
+ */
17025
+ getLazyLoadedRows(groupKeys) {
17026
+ this.lazyLoadedRows = this.lazyLoadedRows ?? new DeepMap();
17027
+ let loadedRows = this.lazyLoadedRows.get(groupKeys);
17028
+ if (!loadedRows) {
17029
+ const { groupDeepMap, originalDataArray, toPrimaryKey, totalCount } = this.getConfig();
17030
+ const group2 = groupKeys.length ? groupDeepMap?.get(groupKeys) : void 0;
17031
+ const items = group2 ? group2.items : originalDataArray ?? [];
17032
+ const rowCount = group2 ? group2.totalChildrenCount : totalCount;
17033
+ const primaryKeys = /* @__PURE__ */ new Set();
17034
+ let complete = rowCount == null || items.length >= rowCount;
17035
+ for (let i = 0; i < items.length; i++) {
17036
+ const item = items[i];
17037
+ if (item == null) {
17038
+ complete = false;
17039
+ } else {
17040
+ primaryKeys.add(toPrimaryKey(item));
17041
+ }
17042
+ }
17043
+ loadedRows = { primaryKeys, complete };
17044
+ this.lazyLoadedRows.set(groupKeys, loadedRows);
17045
+ }
17046
+ return loadedRows;
17047
+ }
17048
+ /**
17049
+ * Lazy load, with the counts after the filter: whether the row or group of a selection entry
17050
+ * is known to be filtered out - its parent has all the children loaded, and it's not among them
17051
+ */
17052
+ isLazyEntryFilteredOut(keys) {
17053
+ const { groupDeepMap } = this.getConfig();
17054
+ const groupByLength = this.getGroupByLength();
17055
+ for (let length = 1; length <= keys.length; length++) {
17056
+ const parentKeys = keys.slice(0, length - 1);
17057
+ const loaded = length > groupByLength ? this.getLazyLoadedRows(parentKeys).primaryKeys.has(keys[length - 1]) : !!groupDeepMap?.get(keys.slice(0, length));
17058
+ if (!loaded) {
17059
+ return this.areLazyChildrenLoaded(parentKeys);
17060
+ }
17061
+ }
17062
+ return false;
17063
+ }
17064
+ /**
17065
+ * Lazy load: counts the explicit selection entries inside the group, at any depth, by their own selection,
17066
+ * whether their rows are loaded or not. The other rows of the group take its selection.
17067
+ */
17068
+ getLazySelectionCountFor(groupKeys, selected) {
17069
+ const cachedResult = this.selectionCountCache.get(groupKeys);
17070
+ if (cachedResult != null) {
17071
+ return cachedResult;
17072
+ }
17073
+ const entries = this.getLazyEntries();
17074
+ const leafLength = this.getGroupByLength() + 1;
17075
+ const countsIncludeFilteredOutRows = this.getLazyUnfilteredCount([]) !== void 0;
17076
+ let selectedCount = 0;
17077
+ let deselectedCount = 0;
17078
+ entries.getKeysOfFirstChildOnEachBranchStartingWith(groupKeys, {
17079
+ excludeSelf: true,
17080
+ respectOrder: false
17081
+ }).forEach((keys) => {
17082
+ if (!countsIncludeFilteredOutRows && this.isLazyEntryFilteredOut(keys)) {
17083
+ return;
17084
+ }
17085
+ const entrySelected = entries.get(keys);
17086
+ if (keys.length >= leafLength) {
17087
+ if (entrySelected) {
17088
+ selectedCount++;
17089
+ } else {
17090
+ deselectedCount++;
17091
+ }
17092
+ return;
17093
+ }
17094
+ const count = this.getLazySelectionCountFor(keys, entrySelected);
17095
+ selectedCount += count.selectedCount;
17096
+ deselectedCount += count.deselectedCount;
17097
+ });
17098
+ const rowCount = this.getLazyRowCount(groupKeys);
17099
+ const otherRowsCount = rowCount === void 0 ? 1 : Math.max(rowCount - selectedCount - deselectedCount, 0);
17100
+ if (selected) {
17101
+ selectedCount += otherRowsCount;
17102
+ } else {
17103
+ deselectedCount += otherRowsCount;
17104
+ }
17105
+ const result = { selectedCount, deselectedCount };
17106
+ this.selectionCountCache.set(groupKeys, result);
17107
+ return result;
17108
+ }
16917
17109
  getGroupCount(groupKeys) {
16918
17110
  if (groupKeys.length == 0) {
16919
17111
  return this.getLazyUnfilteredCount([]) ?? this.getConfig().totalCount;
@@ -16980,6 +17172,9 @@ var RowSelectionState = class _RowSelectionState {
16980
17172
  xcache() {
16981
17173
  this.selectionCache.clear();
16982
17174
  this.selectionCountCache.clear();
17175
+ this.lazyLoadedRows = null;
17176
+ this.lazyChildrenLoaded = null;
17177
+ this.lazyRowCounts = null;
16983
17178
  }
16984
17179
  getState() {
16985
17180
  const normalize = (allKeys) => {
@@ -17311,6 +17506,12 @@ var RowSelectionState = class _RowSelectionState {
17311
17506
  this.selectionCountCache.set(groupKeys, result2);
17312
17507
  return result2;
17313
17508
  }
17509
+ if (this.getConfig().lazyLoad && (!this.onlyUsePrimaryKeys || !groupByLength)) {
17510
+ return this.getLazySelectionCountFor(
17511
+ groupKeys,
17512
+ parentSelected ?? this.getGroupRowBooleanSelectionStateFromParent(groupKeys)
17513
+ );
17514
+ }
17314
17515
  if (this.onlyUsePrimaryKeys && (groupByLength || this.targetsVisibleRowsOnly())) {
17315
17516
  const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
17316
17517
  let selectedCount2 = 0;
@@ -17375,23 +17576,6 @@ var RowSelectionState = class _RowSelectionState {
17375
17576
  }
17376
17577
  let selectedCount = 0;
17377
17578
  let deselectedCount = 0;
17378
- const { lazyLoad, groupDeepMap } = this.getConfig();
17379
- if (lazyLoad && !allKeys.length) {
17380
- const totalChildrenCount = this.getLazyUnfilteredCount(groupKeys) ?? (groupDeepMap?.get(groupKeys)?.totalChildrenCount || 0);
17381
- if (parentSelected) {
17382
- selectedCount = totalChildrenCount;
17383
- deselectedCount = this.deselectedMap.getAllChildrenSizeFor(groupKeys);
17384
- if (deselectedCount === totalChildrenCount) {
17385
- selectedCount = 0;
17386
- }
17387
- } else {
17388
- deselectedCount = totalChildrenCount;
17389
- selectedCount = this.selectedMap.getAllChildrenSizeFor(groupKeys);
17390
- if (selectedCount === totalChildrenCount) {
17391
- deselectedCount = 0;
17392
- }
17393
- }
17394
- }
17395
17579
  allKeys.forEach((keys) => {
17396
17580
  let isSelected = this.selectedMap.get(keys);
17397
17581
  let isDeselected = this.deselectedMap.get(keys);
@@ -17400,12 +17584,6 @@ var RowSelectionState = class _RowSelectionState {
17400
17584
  selectedCount += selCount;
17401
17585
  deselectedCount += deselCount;
17402
17586
  });
17403
- const hiddenCount = allKeys.length ? this.getLazyHiddenRowsCount(groupKeys) : 0;
17404
- if (parentSelected) {
17405
- selectedCount += hiddenCount;
17406
- } else {
17407
- deselectedCount += hiddenCount;
17408
- }
17409
17587
  const result = {
17410
17588
  selectedCount,
17411
17589
  deselectedCount
@@ -17436,6 +17614,7 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
17436
17614
  groupDeepMap: state.groupDeepMap,
17437
17615
  indexer: state.indexer,
17438
17616
  totalCount: lazyLoad ? originalDataArray?.length ?? 0 : state.unfilteredCount,
17617
+ lazyGroupedRowCount: state.groupBy.length ? lazyRoot?.totalChildrenCount : void 0,
17439
17618
  lazyUnfilteredCount: state.groupBy.length ? lazyRoot?.totalChildrenCountUnfiltered : lazyRoot?.totalCountUnfiltered,
17440
17619
  multiRowSelectionTarget: state.multiRowSelectionTarget,
17441
17620
  someRowsFilteredOut: !state.lazyLoad && !!originalDataArray && !!postFilterDataArray && postFilterDataArray.length < originalDataArray.length,
@@ -21621,6 +21800,24 @@ var haveDepsChanged = (state1, state2, deps) => {
21621
21800
  }
21622
21801
  return false;
21623
21802
  };
21803
+ function getLazyGroupedRowCount(lazyGroupData) {
21804
+ const root = lazyGroupData.get([LAZY_ROOT_KEY_FOR_GROUPS]);
21805
+ if (!root) {
21806
+ return void 0;
21807
+ }
21808
+ if (root.totalChildrenCount != null) {
21809
+ return root.totalChildrenCount;
21810
+ }
21811
+ let count = 0;
21812
+ for (let i = 0; i < root.children.length; i++) {
21813
+ const groupCount = root.children[i]?.totalChildrenCount;
21814
+ if (groupCount == null) {
21815
+ return void 0;
21816
+ }
21817
+ count += groupCount;
21818
+ }
21819
+ return count;
21820
+ }
21624
21821
  function returnFalse2() {
21625
21822
  return false;
21626
21823
  }
@@ -22001,7 +22198,7 @@ function concludeReducer(params) {
22001
22198
  state.lastFilterDataArray = dataArray;
22002
22199
  state.filteredAt = now;
22003
22200
  }
22004
- state.filteredCount = dataArray.length;
22201
+ state.filteredCount = (state.lazyLoad && groupBy.length ? getLazyGroupedRowCount(state.originalLazyGroupData) : void 0) ?? dataArray.length;
22005
22202
  state.postFilterDataArray = dataArray;
22006
22203
  if (shouldSort) {
22007
22204
  const prevKnownTypes = multisort.knownTypes;
@@ -22331,7 +22528,8 @@ function concludeReducer(params) {
22331
22528
  state.dataArray = rowInfoDataArray;
22332
22529
  state.reducedAt = now;
22333
22530
  if (state.selectionMode === "multi-row") {
22334
- if (shouldGroup && state.lazyLoad) {
22531
+ const groupKeysSelection = state.rowSelection instanceof RowSelectionState && !state.rowSelection.onlyUsePrimaryKeys;
22532
+ if (shouldGroup && state.lazyLoad && !groupKeysSelection) {
22335
22533
  if (debugId) {
22336
22534
  marker = getMarker(
22337
22535
  debugId
@@ -22599,6 +22797,7 @@ function loadData(data, componentState, actions, overrides, masterContext) {
22599
22797
  totalCount: remoteData2.totalCount ?? dataArray2.length,
22600
22798
  // set even when missing, so a previous response's values are not kept
22601
22799
  totalCountUnfiltered: remoteData2.totalCountUnfiltered,
22800
+ totalChildrenCount: remoteData2.totalChildrenCount,
22602
22801
  totalChildrenCountUnfiltered: remoteData2.totalChildrenCountUnfiltered,
22603
22802
  children: dataArray2,
22604
22803
  error: remoteData2.error
@@ -28159,7 +28358,7 @@ var useLicense = (licenseKey = "") => {
28159
28358
  }
28160
28359
  let valid2 = isValidLicense(licenseKey, {
28161
28360
  publishedAt: 1624970570587,
28162
- version: "9.4.0"
28361
+ version: "9.4.1"
28163
28362
  });
28164
28363
  if (!licenseKey && !valid2 && isInsidePlayground) {
28165
28364
  return true;