@infinite-table/infinite-react 9.3.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.dev.mjs CHANGED
@@ -235,6 +235,7 @@ var DeepMap = class _DeepMap {
235
235
  this.map = /* @__PURE__ */ new Map();
236
236
  this.length = 0;
237
237
  this.revision = 0;
238
+ this.mutations = 0;
238
239
  this.emptyKey = Symbol("emptyKey");
239
240
  this.visit = (fn) => {
240
241
  this.map.forEach((_, k) => this.visitKey(k, this.map, [], fn, false));
@@ -302,6 +303,12 @@ var DeepMap = class _DeepMap {
302
303
  };
303
304
  this.fill(initial);
304
305
  }
306
+ /**
307
+ * Increases on every set, delete and clear, so derived data can be cached until the map changes
308
+ */
309
+ get version() {
310
+ return this.mutations;
311
+ }
305
312
  static clone(map2) {
306
313
  const clone = new _DeepMap();
307
314
  map2.visit((pair, keys) => {
@@ -546,6 +553,7 @@ var DeepMap = class _DeepMap {
546
553
  }
547
554
  set(keys, value) {
548
555
  let currentMap = this.map;
556
+ this.mutations++;
549
557
  if (!keys.length) {
550
558
  keys = [this.emptyKey];
551
559
  }
@@ -607,9 +615,11 @@ var DeepMap = class _DeepMap {
607
615
  clearMap(this.map);
608
616
  this.length = 0;
609
617
  this.revision = 0;
618
+ this.mutations++;
610
619
  }
611
620
  delete(keys) {
612
621
  let currentMap = this.map;
622
+ this.mutations++;
613
623
  if (!keys.length) {
614
624
  keys = [this.emptyKey];
615
625
  } else {
@@ -14963,6 +14973,12 @@ function DEFAULT_TO_KEY(value) {
14963
14973
  return value;
14964
14974
  }
14965
14975
 
14976
+ // src/utils/groupAndPivot/notLoadedYet.ts
14977
+ var NOT_LOADED_YET_KEY_PREFIX = "____not_loaded_yet____";
14978
+ function isNotLoadedYetKey(key) {
14979
+ return typeof key === "string" && key.startsWith(NOT_LOADED_YET_KEY_PREFIX);
14980
+ }
14981
+
14966
14982
  // src/utils/groupAndPivot/sharedValueGetterParamsFlyweightObject.ts
14967
14983
  var sharedValueGetterParamsFlyweightObject = Object.seal({
14968
14984
  data: null,
@@ -14971,7 +14987,6 @@ var sharedValueGetterParamsFlyweightObject = Object.seal({
14971
14987
 
14972
14988
  // src/utils/groupAndPivot/index.ts
14973
14989
  var LAZY_ROOT_KEY_FOR_GROUPS = "____root____";
14974
- var NOT_LOADED_YET_KEY_PREFIX = "____not_loaded_yet____";
14975
14990
  function returnFalse() {
14976
14991
  return false;
14977
14992
  }
@@ -16728,6 +16743,15 @@ var RowSelectionState = class _RowSelectionState {
16728
16743
  // TODO make it easy to share the cache with another instance
16729
16744
  this.selectionCache = new DeepMap();
16730
16745
  this.selectionCountCache = new DeepMap();
16746
+ /**
16747
+ * Lazy load: the selected (true) and deselected (false) entries, in one map,
16748
+ * for the given versions of the selection maps
16749
+ */
16750
+ this.lazyEntries = null;
16751
+ // the caches below depend on the config, so they only live until the next xcache()
16752
+ this.lazyLoadedRows = null;
16753
+ this.lazyChildrenLoaded = null;
16754
+ this.lazyRowCounts = null;
16731
16755
  this.mapSet = (name, key) => {
16732
16756
  if (!Array.isArray(key)) {
16733
16757
  if (this.onlyUsePrimaryKeys) {
@@ -16848,6 +16872,174 @@ var RowSelectionState = class _RowSelectionState {
16848
16872
  });
16849
16873
  return Math.max(unfilteredCount - childrenCount, 0);
16850
16874
  }
16875
+ getLazyEntries() {
16876
+ const version = `${this.selectedMap.version}:${this.deselectedMap.version}`;
16877
+ if (this.lazyEntries?.version !== version) {
16878
+ const entries = new DeepMap();
16879
+ this.selectedMap.getKeysStartingWith([]).forEach((keys) => entries.set(keys, true));
16880
+ this.deselectedMap.getKeysStartingWith([]).forEach((keys) => entries.set(keys, false));
16881
+ this.lazyEntries = { version, entries };
16882
+ }
16883
+ return this.lazyEntries.entries;
16884
+ }
16885
+ /**
16886
+ * Lazy load: the count of the rows inside the group, as the server sent it
16887
+ */
16888
+ getLazyRowCount(groupKeys) {
16889
+ this.lazyRowCounts = this.lazyRowCounts ?? new DeepMap();
16890
+ const cached = this.lazyRowCounts.get(groupKeys);
16891
+ if (cached !== void 0) {
16892
+ return cached ?? void 0;
16893
+ }
16894
+ const result = this.computeLazyRowCount(groupKeys);
16895
+ this.lazyRowCounts.set(groupKeys, result ?? null);
16896
+ return result;
16897
+ }
16898
+ computeLazyRowCount(groupKeys) {
16899
+ const config = this.getConfig();
16900
+ const groupByLength = this.getGroupByLength();
16901
+ const unfilteredCount = this.getLazyUnfilteredCount(groupKeys);
16902
+ if (unfilteredCount !== void 0) {
16903
+ return unfilteredCount;
16904
+ }
16905
+ if (!groupKeys.length && !groupByLength) {
16906
+ return config.totalCount;
16907
+ }
16908
+ const group2 = groupKeys.length ? config.groupDeepMap?.get(groupKeys) : void 0;
16909
+ const count = groupKeys.length ? group2?.totalChildrenCount : config.lazyGroupedRowCount;
16910
+ if (count != null) {
16911
+ return count;
16912
+ }
16913
+ if (groupKeys.length === groupByLength) {
16914
+ return group2?.childrenAvailable ? group2.items.length : void 0;
16915
+ }
16916
+ const childKeys = config.groupDeepMap?.getKeysStartingWith(groupKeys, {
16917
+ excludeSelf: true,
16918
+ depthLimit: 1
16919
+ }) ?? [];
16920
+ if (!childKeys.length) {
16921
+ return void 0;
16922
+ }
16923
+ return childKeys.reduce(
16924
+ (sum2, keys) => sum2 + (isNotLoadedYetKey(keys[keys.length - 1]) ? 1 : this.getLazyRowCount(keys) ?? 1),
16925
+ 0
16926
+ );
16927
+ }
16928
+ /**
16929
+ * Lazy load: whether the server sent all the direct children of the group
16930
+ */
16931
+ areLazyChildrenLoaded(groupKeys) {
16932
+ this.lazyChildrenLoaded = this.lazyChildrenLoaded ?? new DeepMap();
16933
+ const cached = this.lazyChildrenLoaded.get(groupKeys);
16934
+ if (cached !== void 0) {
16935
+ return cached;
16936
+ }
16937
+ const result = this.computeLazyChildrenLoaded(groupKeys);
16938
+ this.lazyChildrenLoaded.set(groupKeys, result);
16939
+ return result;
16940
+ }
16941
+ computeLazyChildrenLoaded(groupKeys) {
16942
+ const { groupDeepMap } = this.getConfig();
16943
+ const group2 = groupKeys.length ? groupDeepMap?.get(groupKeys) : void 0;
16944
+ if (groupKeys.length && !group2?.childrenAvailable) {
16945
+ return false;
16946
+ }
16947
+ if (groupKeys.length === this.getGroupByLength()) {
16948
+ return this.getLazyLoadedRows(groupKeys).complete;
16949
+ }
16950
+ return (groupDeepMap?.getKeysStartingWith(groupKeys, {
16951
+ excludeSelf: true,
16952
+ depthLimit: 1
16953
+ }) ?? []).every((keys) => !isNotLoadedYetKey(keys[keys.length - 1]));
16954
+ }
16955
+ /**
16956
+ * Lazy load, at the last group level (or the root, without grouping): the primary keys
16957
+ * of the loaded rows, and whether they are all the rows of the group
16958
+ */
16959
+ getLazyLoadedRows(groupKeys) {
16960
+ this.lazyLoadedRows = this.lazyLoadedRows ?? new DeepMap();
16961
+ let loadedRows = this.lazyLoadedRows.get(groupKeys);
16962
+ if (!loadedRows) {
16963
+ const { groupDeepMap, originalDataArray, toPrimaryKey, totalCount } = this.getConfig();
16964
+ const group2 = groupKeys.length ? groupDeepMap?.get(groupKeys) : void 0;
16965
+ const items = group2 ? group2.items : originalDataArray ?? [];
16966
+ const rowCount = group2 ? group2.totalChildrenCount : totalCount;
16967
+ const primaryKeys = /* @__PURE__ */ new Set();
16968
+ let complete = rowCount == null || items.length >= rowCount;
16969
+ for (let i = 0; i < items.length; i++) {
16970
+ const item = items[i];
16971
+ if (item == null) {
16972
+ complete = false;
16973
+ } else {
16974
+ primaryKeys.add(toPrimaryKey(item));
16975
+ }
16976
+ }
16977
+ loadedRows = { primaryKeys, complete };
16978
+ this.lazyLoadedRows.set(groupKeys, loadedRows);
16979
+ }
16980
+ return loadedRows;
16981
+ }
16982
+ /**
16983
+ * Lazy load, with the counts after the filter: whether the row or group of a selection entry
16984
+ * is known to be filtered out - its parent has all the children loaded, and it's not among them
16985
+ */
16986
+ isLazyEntryFilteredOut(keys) {
16987
+ const { groupDeepMap } = this.getConfig();
16988
+ const groupByLength = this.getGroupByLength();
16989
+ for (let length = 1; length <= keys.length; length++) {
16990
+ const parentKeys = keys.slice(0, length - 1);
16991
+ const loaded = length > groupByLength ? this.getLazyLoadedRows(parentKeys).primaryKeys.has(keys[length - 1]) : !!groupDeepMap?.get(keys.slice(0, length));
16992
+ if (!loaded) {
16993
+ return this.areLazyChildrenLoaded(parentKeys);
16994
+ }
16995
+ }
16996
+ return false;
16997
+ }
16998
+ /**
16999
+ * Lazy load: counts the explicit selection entries inside the group, at any depth, by their own selection,
17000
+ * whether their rows are loaded or not. The other rows of the group take its selection.
17001
+ */
17002
+ getLazySelectionCountFor(groupKeys, selected) {
17003
+ const cachedResult = this.selectionCountCache.get(groupKeys);
17004
+ if (cachedResult != null) {
17005
+ return cachedResult;
17006
+ }
17007
+ const entries = this.getLazyEntries();
17008
+ const leafLength = this.getGroupByLength() + 1;
17009
+ const countsIncludeFilteredOutRows = this.getLazyUnfilteredCount([]) !== void 0;
17010
+ let selectedCount = 0;
17011
+ let deselectedCount = 0;
17012
+ entries.getKeysOfFirstChildOnEachBranchStartingWith(groupKeys, {
17013
+ excludeSelf: true,
17014
+ respectOrder: false
17015
+ }).forEach((keys) => {
17016
+ if (!countsIncludeFilteredOutRows && this.isLazyEntryFilteredOut(keys)) {
17017
+ return;
17018
+ }
17019
+ const entrySelected = entries.get(keys);
17020
+ if (keys.length >= leafLength) {
17021
+ if (entrySelected) {
17022
+ selectedCount++;
17023
+ } else {
17024
+ deselectedCount++;
17025
+ }
17026
+ return;
17027
+ }
17028
+ const count = this.getLazySelectionCountFor(keys, entrySelected);
17029
+ selectedCount += count.selectedCount;
17030
+ deselectedCount += count.deselectedCount;
17031
+ });
17032
+ const rowCount = this.getLazyRowCount(groupKeys);
17033
+ const otherRowsCount = rowCount === void 0 ? 1 : Math.max(rowCount - selectedCount - deselectedCount, 0);
17034
+ if (selected) {
17035
+ selectedCount += otherRowsCount;
17036
+ } else {
17037
+ deselectedCount += otherRowsCount;
17038
+ }
17039
+ const result = { selectedCount, deselectedCount };
17040
+ this.selectionCountCache.set(groupKeys, result);
17041
+ return result;
17042
+ }
16851
17043
  getGroupCount(groupKeys) {
16852
17044
  if (groupKeys.length == 0) {
16853
17045
  return this.getLazyUnfilteredCount([]) ?? this.getConfig().totalCount;
@@ -16914,6 +17106,9 @@ var RowSelectionState = class _RowSelectionState {
16914
17106
  xcache() {
16915
17107
  this.selectionCache.clear();
16916
17108
  this.selectionCountCache.clear();
17109
+ this.lazyLoadedRows = null;
17110
+ this.lazyChildrenLoaded = null;
17111
+ this.lazyRowCounts = null;
16917
17112
  }
16918
17113
  getState() {
16919
17114
  const normalize = (allKeys) => {
@@ -17245,6 +17440,12 @@ var RowSelectionState = class _RowSelectionState {
17245
17440
  this.selectionCountCache.set(groupKeys, result2);
17246
17441
  return result2;
17247
17442
  }
17443
+ if (this.getConfig().lazyLoad && (!this.onlyUsePrimaryKeys || !groupByLength)) {
17444
+ return this.getLazySelectionCountFor(
17445
+ groupKeys,
17446
+ parentSelected ?? this.getGroupRowBooleanSelectionStateFromParent(groupKeys)
17447
+ );
17448
+ }
17248
17449
  if (this.onlyUsePrimaryKeys && (groupByLength || this.targetsVisibleRowsOnly())) {
17249
17450
  const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
17250
17451
  let selectedCount2 = 0;
@@ -17309,23 +17510,6 @@ var RowSelectionState = class _RowSelectionState {
17309
17510
  }
17310
17511
  let selectedCount = 0;
17311
17512
  let deselectedCount = 0;
17312
- const { lazyLoad, groupDeepMap } = this.getConfig();
17313
- if (lazyLoad && !allKeys.length) {
17314
- const totalChildrenCount = this.getLazyUnfilteredCount(groupKeys) ?? (groupDeepMap?.get(groupKeys)?.totalChildrenCount || 0);
17315
- if (parentSelected) {
17316
- selectedCount = totalChildrenCount;
17317
- deselectedCount = this.deselectedMap.getAllChildrenSizeFor(groupKeys);
17318
- if (deselectedCount === totalChildrenCount) {
17319
- selectedCount = 0;
17320
- }
17321
- } else {
17322
- deselectedCount = totalChildrenCount;
17323
- selectedCount = this.selectedMap.getAllChildrenSizeFor(groupKeys);
17324
- if (selectedCount === totalChildrenCount) {
17325
- deselectedCount = 0;
17326
- }
17327
- }
17328
- }
17329
17513
  allKeys.forEach((keys) => {
17330
17514
  let isSelected = this.selectedMap.get(keys);
17331
17515
  let isDeselected = this.deselectedMap.get(keys);
@@ -17334,12 +17518,6 @@ var RowSelectionState = class _RowSelectionState {
17334
17518
  selectedCount += selCount;
17335
17519
  deselectedCount += deselCount;
17336
17520
  });
17337
- const hiddenCount = allKeys.length ? this.getLazyHiddenRowsCount(groupKeys) : 0;
17338
- if (parentSelected) {
17339
- selectedCount += hiddenCount;
17340
- } else {
17341
- deselectedCount += hiddenCount;
17342
- }
17343
17521
  const result = {
17344
17522
  selectedCount,
17345
17523
  deselectedCount
@@ -17370,6 +17548,7 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
17370
17548
  groupDeepMap: state.groupDeepMap,
17371
17549
  indexer: state.indexer,
17372
17550
  totalCount: lazyLoad ? originalDataArray?.length ?? 0 : state.unfilteredCount,
17551
+ lazyGroupedRowCount: state.groupBy.length ? lazyRoot?.totalChildrenCount : void 0,
17373
17552
  lazyUnfilteredCount: state.groupBy.length ? lazyRoot?.totalChildrenCountUnfiltered : lazyRoot?.totalCountUnfiltered,
17374
17553
  multiRowSelectionTarget: state.multiRowSelectionTarget,
17375
17554
  someRowsFilteredOut: !state.lazyLoad && !!originalDataArray && !!postFilterDataArray && postFilterDataArray.length < originalDataArray.length,
@@ -21068,10 +21247,11 @@ function deriveStateFromProps(params) {
21068
21247
  state.logger
21069
21248
  );
21070
21249
  }
21071
- const groupMode = typeof props.data === "function" ? propsGroupMode ?? "local" : "local";
21250
+ const remoteByDefault = typeof props.data === "function" && !!props.lazyLoad;
21251
+ const groupMode = typeof props.data === "function" ? propsGroupMode ?? (remoteByDefault ? "remote" : "local") : "local";
21072
21252
  const sortMode = props.sortFunction ? "local" : propsSortMode ?? (controlledSort ? "remote" : "local");
21073
21253
  const filterMode = typeof props.filterFunction === "function" || typeof props.treeFilterFunction === "function" ? "local" : propsFilterMode ?? (typeof props.data === "function" ? "remote" : "local");
21074
- const pivotMode = shouldReloadData.pivotBy ? "remote" : "local";
21254
+ const pivotMode = shouldReloadData.pivotBy ?? remoteByDefault ? "remote" : "local";
21075
21255
  const rowDisabledState = state.rowDisabledState;
21076
21256
  let isRowDisabled = props.isRowDisabled;
21077
21257
  if (!isRowDisabled && rowDisabledState) {
@@ -21554,6 +21734,24 @@ var haveDepsChanged = (state1, state2, deps) => {
21554
21734
  }
21555
21735
  return false;
21556
21736
  };
21737
+ function getLazyGroupedRowCount(lazyGroupData) {
21738
+ const root = lazyGroupData.get([LAZY_ROOT_KEY_FOR_GROUPS]);
21739
+ if (!root) {
21740
+ return void 0;
21741
+ }
21742
+ if (root.totalChildrenCount != null) {
21743
+ return root.totalChildrenCount;
21744
+ }
21745
+ let count = 0;
21746
+ for (let i = 0; i < root.children.length; i++) {
21747
+ const groupCount = root.children[i]?.totalChildrenCount;
21748
+ if (groupCount == null) {
21749
+ return void 0;
21750
+ }
21751
+ count += groupCount;
21752
+ }
21753
+ return count;
21754
+ }
21557
21755
  function returnFalse2() {
21558
21756
  return false;
21559
21757
  }
@@ -21934,7 +22132,7 @@ function concludeReducer(params) {
21934
22132
  state.lastFilterDataArray = dataArray;
21935
22133
  state.filteredAt = now;
21936
22134
  }
21937
- state.filteredCount = dataArray.length;
22135
+ state.filteredCount = (state.lazyLoad && groupBy.length ? getLazyGroupedRowCount(state.originalLazyGroupData) : void 0) ?? dataArray.length;
21938
22136
  state.postFilterDataArray = dataArray;
21939
22137
  if (shouldSort) {
21940
22138
  const prevKnownTypes = multisort.knownTypes;
@@ -22264,7 +22462,8 @@ function concludeReducer(params) {
22264
22462
  state.dataArray = rowInfoDataArray;
22265
22463
  state.reducedAt = now;
22266
22464
  if (state.selectionMode === "multi-row") {
22267
- if (shouldGroup && state.lazyLoad) {
22465
+ const groupKeysSelection = state.rowSelection instanceof RowSelectionState && !state.rowSelection.onlyUsePrimaryKeys;
22466
+ if (shouldGroup && state.lazyLoad && !groupKeysSelection) {
22268
22467
  if (debugId) {
22269
22468
  marker = getMarker(
22270
22469
  debugId
@@ -22532,6 +22731,7 @@ function loadData(data, componentState, actions, overrides, masterContext) {
22532
22731
  totalCount: remoteData2.totalCount ?? dataArray2.length,
22533
22732
  // set even when missing, so a previous response's values are not kept
22534
22733
  totalCountUnfiltered: remoteData2.totalCountUnfiltered,
22734
+ totalChildrenCount: remoteData2.totalChildrenCount,
22535
22735
  totalChildrenCountUnfiltered: remoteData2.totalChildrenCountUnfiltered,
22536
22736
  children: dataArray2,
22537
22737
  error: remoteData2.error
@@ -28097,7 +28297,7 @@ var useLicense = (licenseKey = "") => {
28097
28297
  }
28098
28298
  let valid2 = isValidLicense(licenseKey, {
28099
28299
  publishedAt: 1624970570587,
28100
- version: "9.3.0"
28300
+ version: "9.4.1"
28101
28301
  });
28102
28302
  if (!licenseKey && !valid2 && isInsidePlayground) {
28103
28303
  return true;