@infinite-table/infinite-react 9.1.4 → 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.js CHANGED
@@ -16736,6 +16736,52 @@ function getGroupKeysForDataItem(data, groupBy) {
16736
16736
  }
16737
16737
 
16738
16738
  // src/components/DataSource/RowSelectionState.ts
16739
+ var EMPTY_UNFILTERED_GROUPS = new DeepMap();
16740
+ var unfilteredGroupsCache = /* @__PURE__ */ new WeakMap();
16741
+ function getUnfilteredGroups(config) {
16742
+ const { originalDataArray, groupBy, toPrimaryKey } = config;
16743
+ if (!originalDataArray || !groupBy.length) {
16744
+ return EMPTY_UNFILTERED_GROUPS;
16745
+ }
16746
+ const cached = unfilteredGroupsCache.get(originalDataArray);
16747
+ if (cached && cached.groupBy === groupBy) {
16748
+ return cached.groups;
16749
+ }
16750
+ const groups = new DeepMap();
16751
+ const lastLevel = groupBy.length;
16752
+ const keys = [];
16753
+ originalDataArray.forEach((data) => {
16754
+ const groupKeys = getGroupKeysForDataItem(data, groupBy);
16755
+ keys.length = 0;
16756
+ for (let i = 0; i < groupKeys.length; i++) {
16757
+ keys.push(groupKeys[i]);
16758
+ let group2 = groups.get(keys);
16759
+ if (!group2) {
16760
+ group2 = { count: 0 };
16761
+ if (keys.length === lastLevel) {
16762
+ group2.primaryKeys = [];
16763
+ }
16764
+ groups.set(keys, group2);
16765
+ }
16766
+ group2.count++;
16767
+ group2.primaryKeys?.push(toPrimaryKey(data));
16768
+ }
16769
+ });
16770
+ unfilteredGroupsCache.set(originalDataArray, { groupBy, groups });
16771
+ return groups;
16772
+ }
16773
+ function getUnfilteredPrimaryKeysInsideGroup(groups, groupKeys) {
16774
+ const result = [];
16775
+ groups.getLeafNodesStartingWith(groupKeys, (pair) => {
16776
+ const primaryKeys = pair.value?.primaryKeys;
16777
+ if (primaryKeys) {
16778
+ for (let i = 0; i < primaryKeys.length; i++) {
16779
+ result.push(primaryKeys[i]);
16780
+ }
16781
+ }
16782
+ });
16783
+ return result;
16784
+ }
16739
16785
  var RowSelectionState = class _RowSelectionState {
16740
16786
  constructor(state, getConfig, _forTestingOnly) {
16741
16787
  this.selectedRows = null;
@@ -16787,10 +16833,62 @@ var RowSelectionState = class _RowSelectionState {
16787
16833
  getGroupDeepMap() {
16788
16834
  return this.getConfig().groupDeepMap;
16789
16835
  }
16836
+ /**
16837
+ * The selection acts only on the rows that pass the filter, and some rows are filtered out
16838
+ */
16839
+ targetsVisibleRowsOnly() {
16840
+ const { multiRowSelectionTarget, someRowsFilteredOut } = this.getConfig();
16841
+ return multiRowSelectionTarget === "visible" && !!someRowsFilteredOut;
16842
+ }
16843
+ /**
16844
+ * The selection also acts on rows that are filtered out, and some rows are filtered out
16845
+ */
16846
+ targetsFilteredOutRows() {
16847
+ const { multiRowSelectionTarget, someRowsFilteredOut } = this.getConfig();
16848
+ return multiRowSelectionTarget !== "visible" && !!someRowsFilteredOut;
16849
+ }
16850
+ getVisibleDataInsideGroup(groupKeys) {
16851
+ const { postFilterDataArray, groupDeepMap } = this.getConfig();
16852
+ if (!groupKeys.length) {
16853
+ return postFilterDataArray ?? [];
16854
+ }
16855
+ return groupDeepMap?.get(groupKeys)?.items ?? [];
16856
+ }
16857
+ hasFilteredOutRowsInsideGroup(groupKeys) {
16858
+ const config = this.getConfig();
16859
+ if (!config.someRowsFilteredOut) {
16860
+ return false;
16861
+ }
16862
+ const allCount = groupKeys.length ? getUnfilteredGroups(config).get(groupKeys)?.count ?? 0 : config.originalDataArray?.length ?? 0;
16863
+ return allCount > this.getVisibleDataInsideGroup(groupKeys).length;
16864
+ }
16865
+ /**
16866
+ * Sets the selection of each visible row inside the group, by its full path,
16867
+ * so the rows of the group that are filtered out keep their selection
16868
+ */
16869
+ setVisibleRowsSelection(groupKeys, selected) {
16870
+ const { groupBy, toPrimaryKey } = this.getConfig();
16871
+ const mapToSet = selected ? this.selectedMap : this.deselectedMap;
16872
+ const mapToClear = selected ? this.deselectedMap : this.selectedMap;
16873
+ this.xcache();
16874
+ this.getVisibleDataInsideGroup(groupKeys).forEach((data) => {
16875
+ const rowGroupKeys = getGroupKeysForDataItem(data, groupBy);
16876
+ const pk = toPrimaryKey(data);
16877
+ const finalKey = [...rowGroupKeys, pk];
16878
+ mapToClear.delete(finalKey);
16879
+ if (this.isRowSelected(pk, rowGroupKeys) !== selected) {
16880
+ mapToSet.set(finalKey, true);
16881
+ }
16882
+ });
16883
+ this.xcache();
16884
+ }
16790
16885
  getGroupCount(groupKeys) {
16791
16886
  if (groupKeys.length == 0) {
16792
16887
  return this.getConfig().totalCount;
16793
16888
  }
16889
+ if (this.targetsFilteredOutRows()) {
16890
+ return getUnfilteredGroups(this.getConfig()).get(groupKeys)?.count ?? 0;
16891
+ }
16794
16892
  const groupDeepMap = this.getGroupDeepMap();
16795
16893
  const deepMapValue = groupDeepMap?.get(groupKeys);
16796
16894
  if (!deepMapValue) {
@@ -16799,14 +16897,28 @@ var RowSelectionState = class _RowSelectionState {
16799
16897
  return deepMapValue.totalChildrenCount ?? (deepMapValue.items.length || 0);
16800
16898
  }
16801
16899
  getGroupKeysDirectlyInsideGroup(groupKeys) {
16802
- const { groupDeepMap } = this.getConfig();
16803
- return groupDeepMap?.getKeysStartingWith(groupKeys, {
16804
- excludeSelf: true,
16805
- depthLimit: 1
16806
- }) || [];
16900
+ const config = this.getConfig();
16901
+ const options = { excludeSelf: true, depthLimit: 1 };
16902
+ if (this.targetsFilteredOutRows()) {
16903
+ return getUnfilteredGroups(config).getKeysStartingWith(
16904
+ groupKeys,
16905
+ options
16906
+ );
16907
+ }
16908
+ return config.groupDeepMap?.getKeysStartingWith(groupKeys, options) || [];
16807
16909
  }
16808
16910
  getAllPrimaryKeysInsideGroup(groupKeys) {
16809
- const { groupDeepMap } = this.getConfig();
16911
+ const config = this.getConfig();
16912
+ const { groupDeepMap, toPrimaryKey } = config;
16913
+ if (this.targetsFilteredOutRows()) {
16914
+ return groupKeys.length ? getUnfilteredPrimaryKeysInsideGroup(
16915
+ getUnfilteredGroups(config),
16916
+ groupKeys
16917
+ ) : (config.originalDataArray ?? []).map(toPrimaryKey);
16918
+ }
16919
+ if (!config.groupBy.length) {
16920
+ return this.getVisibleDataInsideGroup([]).map(toPrimaryKey);
16921
+ }
16810
16922
  if (!groupKeys.length) {
16811
16923
  const topLevelKeys = groupDeepMap?.getKeysStartingWith([], {
16812
16924
  excludeSelf: true,
@@ -16844,7 +16956,7 @@ var RowSelectionState = class _RowSelectionState {
16844
16956
  if (this.onlyUsePrimaryKeys) {
16845
16957
  return keys[0];
16846
16958
  }
16847
- return keys.length > groupByLength ? keys.pop() : keys;
16959
+ return groupByLength === 0 && keys.length === 1 ? keys[0] : keys;
16848
16960
  });
16849
16961
  };
16850
16962
  const selectedRows = normalize(this.selectedMap.topDownKeys());
@@ -16856,6 +16968,14 @@ var RowSelectionState = class _RowSelectionState {
16856
16968
  };
16857
16969
  }
16858
16970
  deselectAll() {
16971
+ if (this.targetsVisibleRowsOnly()) {
16972
+ if (this.onlyUsePrimaryKeys) {
16973
+ this.deselectGroupRow([]);
16974
+ } else {
16975
+ this.setVisibleRowsSelection([], false);
16976
+ }
16977
+ return;
16978
+ }
16859
16979
  this.update({
16860
16980
  defaultSelection: false,
16861
16981
  selectedRows: [],
@@ -16863,6 +16983,14 @@ var RowSelectionState = class _RowSelectionState {
16863
16983
  });
16864
16984
  }
16865
16985
  selectAll() {
16986
+ if (this.targetsVisibleRowsOnly()) {
16987
+ if (this.onlyUsePrimaryKeys) {
16988
+ this.selectGroupRow([]);
16989
+ } else {
16990
+ this.setVisibleRowsSelection([], true);
16991
+ }
16992
+ return;
16993
+ }
16866
16994
  this.update({
16867
16995
  defaultSelection: true,
16868
16996
  deselectedRows: [],
@@ -17017,6 +17145,10 @@ var RowSelectionState = class _RowSelectionState {
17017
17145
  this.xcache();
17018
17146
  return;
17019
17147
  }
17148
+ if (this.targetsVisibleRowsOnly() && this.hasFilteredOutRowsInsideGroup(groupKeys)) {
17149
+ this.setVisibleRowsSelection(groupKeys, true);
17150
+ return;
17151
+ }
17020
17152
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, {
17021
17153
  excludeSelf: true
17022
17154
  });
@@ -17045,6 +17177,10 @@ var RowSelectionState = class _RowSelectionState {
17045
17177
  this.xcache();
17046
17178
  return;
17047
17179
  }
17180
+ if (this.targetsVisibleRowsOnly() && this.hasFilteredOutRowsInsideGroup(groupKeys)) {
17181
+ this.setVisibleRowsSelection(groupKeys, false);
17182
+ return;
17183
+ }
17048
17184
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys, {
17049
17185
  excludeSelf: true
17050
17186
  });
@@ -17143,7 +17279,7 @@ var RowSelectionState = class _RowSelectionState {
17143
17279
  this.selectionCountCache.set(groupKeys, result2);
17144
17280
  return result2;
17145
17281
  }
17146
- if (groupByLength && this.onlyUsePrimaryKeys) {
17282
+ if (this.onlyUsePrimaryKeys && (groupByLength || this.targetsVisibleRowsOnly())) {
17147
17283
  const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
17148
17284
  let selectedCount2 = 0;
17149
17285
  let deselectedCount2 = 0;
@@ -17169,6 +17305,21 @@ var RowSelectionState = class _RowSelectionState {
17169
17305
  this.selectionCountCache.set(groupKeys, result2);
17170
17306
  return result2;
17171
17307
  }
17308
+ if (groupKeys.length === groupByLength && this.targetsVisibleRowsOnly()) {
17309
+ const { toPrimaryKey } = this.getConfig();
17310
+ let selectedCount2 = 0;
17311
+ let deselectedCount2 = 0;
17312
+ this.getVisibleDataInsideGroup(groupKeys).forEach((data) => {
17313
+ if (this.isRowSelected(toPrimaryKey(data), groupKeys)) {
17314
+ selectedCount2++;
17315
+ } else {
17316
+ deselectedCount2++;
17317
+ }
17318
+ });
17319
+ const result2 = { selectedCount: selectedCount2, deselectedCount: deselectedCount2 };
17320
+ this.selectionCountCache.set(groupKeys, result2);
17321
+ return result2;
17322
+ }
17172
17323
  parentSelected = parentSelected ?? this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
17173
17324
  let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
17174
17325
  if (groupKeys.length === this.getGroupByLength()) {
@@ -17235,6 +17386,7 @@ function cloneRowSelection(rowSelection, stateOrGetDataSourceState) {
17235
17386
  function rowSelectionStateConfigGetter(stateOrStateGetter) {
17236
17387
  return () => {
17237
17388
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
17389
+ const { originalDataArray, postFilterDataArray } = state;
17238
17390
  return {
17239
17391
  lazyLoad: !!state.lazyLoad,
17240
17392
  toPrimaryKey: state.toPrimaryKey,
@@ -17242,7 +17394,11 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
17242
17394
  groupBy: state.groupBy,
17243
17395
  groupDeepMap: state.groupDeepMap,
17244
17396
  indexer: state.indexer,
17245
- totalCount: state.unfilteredCount
17397
+ totalCount: state.unfilteredCount,
17398
+ multiRowSelectionTarget: state.multiRowSelectionTarget,
17399
+ someRowsFilteredOut: !state.lazyLoad && !!originalDataArray && !!postFilterDataArray && postFilterDataArray.length < originalDataArray.length,
17400
+ originalDataArray,
17401
+ postFilterDataArray
17246
17402
  };
17247
17403
  };
17248
17404
  }
@@ -18177,6 +18333,9 @@ var TreeExpandState = class {
18177
18333
  };
18178
18334
 
18179
18335
  // src/components/DataSource/TreeSelectionState.ts
18336
+ var toTreePathsMap = (treePaths) => {
18337
+ return Array.isArray(treePaths) ? new DeepMap(treePaths.map((path) => [path, true])) : treePaths;
18338
+ };
18180
18339
  var shortestToLongest = (a, b) => a.length - b.length;
18181
18340
  var TreeSelectionState = class _TreeSelectionState {
18182
18341
  constructor(state, getConfig) {
@@ -18203,13 +18362,7 @@ var TreeSelectionState = class _TreeSelectionState {
18203
18362
  }
18204
18363
  }
18205
18364
  getTreePaths(treePaths) {
18206
- if (treePaths) {
18207
- if (Array.isArray(treePaths)) {
18208
- return new DeepMap(treePaths.map((path) => [path, true]));
18209
- }
18210
- return treePaths;
18211
- }
18212
- return this.config.treePaths;
18365
+ return treePaths ? toTreePathsMap(treePaths) : this.config.treePaths;
18213
18366
  }
18214
18367
  withTreePaths(fn, treePaths) {
18215
18368
  const initialTreePaths = this.config.treePaths;
@@ -18282,11 +18435,38 @@ var TreeSelectionState = class _TreeSelectionState {
18282
18435
  setConfig(getConfig) {
18283
18436
  const config = typeof getConfig === "function" ? getConfig() : getConfig;
18284
18437
  this.config = {
18285
- treePaths: Array.isArray(config.treePaths) ? new DeepMap(config.treePaths.map((path) => [path, true])) : config.treePaths,
18286
- strictCheckPaths: config.strictCheckPaths ?? true
18438
+ treePaths: toTreePathsMap(config.treePaths),
18439
+ strictCheckPaths: config.strictCheckPaths ?? true,
18440
+ multiRowSelectionTarget: config.multiRowSelectionTarget,
18441
+ unfilteredTreePaths: config.unfilteredTreePaths ? toTreePathsMap(config.unfilteredTreePaths) : void 0
18287
18442
  };
18288
18443
  this.xcache();
18289
18444
  }
18445
+ hasFilteredOutLeavesInside(nodePath) {
18446
+ const { multiRowSelectionTarget, unfilteredTreePaths, treePaths } = this.config;
18447
+ if (multiRowSelectionTarget !== "visible" || !unfilteredTreePaths || unfilteredTreePaths === treePaths) {
18448
+ return false;
18449
+ }
18450
+ return unfilteredTreePaths.getAllChildrenSizeFor(nodePath) > treePaths.getAllChildrenSizeFor(nodePath);
18451
+ }
18452
+ /**
18453
+ * Sets the selection of each visible leaf node inside the node, by its path,
18454
+ * so the leaf nodes that are filtered out keep their selection
18455
+ */
18456
+ setVisibleLeafNodesSelection(nodePath, selected) {
18457
+ const { unfilteredTreePaths, treePaths } = this.config;
18458
+ this.xcache();
18459
+ treePaths.getKeysForLeafNodesStartingWith(nodePath).forEach((leafPath) => {
18460
+ if (unfilteredTreePaths.getAllChildrenSizeFor(leafPath) > 0) {
18461
+ return;
18462
+ }
18463
+ this.selectionMap.delete(leafPath);
18464
+ if (this.isNodeSelected(leafPath) !== selected) {
18465
+ this.setSelectionForPath(leafPath, selected);
18466
+ }
18467
+ });
18468
+ this.xcache();
18469
+ }
18290
18470
  xcache() {
18291
18471
  this.cache.clear();
18292
18472
  }
@@ -18327,6 +18507,10 @@ var TreeSelectionState = class _TreeSelectionState {
18327
18507
  };
18328
18508
  }
18329
18509
  deselectAll() {
18510
+ if (this.hasFilteredOutLeavesInside([])) {
18511
+ this.setVisibleLeafNodesSelection([], false);
18512
+ return;
18513
+ }
18330
18514
  this.update({
18331
18515
  defaultSelection: false,
18332
18516
  selectedPaths: [],
@@ -18334,6 +18518,10 @@ var TreeSelectionState = class _TreeSelectionState {
18334
18518
  });
18335
18519
  }
18336
18520
  selectAll() {
18521
+ if (this.hasFilteredOutLeavesInside([])) {
18522
+ this.setVisibleLeafNodesSelection([], true);
18523
+ return;
18524
+ }
18337
18525
  this.update({
18338
18526
  defaultSelection: true,
18339
18527
  deselectedPaths: [],
@@ -18485,6 +18673,10 @@ var TreeSelectionState = class _TreeSelectionState {
18485
18673
  if (!nodePath.length) {
18486
18674
  return;
18487
18675
  }
18676
+ if (this.hasFilteredOutLeavesInside(nodePath)) {
18677
+ this.setVisibleLeafNodesSelection(nodePath, selected);
18678
+ return;
18679
+ }
18488
18680
  this.xcache();
18489
18681
  const keys = this.selectionMap.getKeysStartingWith(nodePath);
18490
18682
  keys.forEach((nodePath2) => {
@@ -18541,8 +18733,17 @@ function cloneTreeSelection(treeSelection2, stateOrGetState) {
18541
18733
  function treeSelectionStateConfigGetter(stateOrStateGetter) {
18542
18734
  return () => {
18543
18735
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
18736
+ const { treePaths, unfilteredTreePaths, multiRowSelectionTarget } = state;
18737
+ if (multiRowSelectionTarget === "visible") {
18738
+ return {
18739
+ treePaths,
18740
+ unfilteredTreePaths,
18741
+ multiRowSelectionTarget
18742
+ };
18743
+ }
18544
18744
  return {
18545
- treePaths: state.treePaths
18745
+ treePaths: unfilteredTreePaths ?? treePaths,
18746
+ multiRowSelectionTarget
18546
18747
  };
18547
18748
  };
18548
18749
  }
@@ -20607,6 +20808,7 @@ var forwardProps3 = (setupState, props) => {
20607
20808
  treeFilterFunction: 1,
20608
20809
  filterValue: 1,
20609
20810
  useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) => useGroupKeysForMultiRowSelection ?? false,
20811
+ multiRowSelectionTarget: (multiRowSelectionTarget) => multiRowSelectionTarget ?? "all",
20610
20812
  filterDelay: (filterDelay) => filterDelay ?? 200,
20611
20813
  filterTypes: (filterTypes) => {
20612
20814
  return { ...defaultFilterTypes2, ...filterTypes };
@@ -21670,12 +21872,14 @@ function concludeReducer(params) {
21670
21872
  "rowSelection",
21671
21873
  "cellSelection",
21672
21874
  "isRowSelected",
21875
+ "multiRowSelectionTarget",
21673
21876
  "originalLazyGroupDataChangeDetect"
21674
21877
  ]);
21675
21878
  const treeSelectionDepsChanged = haveDepsChanged(previousState, state, [
21676
21879
  "treeSelection",
21677
21880
  "cellSelection",
21678
21881
  "isNodeSelected",
21882
+ "multiRowSelectionTarget",
21679
21883
  "originalLazyGroupDataChangeDetect"
21680
21884
  ]);
21681
21885
  const groupsDepsChanged = originalDataArrayChanged || sortDepsChanged || haveDepsChanged(previousState, state, [
@@ -21809,6 +22013,9 @@ function concludeReducer(params) {
21809
22013
  const rowSelectionState = state.rowSelection instanceof RowSelectionState ? state.rowSelection : void 0;
21810
22014
  const treeExpandState = state.treeExpandState instanceof TreeExpandState ? state.treeExpandState : void 0;
21811
22015
  const cellSelectionState = state.cellSelection instanceof CellSelectionState ? state.cellSelection : void 0;
22016
+ if (rowSelectionState) {
22017
+ rowSelectionState.getConfig = rowSelectionStateConfigGetter(state);
22018
+ }
21812
22019
  rowSelectionState?.xcache();
21813
22020
  let isRowSelected = state.selectionMode === "single-row" ? (rowInfo) => {
21814
22021
  return rowInfo.id === state.rowSelection;
@@ -22115,10 +22322,14 @@ function concludeReducer(params) {
22115
22322
  debugId
22116
22323
  ).track.DataSource.label.ComputeSelectionCount.start();
22117
22324
  }
22118
- const dataArrayCount = state.isTree ? state.totalLeafNodesCount : state.filteredCount;
22119
- const selectedRowCount = state.isTree ? state.treeSelectionState ? state.treeSelectionState.getSelectedCount() : 0 : state.rowSelection.getSelectedCount();
22120
- state.allRowsSelected = dataArrayCount === selectedRowCount;
22121
- state.someRowsSelected = selectedRowCount > 0;
22325
+ const selectionCount = state.isTree ? state.treeSelectionState?.getSelectionCountFor([]) : state.rowSelection.getSelectionCountFor([]);
22326
+ if (selectionCount) {
22327
+ state.allRowsSelected = selectionCount.deselectedCount === 0;
22328
+ state.someRowsSelected = selectionCount.selectedCount > 0;
22329
+ } else {
22330
+ state.allRowsSelected = state.totalLeafNodesCount === 0;
22331
+ state.someRowsSelected = false;
22332
+ }
22122
22333
  if (debugId) {
22123
22334
  marker?.end();
22124
22335
  marker = void 0;
@@ -22217,6 +22428,7 @@ function buildDataSourceDataParams(componentState, overrides, masterContext) {
22217
22428
  dataSourceParams.lazyLoadStartIndex = 0;
22218
22429
  }
22219
22430
  dataSourceParams.groupKeys = [];
22431
+ dataSourceParams.multiRowSelectionTarget = componentState.multiRowSelectionTarget;
22220
22432
  }
22221
22433
  if (overrides) {
22222
22434
  Object.assign(dataSourceParams, overrides);
@@ -27893,7 +28105,7 @@ var useLicense = (licenseKey = "") => {
27893
28105
  }
27894
28106
  let valid2 = isValidLicense(licenseKey, {
27895
28107
  publishedAt: 1624970570587,
27896
- version: "9.1.4"
28108
+ version: "9.2.0"
27897
28109
  });
27898
28110
  if (!licenseKey && !valid2 && isInsidePlayground) {
27899
28111
  return true;