@infinite-table/infinite-react 9.1.5 → 9.2.0

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
@@ -16670,6 +16670,52 @@ function getGroupKeysForDataItem(data, groupBy) {
16670
16670
  }
16671
16671
 
16672
16672
  // src/components/DataSource/RowSelectionState.ts
16673
+ var EMPTY_UNFILTERED_GROUPS = new DeepMap();
16674
+ var unfilteredGroupsCache = /* @__PURE__ */ new WeakMap();
16675
+ function getUnfilteredGroups(config) {
16676
+ const { originalDataArray, groupBy, toPrimaryKey } = config;
16677
+ if (!originalDataArray || !groupBy.length) {
16678
+ return EMPTY_UNFILTERED_GROUPS;
16679
+ }
16680
+ const cached = unfilteredGroupsCache.get(originalDataArray);
16681
+ if (cached && cached.groupBy === groupBy) {
16682
+ return cached.groups;
16683
+ }
16684
+ const groups = new DeepMap();
16685
+ const lastLevel = groupBy.length;
16686
+ const keys = [];
16687
+ originalDataArray.forEach((data) => {
16688
+ const groupKeys = getGroupKeysForDataItem(data, groupBy);
16689
+ keys.length = 0;
16690
+ for (let i = 0; i < groupKeys.length; i++) {
16691
+ keys.push(groupKeys[i]);
16692
+ let group2 = groups.get(keys);
16693
+ if (!group2) {
16694
+ group2 = { count: 0 };
16695
+ if (keys.length === lastLevel) {
16696
+ group2.primaryKeys = [];
16697
+ }
16698
+ groups.set(keys, group2);
16699
+ }
16700
+ group2.count++;
16701
+ group2.primaryKeys?.push(toPrimaryKey(data));
16702
+ }
16703
+ });
16704
+ unfilteredGroupsCache.set(originalDataArray, { groupBy, groups });
16705
+ return groups;
16706
+ }
16707
+ function getUnfilteredPrimaryKeysInsideGroup(groups, groupKeys) {
16708
+ const result = [];
16709
+ groups.getLeafNodesStartingWith(groupKeys, (pair) => {
16710
+ const primaryKeys = pair.value?.primaryKeys;
16711
+ if (primaryKeys) {
16712
+ for (let i = 0; i < primaryKeys.length; i++) {
16713
+ result.push(primaryKeys[i]);
16714
+ }
16715
+ }
16716
+ });
16717
+ return result;
16718
+ }
16673
16719
  var RowSelectionState = class _RowSelectionState {
16674
16720
  constructor(state, getConfig, _forTestingOnly) {
16675
16721
  this.selectedRows = null;
@@ -16721,10 +16767,62 @@ var RowSelectionState = class _RowSelectionState {
16721
16767
  getGroupDeepMap() {
16722
16768
  return this.getConfig().groupDeepMap;
16723
16769
  }
16770
+ /**
16771
+ * The selection acts only on the rows that pass the filter, and some rows are filtered out
16772
+ */
16773
+ targetsVisibleRowsOnly() {
16774
+ const { multiRowSelectionTarget, someRowsFilteredOut } = this.getConfig();
16775
+ return multiRowSelectionTarget === "visible" && !!someRowsFilteredOut;
16776
+ }
16777
+ /**
16778
+ * The selection also acts on rows that are filtered out, and some rows are filtered out
16779
+ */
16780
+ targetsFilteredOutRows() {
16781
+ const { multiRowSelectionTarget, someRowsFilteredOut } = this.getConfig();
16782
+ return multiRowSelectionTarget !== "visible" && !!someRowsFilteredOut;
16783
+ }
16784
+ getVisibleDataInsideGroup(groupKeys) {
16785
+ const { postFilterDataArray, groupDeepMap } = this.getConfig();
16786
+ if (!groupKeys.length) {
16787
+ return postFilterDataArray ?? [];
16788
+ }
16789
+ return groupDeepMap?.get(groupKeys)?.items ?? [];
16790
+ }
16791
+ hasFilteredOutRowsInsideGroup(groupKeys) {
16792
+ const config = this.getConfig();
16793
+ if (!config.someRowsFilteredOut) {
16794
+ return false;
16795
+ }
16796
+ const allCount = groupKeys.length ? getUnfilteredGroups(config).get(groupKeys)?.count ?? 0 : config.originalDataArray?.length ?? 0;
16797
+ return allCount > this.getVisibleDataInsideGroup(groupKeys).length;
16798
+ }
16799
+ /**
16800
+ * Sets the selection of each visible row inside the group, by its full path,
16801
+ * so the rows of the group that are filtered out keep their selection
16802
+ */
16803
+ setVisibleRowsSelection(groupKeys, selected) {
16804
+ const { groupBy, toPrimaryKey } = this.getConfig();
16805
+ const mapToSet = selected ? this.selectedMap : this.deselectedMap;
16806
+ const mapToClear = selected ? this.deselectedMap : this.selectedMap;
16807
+ this.xcache();
16808
+ this.getVisibleDataInsideGroup(groupKeys).forEach((data) => {
16809
+ const rowGroupKeys = getGroupKeysForDataItem(data, groupBy);
16810
+ const pk = toPrimaryKey(data);
16811
+ const finalKey = [...rowGroupKeys, pk];
16812
+ mapToClear.delete(finalKey);
16813
+ if (this.isRowSelected(pk, rowGroupKeys) !== selected) {
16814
+ mapToSet.set(finalKey, true);
16815
+ }
16816
+ });
16817
+ this.xcache();
16818
+ }
16724
16819
  getGroupCount(groupKeys) {
16725
16820
  if (groupKeys.length == 0) {
16726
16821
  return this.getConfig().totalCount;
16727
16822
  }
16823
+ if (this.targetsFilteredOutRows()) {
16824
+ return getUnfilteredGroups(this.getConfig()).get(groupKeys)?.count ?? 0;
16825
+ }
16728
16826
  const groupDeepMap = this.getGroupDeepMap();
16729
16827
  const deepMapValue = groupDeepMap?.get(groupKeys);
16730
16828
  if (!deepMapValue) {
@@ -16733,14 +16831,28 @@ var RowSelectionState = class _RowSelectionState {
16733
16831
  return deepMapValue.totalChildrenCount ?? (deepMapValue.items.length || 0);
16734
16832
  }
16735
16833
  getGroupKeysDirectlyInsideGroup(groupKeys) {
16736
- const { groupDeepMap } = this.getConfig();
16737
- return groupDeepMap?.getKeysStartingWith(groupKeys, {
16738
- excludeSelf: true,
16739
- depthLimit: 1
16740
- }) || [];
16834
+ const config = this.getConfig();
16835
+ const options = { excludeSelf: true, depthLimit: 1 };
16836
+ if (this.targetsFilteredOutRows()) {
16837
+ return getUnfilteredGroups(config).getKeysStartingWith(
16838
+ groupKeys,
16839
+ options
16840
+ );
16841
+ }
16842
+ return config.groupDeepMap?.getKeysStartingWith(groupKeys, options) || [];
16741
16843
  }
16742
16844
  getAllPrimaryKeysInsideGroup(groupKeys) {
16743
- const { groupDeepMap } = this.getConfig();
16845
+ const config = this.getConfig();
16846
+ const { groupDeepMap, toPrimaryKey } = config;
16847
+ if (this.targetsFilteredOutRows()) {
16848
+ return groupKeys.length ? getUnfilteredPrimaryKeysInsideGroup(
16849
+ getUnfilteredGroups(config),
16850
+ groupKeys
16851
+ ) : (config.originalDataArray ?? []).map(toPrimaryKey);
16852
+ }
16853
+ if (!config.groupBy.length) {
16854
+ return this.getVisibleDataInsideGroup([]).map(toPrimaryKey);
16855
+ }
16744
16856
  if (!groupKeys.length) {
16745
16857
  const topLevelKeys = groupDeepMap?.getKeysStartingWith([], {
16746
16858
  excludeSelf: true,
@@ -16778,7 +16890,7 @@ var RowSelectionState = class _RowSelectionState {
16778
16890
  if (this.onlyUsePrimaryKeys) {
16779
16891
  return keys[0];
16780
16892
  }
16781
- return keys.length > groupByLength ? keys.pop() : keys;
16893
+ return groupByLength === 0 && keys.length === 1 ? keys[0] : keys;
16782
16894
  });
16783
16895
  };
16784
16896
  const selectedRows = normalize(this.selectedMap.topDownKeys());
@@ -16790,6 +16902,14 @@ var RowSelectionState = class _RowSelectionState {
16790
16902
  };
16791
16903
  }
16792
16904
  deselectAll() {
16905
+ if (this.targetsVisibleRowsOnly()) {
16906
+ if (this.onlyUsePrimaryKeys) {
16907
+ this.deselectGroupRow([]);
16908
+ } else {
16909
+ this.setVisibleRowsSelection([], false);
16910
+ }
16911
+ return;
16912
+ }
16793
16913
  this.update({
16794
16914
  defaultSelection: false,
16795
16915
  selectedRows: [],
@@ -16797,6 +16917,14 @@ var RowSelectionState = class _RowSelectionState {
16797
16917
  });
16798
16918
  }
16799
16919
  selectAll() {
16920
+ if (this.targetsVisibleRowsOnly()) {
16921
+ if (this.onlyUsePrimaryKeys) {
16922
+ this.selectGroupRow([]);
16923
+ } else {
16924
+ this.setVisibleRowsSelection([], true);
16925
+ }
16926
+ return;
16927
+ }
16800
16928
  this.update({
16801
16929
  defaultSelection: true,
16802
16930
  deselectedRows: [],
@@ -16951,6 +17079,10 @@ var RowSelectionState = class _RowSelectionState {
16951
17079
  this.xcache();
16952
17080
  return;
16953
17081
  }
17082
+ if (this.targetsVisibleRowsOnly() && this.hasFilteredOutRowsInsideGroup(groupKeys)) {
17083
+ this.setVisibleRowsSelection(groupKeys, true);
17084
+ return;
17085
+ }
16954
17086
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, {
16955
17087
  excludeSelf: true
16956
17088
  });
@@ -16979,6 +17111,10 @@ var RowSelectionState = class _RowSelectionState {
16979
17111
  this.xcache();
16980
17112
  return;
16981
17113
  }
17114
+ if (this.targetsVisibleRowsOnly() && this.hasFilteredOutRowsInsideGroup(groupKeys)) {
17115
+ this.setVisibleRowsSelection(groupKeys, false);
17116
+ return;
17117
+ }
16982
17118
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys, {
16983
17119
  excludeSelf: true
16984
17120
  });
@@ -17077,7 +17213,7 @@ var RowSelectionState = class _RowSelectionState {
17077
17213
  this.selectionCountCache.set(groupKeys, result2);
17078
17214
  return result2;
17079
17215
  }
17080
- if (groupByLength && this.onlyUsePrimaryKeys) {
17216
+ if (this.onlyUsePrimaryKeys && (groupByLength || this.targetsVisibleRowsOnly())) {
17081
17217
  const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
17082
17218
  let selectedCount2 = 0;
17083
17219
  let deselectedCount2 = 0;
@@ -17103,6 +17239,21 @@ var RowSelectionState = class _RowSelectionState {
17103
17239
  this.selectionCountCache.set(groupKeys, result2);
17104
17240
  return result2;
17105
17241
  }
17242
+ if (groupKeys.length === groupByLength && this.targetsVisibleRowsOnly()) {
17243
+ const { toPrimaryKey } = this.getConfig();
17244
+ let selectedCount2 = 0;
17245
+ let deselectedCount2 = 0;
17246
+ this.getVisibleDataInsideGroup(groupKeys).forEach((data) => {
17247
+ if (this.isRowSelected(toPrimaryKey(data), groupKeys)) {
17248
+ selectedCount2++;
17249
+ } else {
17250
+ deselectedCount2++;
17251
+ }
17252
+ });
17253
+ const result2 = { selectedCount: selectedCount2, deselectedCount: deselectedCount2 };
17254
+ this.selectionCountCache.set(groupKeys, result2);
17255
+ return result2;
17256
+ }
17106
17257
  parentSelected = parentSelected ?? this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
17107
17258
  let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
17108
17259
  if (groupKeys.length === this.getGroupByLength()) {
@@ -17169,6 +17320,7 @@ function cloneRowSelection(rowSelection, stateOrGetDataSourceState) {
17169
17320
  function rowSelectionStateConfigGetter(stateOrStateGetter) {
17170
17321
  return () => {
17171
17322
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
17323
+ const { originalDataArray, postFilterDataArray } = state;
17172
17324
  return {
17173
17325
  lazyLoad: !!state.lazyLoad,
17174
17326
  toPrimaryKey: state.toPrimaryKey,
@@ -17176,7 +17328,11 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
17176
17328
  groupBy: state.groupBy,
17177
17329
  groupDeepMap: state.groupDeepMap,
17178
17330
  indexer: state.indexer,
17179
- totalCount: state.unfilteredCount
17331
+ totalCount: state.unfilteredCount,
17332
+ multiRowSelectionTarget: state.multiRowSelectionTarget,
17333
+ someRowsFilteredOut: !state.lazyLoad && !!originalDataArray && !!postFilterDataArray && postFilterDataArray.length < originalDataArray.length,
17334
+ originalDataArray,
17335
+ postFilterDataArray
17180
17336
  };
17181
17337
  };
17182
17338
  }
@@ -18111,6 +18267,9 @@ var TreeExpandState = class {
18111
18267
  };
18112
18268
 
18113
18269
  // src/components/DataSource/TreeSelectionState.ts
18270
+ var toTreePathsMap = (treePaths) => {
18271
+ return Array.isArray(treePaths) ? new DeepMap(treePaths.map((path) => [path, true])) : treePaths;
18272
+ };
18114
18273
  var shortestToLongest = (a, b) => a.length - b.length;
18115
18274
  var TreeSelectionState = class _TreeSelectionState {
18116
18275
  constructor(state, getConfig) {
@@ -18137,13 +18296,7 @@ var TreeSelectionState = class _TreeSelectionState {
18137
18296
  }
18138
18297
  }
18139
18298
  getTreePaths(treePaths) {
18140
- if (treePaths) {
18141
- if (Array.isArray(treePaths)) {
18142
- return new DeepMap(treePaths.map((path) => [path, true]));
18143
- }
18144
- return treePaths;
18145
- }
18146
- return this.config.treePaths;
18299
+ return treePaths ? toTreePathsMap(treePaths) : this.config.treePaths;
18147
18300
  }
18148
18301
  withTreePaths(fn, treePaths) {
18149
18302
  const initialTreePaths = this.config.treePaths;
@@ -18216,11 +18369,38 @@ var TreeSelectionState = class _TreeSelectionState {
18216
18369
  setConfig(getConfig) {
18217
18370
  const config = typeof getConfig === "function" ? getConfig() : getConfig;
18218
18371
  this.config = {
18219
- treePaths: Array.isArray(config.treePaths) ? new DeepMap(config.treePaths.map((path) => [path, true])) : config.treePaths,
18220
- strictCheckPaths: config.strictCheckPaths ?? true
18372
+ treePaths: toTreePathsMap(config.treePaths),
18373
+ strictCheckPaths: config.strictCheckPaths ?? true,
18374
+ multiRowSelectionTarget: config.multiRowSelectionTarget,
18375
+ unfilteredTreePaths: config.unfilteredTreePaths ? toTreePathsMap(config.unfilteredTreePaths) : void 0
18221
18376
  };
18222
18377
  this.xcache();
18223
18378
  }
18379
+ hasFilteredOutLeavesInside(nodePath) {
18380
+ const { multiRowSelectionTarget, unfilteredTreePaths, treePaths } = this.config;
18381
+ if (multiRowSelectionTarget !== "visible" || !unfilteredTreePaths || unfilteredTreePaths === treePaths) {
18382
+ return false;
18383
+ }
18384
+ return unfilteredTreePaths.getAllChildrenSizeFor(nodePath) > treePaths.getAllChildrenSizeFor(nodePath);
18385
+ }
18386
+ /**
18387
+ * Sets the selection of each visible leaf node inside the node, by its path,
18388
+ * so the leaf nodes that are filtered out keep their selection
18389
+ */
18390
+ setVisibleLeafNodesSelection(nodePath, selected) {
18391
+ const { unfilteredTreePaths, treePaths } = this.config;
18392
+ this.xcache();
18393
+ treePaths.getKeysForLeafNodesStartingWith(nodePath).forEach((leafPath) => {
18394
+ if (unfilteredTreePaths.getAllChildrenSizeFor(leafPath) > 0) {
18395
+ return;
18396
+ }
18397
+ this.selectionMap.delete(leafPath);
18398
+ if (this.isNodeSelected(leafPath) !== selected) {
18399
+ this.setSelectionForPath(leafPath, selected);
18400
+ }
18401
+ });
18402
+ this.xcache();
18403
+ }
18224
18404
  xcache() {
18225
18405
  this.cache.clear();
18226
18406
  }
@@ -18261,6 +18441,10 @@ var TreeSelectionState = class _TreeSelectionState {
18261
18441
  };
18262
18442
  }
18263
18443
  deselectAll() {
18444
+ if (this.hasFilteredOutLeavesInside([])) {
18445
+ this.setVisibleLeafNodesSelection([], false);
18446
+ return;
18447
+ }
18264
18448
  this.update({
18265
18449
  defaultSelection: false,
18266
18450
  selectedPaths: [],
@@ -18268,6 +18452,10 @@ var TreeSelectionState = class _TreeSelectionState {
18268
18452
  });
18269
18453
  }
18270
18454
  selectAll() {
18455
+ if (this.hasFilteredOutLeavesInside([])) {
18456
+ this.setVisibleLeafNodesSelection([], true);
18457
+ return;
18458
+ }
18271
18459
  this.update({
18272
18460
  defaultSelection: true,
18273
18461
  deselectedPaths: [],
@@ -18419,6 +18607,10 @@ var TreeSelectionState = class _TreeSelectionState {
18419
18607
  if (!nodePath.length) {
18420
18608
  return;
18421
18609
  }
18610
+ if (this.hasFilteredOutLeavesInside(nodePath)) {
18611
+ this.setVisibleLeafNodesSelection(nodePath, selected);
18612
+ return;
18613
+ }
18422
18614
  this.xcache();
18423
18615
  const keys = this.selectionMap.getKeysStartingWith(nodePath);
18424
18616
  keys.forEach((nodePath2) => {
@@ -18475,8 +18667,17 @@ function cloneTreeSelection(treeSelection2, stateOrGetState) {
18475
18667
  function treeSelectionStateConfigGetter(stateOrStateGetter) {
18476
18668
  return () => {
18477
18669
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
18670
+ const { treePaths, unfilteredTreePaths, multiRowSelectionTarget } = state;
18671
+ if (multiRowSelectionTarget === "visible") {
18672
+ return {
18673
+ treePaths,
18674
+ unfilteredTreePaths,
18675
+ multiRowSelectionTarget
18676
+ };
18677
+ }
18478
18678
  return {
18479
- treePaths: state.treePaths
18679
+ treePaths: unfilteredTreePaths ?? treePaths,
18680
+ multiRowSelectionTarget
18480
18681
  };
18481
18682
  };
18482
18683
  }
@@ -20541,6 +20742,7 @@ var forwardProps3 = (setupState, props) => {
20541
20742
  treeFilterFunction: 1,
20542
20743
  filterValue: 1,
20543
20744
  useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) => useGroupKeysForMultiRowSelection ?? false,
20745
+ multiRowSelectionTarget: (multiRowSelectionTarget) => multiRowSelectionTarget ?? "all",
20544
20746
  filterDelay: (filterDelay) => filterDelay ?? 200,
20545
20747
  filterTypes: (filterTypes) => {
20546
20748
  return { ...defaultFilterTypes2, ...filterTypes };
@@ -21604,12 +21806,14 @@ function concludeReducer(params) {
21604
21806
  "rowSelection",
21605
21807
  "cellSelection",
21606
21808
  "isRowSelected",
21809
+ "multiRowSelectionTarget",
21607
21810
  "originalLazyGroupDataChangeDetect"
21608
21811
  ]);
21609
21812
  const treeSelectionDepsChanged = haveDepsChanged(previousState, state, [
21610
21813
  "treeSelection",
21611
21814
  "cellSelection",
21612
21815
  "isNodeSelected",
21816
+ "multiRowSelectionTarget",
21613
21817
  "originalLazyGroupDataChangeDetect"
21614
21818
  ]);
21615
21819
  const groupsDepsChanged = originalDataArrayChanged || sortDepsChanged || haveDepsChanged(previousState, state, [
@@ -21743,6 +21947,9 @@ function concludeReducer(params) {
21743
21947
  const rowSelectionState = state.rowSelection instanceof RowSelectionState ? state.rowSelection : void 0;
21744
21948
  const treeExpandState = state.treeExpandState instanceof TreeExpandState ? state.treeExpandState : void 0;
21745
21949
  const cellSelectionState = state.cellSelection instanceof CellSelectionState ? state.cellSelection : void 0;
21950
+ if (rowSelectionState) {
21951
+ rowSelectionState.getConfig = rowSelectionStateConfigGetter(state);
21952
+ }
21746
21953
  rowSelectionState?.xcache();
21747
21954
  let isRowSelected = state.selectionMode === "single-row" ? (rowInfo) => {
21748
21955
  return rowInfo.id === state.rowSelection;
@@ -22049,10 +22256,14 @@ function concludeReducer(params) {
22049
22256
  debugId
22050
22257
  ).track.DataSource.label.ComputeSelectionCount.start();
22051
22258
  }
22052
- const dataArrayCount = state.isTree ? state.totalLeafNodesCount : state.filteredCount;
22053
- const selectedRowCount = state.isTree ? state.treeSelectionState ? state.treeSelectionState.getSelectedCount() : 0 : state.rowSelection.getSelectedCount();
22054
- state.allRowsSelected = dataArrayCount === selectedRowCount;
22055
- state.someRowsSelected = selectedRowCount > 0;
22259
+ const selectionCount = state.isTree ? state.treeSelectionState?.getSelectionCountFor([]) : state.rowSelection.getSelectionCountFor([]);
22260
+ if (selectionCount) {
22261
+ state.allRowsSelected = selectionCount.deselectedCount === 0;
22262
+ state.someRowsSelected = selectionCount.selectedCount > 0;
22263
+ } else {
22264
+ state.allRowsSelected = state.totalLeafNodesCount === 0;
22265
+ state.someRowsSelected = false;
22266
+ }
22056
22267
  if (debugId) {
22057
22268
  marker?.end();
22058
22269
  marker = void 0;
@@ -22151,6 +22362,7 @@ function buildDataSourceDataParams(componentState, overrides, masterContext) {
22151
22362
  dataSourceParams.lazyLoadStartIndex = 0;
22152
22363
  }
22153
22364
  dataSourceParams.groupKeys = [];
22365
+ dataSourceParams.multiRowSelectionTarget = componentState.multiRowSelectionTarget;
22154
22366
  }
22155
22367
  if (overrides) {
22156
22368
  Object.assign(dataSourceParams, overrides);
@@ -27832,7 +28044,7 @@ var useLicense = (licenseKey = "") => {
27832
28044
  }
27833
28045
  let valid2 = isValidLicense(licenseKey, {
27834
28046
  publishedAt: 1624970570587,
27835
- version: "9.1.5"
28047
+ version: "9.2.0"
27836
28048
  });
27837
28049
  if (!licenseKey && !valid2 && isInsidePlayground) {
27838
28050
  return true;