@infinite-table/infinite-react 0.4.8 → 0.4.11

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.
Files changed (4) hide show
  1. package/index.d.ts +8 -1
  2. package/index.esm.js +188 -55
  3. package/index.js +188 -55
  4. package/package.json +2 -2
package/index.d.ts CHANGED
@@ -663,9 +663,11 @@ declare type RowSelectionStateObject = {
663
663
  declare type RowSelectionStateConfig<T> = {
664
664
  groupBy: DataSourceState<T>['groupBy'];
665
665
  groupDeepMap: DataSourceState<T>['groupDeepMap'];
666
+ toPrimaryKey: DataSourceState<T>['toPrimaryKey'];
666
667
  totalCount: number;
667
668
  indexer: DataSourceState<T>['indexer'];
668
669
  lazyLoad: boolean;
670
+ onlyUsePrimaryKeys: boolean;
669
671
  };
670
672
  declare type GetRowSelectionStateConfig<T> = () => RowSelectionStateConfig<T>;
671
673
  declare type RowSelectionStateOverrideForTesting = {
@@ -673,6 +675,7 @@ declare type RowSelectionStateOverrideForTesting = {
673
675
  getGroupByLength: RowSelectionState<any>['getGroupByLength'];
674
676
  getGroupCount: RowSelectionState<any>['getGroupCount'];
675
677
  getGroupKeysDirectlyInsideGroup: RowSelectionState<any>['getGroupKeysDirectlyInsideGroup'];
678
+ getAllPrimaryKeysInsideGroup: RowSelectionState<any>['getAllPrimaryKeysInsideGroup'];
676
679
  };
677
680
  declare class RowSelectionState<T = any> {
678
681
  selectedRows: RowSelectionStateItem | null;
@@ -680,6 +683,7 @@ declare class RowSelectionState<T = any> {
680
683
  defaultSelection: boolean;
681
684
  selectedMap: DeepMap<any, true>;
682
685
  deselectedMap: DeepMap<any, true>;
686
+ onlyUsePrimaryKeys: boolean;
683
687
  selectionCache: DeepMap<any, boolean | null>;
684
688
  selectionCountCache: DeepMap<any, {
685
689
  selectedCount: number;
@@ -690,6 +694,7 @@ declare class RowSelectionState<T = any> {
690
694
  getGroupDeepMap(): DeepMap<any, DeepMapGroupValueType<T, any>> | undefined;
691
695
  getGroupCount(groupKeys: any[]): number;
692
696
  getGroupKeysDirectlyInsideGroup(groupKeys: any[]): any[][];
697
+ getAllPrimaryKeysInsideGroup(groupKeys: any[]): any[];
693
698
  getGroupByLength(): number;
694
699
  static from<T>(rowSeleStateObject: RowSelectionStateObject, getConfig: GetRowSelectionStateConfig<T>, _forTestingOnly?: RowSelectionStateOverrideForTesting): RowSelectionState<T>;
695
700
  constructor(state: RowSelectionStateObject | RowSelectionState, getConfig: GetRowSelectionStateConfig<T>, _forTestingOnly?: RowSelectionStateOverrideForTesting);
@@ -1155,6 +1160,7 @@ interface DataSourceMappedState<T> {
1155
1160
  livePagination: DataSourceProps<T>['livePagination'];
1156
1161
  isRowSelected: DataSourceProps<T>['isRowSelected'];
1157
1162
  lazyLoad: DataSourceProps<T>['lazyLoad'];
1163
+ useGroupKeysForMultiRowSelection: NonUndefined<DataSourceProps<T>['useGroupKeysForMultiRowSelection']>;
1158
1164
  onDataParamsChange: DataSourceProps<T>['onDataParamsChange'];
1159
1165
  data: DataSourceProps<T>['data'];
1160
1166
  sortMode: DataSourceProps<T>['sortMode'];
@@ -1164,7 +1170,6 @@ interface DataSourceMappedState<T> {
1164
1170
  primaryKey: DataSourceProps<T>['primaryKey'];
1165
1171
  filterDelay: NonUndefined<DataSourceProps<T>['filterDelay']>;
1166
1172
  groupBy: NonUndefined<DataSourceProps<T>['groupBy']>;
1167
- groupRowsState: GroupRowsState<T>;
1168
1173
  pivotBy: DataSourceProps<T>['pivotBy'];
1169
1174
  loading: NonUndefined<DataSourceProps<T>['loading']>;
1170
1175
  sortTypes: NonUndefined<DataSourceProps<T>['sortTypes']>;
@@ -1267,6 +1272,7 @@ declare type DataSourceProps<T> = {
1267
1272
  fields?: (keyof T)[];
1268
1273
  data: DataSourceData<T>;
1269
1274
  selectionMode?: DataSourcePropSelectionMode;
1275
+ useGroupKeysForMultiRowSelection?: boolean;
1270
1276
  rowSelection?: DataSourcePropRowSelection_MultiRow | DataSourcePropRowSelection_SingleRow;
1271
1277
  defaultRowSelection?: DataSourcePropRowSelection_MultiRow | DataSourcePropRowSelection_SingleRow;
1272
1278
  cellSelection?: DataSourcePropCellSelection;
@@ -1377,6 +1383,7 @@ declare type DataSourceDerivedState<T> = {
1377
1383
  toPrimaryKey: (data: T) => any;
1378
1384
  operatorsByFilterType: Record<string, Record<string, DataSourceFilterOperator<T>>>;
1379
1385
  filterMode: NonUndefined<DataSourceProps<T>['filterMode']>;
1386
+ groupRowsState: GroupRowsState<T>;
1380
1387
  multiSort: boolean;
1381
1388
  controlledSort: boolean;
1382
1389
  controlledFilter: boolean;
package/index.esm.js CHANGED
@@ -4360,6 +4360,10 @@ function useCellClassName(column, baseClasses, variants, extraFlags) {
4360
4360
  if (extraFlags.rowSelected) {
4361
4361
  result.push(...baseClasses.map((c) => `${c}--row-selected`));
4362
4362
  }
4363
+ if (extraFlags.groupRow) {
4364
+ result.push(...baseClasses.map((c) => `${c}--group-row`));
4365
+ result.push(...baseClasses.map((c) => `${c}--${extraFlags.rowExpanded ? "group-row-expanded" : "group-row-collapsed"}`));
4366
+ }
4363
4367
  if (column.computedPinned) {
4364
4368
  result.push(...baseClasses.map((c) => `${c}--pinned-${column.computedPinned}`));
4365
4369
  } else {
@@ -5906,7 +5910,14 @@ function InfiniteTableColumnCellFn(props) {
5906
5910
  onClick,
5907
5911
  onMouseDown,
5908
5912
  cssEllipsis: (_a = column.cssEllipsis) != null ? _a : true,
5909
- className: join(useCellClassName(column, [InfiniteTableColumnCellClassName, InfiniteTableCellClassName], ColumnCellRecipe, { dragging: false, zebra, rowActive, rowSelected }), colClassName, rowComputedClassName),
5913
+ className: join(useCellClassName(column, [InfiniteTableColumnCellClassName, InfiniteTableCellClassName], ColumnCellRecipe, {
5914
+ dragging: false,
5915
+ zebra,
5916
+ rowActive,
5917
+ rowSelected,
5918
+ groupRow: rowInfo.isGroupRow,
5919
+ rowExpanded: rowInfo.isGroupRow ? !rowInfo.collapsed : false
5920
+ }), colClassName, rowComputedClassName),
5910
5921
  renderChildren
5911
5922
  };
5912
5923
  return /* @__PURE__ */ createElement18(InfiniteTableCell, __spreadValues({}, cellProps));
@@ -6954,7 +6965,9 @@ function InfiniteTableHeaderCell(props) {
6954
6965
  dragging,
6955
6966
  rowSelected: false,
6956
6967
  zebra: false,
6957
- rowActive: false
6968
+ rowActive: false,
6969
+ groupRow: false,
6970
+ rowExpanded: false
6958
6971
  }), CellCls),
6959
6972
  cssEllipsis: (_e = (_d = column.headerCssEllipsis) != null ? _d : column.cssEllipsis) != null ? _e : true,
6960
6973
  afterChildren: /* @__PURE__ */ createElement25(Fragment3, null, showColumnFilters ? column.computedFilterable ? /* @__PURE__ */ createElement25(InfiniteTableColumnHeaderFilter, {
@@ -7696,6 +7709,14 @@ function lazyGroup(groupParams, rootData) {
7696
7709
  if (currentGroupKeys.length == groupBy.length && groupBy.length) {
7697
7710
  if (current) {
7698
7711
  current.items = dataArray;
7712
+ for (let i = 0, len = currentGroupKeys.length; i < len; i++) {
7713
+ const currentKeys = currentGroupKeys.slice(0, i);
7714
+ const deepMapGroupValue = deepMap.get(currentKeys);
7715
+ if (deepMapGroupValue) {
7716
+ deepMapGroupValue.items = deepMapGroupValue.items || [];
7717
+ deepMapGroupValue.items = deepMapGroupValue.items.concat(dataArray);
7718
+ }
7719
+ }
7699
7720
  indexer.indexArray(dataArray, toPrimaryKey);
7700
7721
  }
7701
7722
  return next == null ? void 0 : next();
@@ -7716,7 +7737,7 @@ function lazyGroup(groupParams, rootData) {
7716
7737
  continue;
7717
7738
  }
7718
7739
  const dataObject = dataArray[i].data;
7719
- const dataKeys = dataArray[i].keys;
7740
+ const dataKeys = dataArray[i].keys || [];
7720
7741
  if (dataKeys.length) {
7721
7742
  const key = dataKeys[dataKeys.length - 1];
7722
7743
  currentGroupKeys.push(key);
@@ -7894,7 +7915,7 @@ function flatten(groupResult) {
7894
7915
  }
7895
7916
  function getEnhancedGroupData(options, deepMapValue) {
7896
7917
  var _a;
7897
- const { groupBy, groupKeys, collapsed, parents, reducers, lazyLoad } = options;
7918
+ const { groupBy, groupKeys, parents, reducers, lazyLoad } = options;
7898
7919
  const groupNesting = groupKeys.length;
7899
7920
  const {
7900
7921
  items: groupItems,
@@ -7929,7 +7950,7 @@ function getEnhancedGroupData(options, deepMapValue) {
7929
7950
  selectedChildredCount: 0,
7930
7951
  deselectedChildredCount: 0,
7931
7952
  id: `${groupKeys}`,
7932
- collapsed,
7953
+ collapsed: false,
7933
7954
  dataSourceHasGrouping: true,
7934
7955
  selfLoaded,
7935
7956
  error: options.error,
@@ -7988,7 +8009,7 @@ function enhancedFlatten(param) {
7988
8009
  var _a, _b;
7989
8010
  const items = deepMapValue.items;
7990
8011
  const groupNesting = groupKeys.length;
7991
- const collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
8012
+ let collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
7992
8013
  indexInParentGroups.push(indexInGroup);
7993
8014
  const enhancedGroupData = getEnhancedGroupData({
7994
8015
  lazyLoad,
@@ -8001,11 +8022,10 @@ function enhancedFlatten(param) {
8001
8022
  groupKeys,
8002
8023
  error: deepMapValue.error,
8003
8024
  totalChildrenCount: deepMapValue.totalChildrenCount,
8004
- childrenLoading: deepMapValue.childrenLoading,
8025
+ childrenLoading: (deepMapValue.childrenLoading || !collapsed && !deepMapValue.childrenAvailable) && lazyLoad,
8005
8026
  childrenAvailable: deepMapValue.childrenAvailable,
8006
8027
  directChildrenCount: groupKeys.length === groupByStrings.length ? deepMapValue.items.length : deepMap.getDirectChildrenSizeFor(groupKeys),
8007
- directChildrenLoadedCount: 0,
8008
- collapsed
8028
+ directChildrenLoadedCount: 0
8009
8029
  }, deepMapValue);
8010
8030
  if (isRowSelected) {
8011
8031
  enhancedGroupData.rowSelected = isRowSelected(enhancedGroupData);
@@ -8017,6 +8037,10 @@ function enhancedFlatten(param) {
8017
8037
  }
8018
8038
  const parent = parents[parents.length - 1];
8019
8039
  const parentCollapsed = (_b = parent == null ? void 0 : parent.collapsed) != null ? _b : false;
8040
+ if (parentCollapsed) {
8041
+ collapsed = true;
8042
+ }
8043
+ enhancedGroupData.collapsed = collapsed;
8020
8044
  let include = generateGroupRows || collapsed;
8021
8045
  if (parentCollapsed) {
8022
8046
  include = false;
@@ -8024,27 +8048,16 @@ function enhancedFlatten(param) {
8024
8048
  if (include) {
8025
8049
  result.push(enhancedGroupData);
8026
8050
  }
8027
- if (collapsed) {
8028
- enhancedGroupData.collapsedChildrenCount = enhancedGroupData.groupCount;
8029
- parents.forEach((parent2) => {
8030
- if (!parentCollapsed) {
8031
- parent2.deepRowInfoArray.push(enhancedGroupData);
8032
- }
8033
- parent2.collapsedChildrenCount += enhancedGroupData.groupCount;
8034
- parent2.collapsedGroupsCount += 1;
8035
- });
8036
- } else {
8037
- if (!parentCollapsed) {
8038
- parents.forEach((parent2) => {
8039
- parent2.deepRowInfoArray.push(enhancedGroupData);
8040
- });
8041
- }
8042
- }
8051
+ enhancedGroupData.collapsedChildrenCount = 0;
8052
+ parents.forEach((parent2) => {
8053
+ parent2.deepRowInfoArray.push(enhancedGroupData);
8054
+ parent2.collapsedGroupsCount += collapsed ? 1 : 0;
8055
+ });
8043
8056
  if (parent && enhancedGroupData.selfLoaded && lazyLoad) {
8044
8057
  parent.directChildrenLoadedCount += 1;
8045
8058
  }
8046
8059
  parents.push(enhancedGroupData);
8047
- const continueWithChildren = !collapsed || lazyLoad;
8060
+ const continueWithChildren = true;
8048
8061
  if (continueWithChildren) {
8049
8062
  if (!next) {
8050
8063
  if (!pivot) {
@@ -8082,9 +8095,10 @@ function enhancedFlatten(param) {
8082
8095
  if (last && item) {
8083
8096
  parent2.directChildrenLoadedCount += 1;
8084
8097
  }
8085
- if (!parentCollapsed) {
8086
- parent2.deepRowInfoArray.push(rowInfo);
8098
+ if (collapsed) {
8099
+ parent2.collapsedChildrenCount += 1;
8087
8100
  }
8101
+ parent2.deepRowInfoArray.push(rowInfo);
8088
8102
  });
8089
8103
  if (!collapsed) {
8090
8104
  result[startIndex + index] = rowInfo;
@@ -8753,8 +8767,10 @@ function useLazyLoadRange() {
8753
8767
  const {
8754
8768
  lazyLoadBatchSize,
8755
8769
  lazyLoad,
8770
+ originalLazyGroupDataChangeDetect,
8756
8771
  notifyRenderRangeChange,
8757
8772
  dataArray,
8773
+ groupRowsState,
8758
8774
  scrollStopDelayUpdatedByTable
8759
8775
  } = componentState;
8760
8776
  const latestRenderRangeRef = useRef18(null);
@@ -8783,20 +8799,27 @@ function useLazyLoadRange() {
8783
8799
  }, cache);
8784
8800
  };
8785
8801
  const debouncedLoadRange = useMemo7(() => debounce(loadRange, { wait: scrollStopDelayUpdatedByTable }), [scrollStopDelayUpdatedByTable]);
8786
- useEffect17(() => {
8802
+ useEffectWithChanges((changes) => {
8787
8803
  if (lazyLoad) {
8804
+ if (changes.originalLazyGroupDataChangeDetect || changes.groupRowsState) {
8805
+ loadRange(notifyRenderRangeChange.get());
8806
+ }
8788
8807
  return notifyRenderRangeChange.onChange((renderRange) => {
8789
8808
  latestRenderRangeRef.current = renderRange;
8790
8809
  loadRange(renderRange);
8791
8810
  });
8792
8811
  }
8793
8812
  return;
8794
- }, [lazyLoadBatchSize, lazyLoad]);
8813
+ }, {
8814
+ lazyLoadBatchSize,
8815
+ lazyLoad,
8816
+ originalLazyGroupDataChangeDetect,
8817
+ groupRowsState
8818
+ });
8795
8819
  useEffect17(() => {
8796
8820
  if (lazyLoadBatchSize && lazyLoadBatchSize > 0) {
8797
8821
  debouncedLoadRange();
8798
8822
  }
8799
- return;
8800
8823
  }, [dataArray]);
8801
8824
  }
8802
8825
  function lazyLoadRange(options, cache) {
@@ -8894,11 +8917,16 @@ var RowSelectionState = class {
8894
8917
  this.defaultSelection = false;
8895
8918
  this.selectedMap = new DeepMap();
8896
8919
  this.deselectedMap = new DeepMap();
8920
+ this.onlyUsePrimaryKeys = false;
8897
8921
  this.selectionCache = new DeepMap();
8898
8922
  this.selectionCountCache = new DeepMap();
8899
8923
  this.mapSet = (name, key) => {
8900
8924
  if (!Array.isArray(key)) {
8901
- key = [...this.getGroupKeysForPrimaryKey(key), key];
8925
+ if (this.onlyUsePrimaryKeys) {
8926
+ key = [key];
8927
+ } else {
8928
+ key = [...this.getGroupKeysForPrimaryKey(key), key];
8929
+ }
8902
8930
  }
8903
8931
  this.xcache();
8904
8932
  if (name === "selected") {
@@ -8915,6 +8943,7 @@ var RowSelectionState = class {
8915
8943
  };
8916
8944
  const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? state.getState() : state;
8917
8945
  this.getConfig = getConfig;
8946
+ this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
8918
8947
  if (_forTestingOnly) {
8919
8948
  Object.assign(this, _forTestingOnly);
8920
8949
  }
@@ -8944,6 +8973,15 @@ var RowSelectionState = class {
8944
8973
  const { groupDeepMap } = this.getConfig();
8945
8974
  return (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith(groupKeys, true, 1)) || [];
8946
8975
  }
8976
+ getAllPrimaryKeysInsideGroup(groupKeys) {
8977
+ const { groupDeepMap } = this.getConfig();
8978
+ if (!groupKeys.length) {
8979
+ const topLevelKeys = (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith([], true, 1)) || [];
8980
+ return topLevelKeys.map((groupKeys2) => this.getAllPrimaryKeysInsideGroup(groupKeys2)).flat();
8981
+ }
8982
+ const group2 = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
8983
+ return group2 ? group2.items.map(this.getConfig().toPrimaryKey) : [];
8984
+ }
8947
8985
  getGroupByLength() {
8948
8986
  return this.getConfig().groupBy.length;
8949
8987
  }
@@ -8968,7 +9006,12 @@ var RowSelectionState = class {
8968
9006
  getState() {
8969
9007
  const normalize = (allKeys) => {
8970
9008
  const groupByLength = this.getGroupByLength();
8971
- return allKeys.map((keys) => keys.length > groupByLength ? keys.pop() : keys);
9009
+ return allKeys.map((keys) => {
9010
+ if (this.onlyUsePrimaryKeys) {
9011
+ return keys[0];
9012
+ }
9013
+ return keys.length > groupByLength ? keys.pop() : keys;
9014
+ });
8972
9015
  };
8973
9016
  const selectedRows = normalize(this.selectedMap.topDownKeys());
8974
9017
  const deselectedRows = normalize(this.deselectedMap.topDownKeys());
@@ -8999,6 +9042,9 @@ var RowSelectionState = class {
8999
9042
  return this.defaultSelection === false;
9000
9043
  }
9001
9044
  isRowSelected(key, groupKeys) {
9045
+ if (this.onlyUsePrimaryKeys) {
9046
+ return this.defaultSelection ? !this.deselectedMap.has([key]) : this.selectedMap.has([key]);
9047
+ }
9002
9048
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9003
9049
  const finalKey = [...groupKeys, key];
9004
9050
  const cachedResult = this.selectionCache.get(finalKey);
@@ -9055,7 +9101,7 @@ var RowSelectionState = class {
9055
9101
  if (cachedResult !== void 0) {
9056
9102
  return cachedResult;
9057
9103
  }
9058
- const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
9104
+ const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.onlyUsePrimaryKeys ? void 0 : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
9059
9105
  const result = selectedCount && deselectedCount ? null : selectedCount ? true : false;
9060
9106
  this.selectionCache.set(initialGroupKeys, result);
9061
9107
  return result;
@@ -9096,28 +9142,67 @@ var RowSelectionState = class {
9096
9142
  return this.getGroupRowSelectionState(groupKeys) === false;
9097
9143
  }
9098
9144
  selectGroupRow(groupKeys) {
9145
+ if (this.onlyUsePrimaryKeys) {
9146
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9147
+ keys.forEach((key) => {
9148
+ if (this.defaultSelection === true) {
9149
+ this.deselectedMap.delete([key]);
9150
+ } else {
9151
+ this._selectedMapSet(key);
9152
+ }
9153
+ });
9154
+ this.xcache();
9155
+ return;
9156
+ }
9099
9157
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
9100
9158
  selectedKeys.forEach((groupKeys2) => {
9101
9159
  this.selectedMap.delete(groupKeys2);
9102
9160
  });
9103
- this._selectedMapSet(groupKeys);
9161
+ if (groupKeys.length === 1 && this.defaultSelection === true) {
9162
+ } else {
9163
+ this._selectedMapSet(groupKeys);
9164
+ }
9104
9165
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
9105
9166
  deselectedKeys.forEach((groupKeys2) => {
9106
9167
  this.deselectedMap.delete(groupKeys2);
9107
9168
  });
9108
9169
  }
9109
9170
  deselectGroupRow(groupKeys) {
9171
+ if (this.onlyUsePrimaryKeys) {
9172
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9173
+ keys.forEach((key) => {
9174
+ if (this.defaultSelection === false) {
9175
+ this.selectedMap.delete([key]);
9176
+ } else {
9177
+ this._deselectedMapSet(key);
9178
+ }
9179
+ });
9180
+ this.xcache();
9181
+ return;
9182
+ }
9110
9183
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys, true);
9111
9184
  deselectedKeys.forEach((groupKeys2) => {
9112
9185
  this.deselectedMap.delete(groupKeys2);
9113
9186
  });
9114
- this._deselectedMapSet(groupKeys);
9187
+ if (groupKeys.length === 1 && this.defaultSelection === false) {
9188
+ } else {
9189
+ this._deselectedMapSet(groupKeys);
9190
+ }
9115
9191
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
9116
9192
  selectedKeys.forEach((groupKeys2) => {
9117
9193
  this.selectedMap.delete(groupKeys2);
9118
9194
  });
9119
9195
  }
9120
9196
  setRowAsSelected(key, groupKeys) {
9197
+ if (this.onlyUsePrimaryKeys) {
9198
+ if (this.defaultSelection) {
9199
+ this.deselectedMap.delete([key]);
9200
+ } else {
9201
+ this._selectedMapSet(key);
9202
+ }
9203
+ this.xcache();
9204
+ return;
9205
+ }
9121
9206
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9122
9207
  const finalKey = [...groupKeys, key];
9123
9208
  this.deselectedMap.delete(finalKey);
@@ -9130,9 +9215,19 @@ var RowSelectionState = class {
9130
9215
  }
9131
9216
  }
9132
9217
  setRowAsDeselected(key, groupKeys) {
9218
+ if (this.onlyUsePrimaryKeys) {
9219
+ if (this.defaultSelection) {
9220
+ this._deselectedMapSet(key);
9221
+ } else {
9222
+ this.selectedMap.delete([key]);
9223
+ }
9224
+ this.xcache();
9225
+ return;
9226
+ }
9133
9227
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9134
9228
  const finalKey = [...groupKeys, key];
9135
9229
  this.selectedMap.delete(finalKey);
9230
+ this.xcache();
9136
9231
  if (this.getGroupRowSelectionState(groupKeys) !== false) {
9137
9232
  this._deselectedMapSet(finalKey);
9138
9233
  if (this.getGroupRowSelectionState(groupKeys) === false) {
@@ -9173,7 +9268,8 @@ var RowSelectionState = class {
9173
9268
  if (cachedResult != null) {
9174
9269
  return cachedResult;
9175
9270
  }
9176
- if (groupKeys.length > this.getGroupByLength()) {
9271
+ const groupByLength = this.getGroupByLength();
9272
+ if (groupKeys.length > groupByLength) {
9177
9273
  const result2 = this.isRowSelected(groupKeys) ? { selectedCount: 1, deselectedCount: 0 } : {
9178
9274
  selectedCount: 0,
9179
9275
  deselectedCount: 1
@@ -9181,6 +9277,32 @@ var RowSelectionState = class {
9181
9277
  this.selectionCountCache.set(groupKeys, result2);
9182
9278
  return result2;
9183
9279
  }
9280
+ if (groupByLength && this.onlyUsePrimaryKeys) {
9281
+ const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
9282
+ let selectedCount2 = 0;
9283
+ let deselectedCount2 = 0;
9284
+ allKeys2.forEach((key) => {
9285
+ if (this.defaultSelection) {
9286
+ if (this.deselectedMap.has([key])) {
9287
+ deselectedCount2++;
9288
+ return;
9289
+ }
9290
+ selectedCount2++;
9291
+ } else {
9292
+ if (this.selectedMap.has([key])) {
9293
+ selectedCount2++;
9294
+ return;
9295
+ }
9296
+ deselectedCount2++;
9297
+ }
9298
+ });
9299
+ const result2 = {
9300
+ selectedCount: selectedCount2,
9301
+ deselectedCount: deselectedCount2
9302
+ };
9303
+ this.selectionCountCache.set(groupKeys, result2);
9304
+ return result2;
9305
+ }
9184
9306
  parentSelected = parentSelected != null ? parentSelected : this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
9185
9307
  let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
9186
9308
  if (groupKeys.length === this.getGroupByLength()) {
@@ -9237,6 +9359,8 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
9237
9359
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
9238
9360
  return {
9239
9361
  lazyLoad: !!state.lazyLoad,
9362
+ toPrimaryKey: state.toPrimaryKey,
9363
+ onlyUsePrimaryKeys: !state.useGroupKeysForMultiRowSelection,
9240
9364
  groupBy: state.groupBy,
9241
9365
  groupDeepMap: state.groupDeepMap,
9242
9366
  indexer: state.indexer,
@@ -9391,18 +9515,20 @@ function getSelectionApi(param) {
9391
9515
  rowSelectionState.toggleGroupRowSelection(groupKeys);
9392
9516
  dataSourceActions.rowSelection = rowSelectionState;
9393
9517
  },
9394
- getGroupRowSelectionState(groupKeys) {
9395
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
9518
+ getGroupRowSelectionState(groupKeys, rowSelection) {
9519
+ const state = getDataSourceState();
9520
+ const { selectionMode, groupBy } = state;
9521
+ const rowSelectionState = rowSelection ? new RowSelectionState(rowSelection, rowSelectionStateConfigGetter(state)) : state.rowSelection;
9396
9522
  if (selectionMode !== "multi-row") {
9397
9523
  throw 'Selection mode should be "multi-row"';
9398
9524
  }
9399
9525
  if (!groupBy) {
9400
9526
  throw "No grouping specified";
9401
9527
  }
9402
- if (!(rowSelection instanceof RowSelectionState)) {
9528
+ if (!(rowSelectionState instanceof RowSelectionState)) {
9403
9529
  throw "Invalid row selection";
9404
9530
  }
9405
- return rowSelection.getGroupRowSelectionState(groupKeys);
9531
+ return rowSelectionState.getGroupRowSelectionState(groupKeys);
9406
9532
  },
9407
9533
  getSelectedPrimaryKeys: (rowSelection) => {
9408
9534
  const state = getDataSourceState();
@@ -9556,6 +9682,7 @@ var forwardProps3 = (setupState) => {
9556
9682
  livePagination: 1,
9557
9683
  filterFunction: 1,
9558
9684
  filterValue: 1,
9685
+ useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) => useGroupKeysForMultiRowSelection != null ? useGroupKeysForMultiRowSelection : false,
9559
9686
  filterDelay: (filterDelay) => filterDelay != null ? filterDelay : 200,
9560
9687
  filterTypes: (filterTypes) => {
9561
9688
  return __spreadValues(__spreadValues({}, defaultFilterTypes), filterTypes);
@@ -9569,16 +9696,7 @@ var forwardProps3 = (setupState) => {
9569
9696
  collapseGroupRowsOnDataFunctionChange: (collapseGroupRowsOnDataFunctionChange) => collapseGroupRowsOnDataFunctionChange != null ? collapseGroupRowsOnDataFunctionChange : true,
9570
9697
  loading: (loading) => loading != null ? loading : false,
9571
9698
  sortInfo: (sortInfo) => normalizeSortInfo(sortInfo, setupState.propsCache.get("sortInfo")),
9572
- groupBy: (groupBy) => groupBy != null ? groupBy : [],
9573
- groupRowsState: (groupRowsState) => {
9574
- if (groupRowsState && !(groupRowsState instanceof GroupRowsState)) {
9575
- groupRowsState = new GroupRowsState(groupRowsState);
9576
- }
9577
- return groupRowsState || new GroupRowsState({
9578
- expandedRows: true,
9579
- collapsedRows: []
9580
- });
9581
- }
9699
+ groupBy: (groupBy) => groupBy != null ? groupBy : []
9582
9700
  };
9583
9701
  };
9584
9702
  function getLivePaginationCursorValue(livePaginationCursorProp, state) {
@@ -9637,8 +9755,17 @@ function mapPropsToState(params) {
9637
9755
  }
9638
9756
  const primaryKeyDescriptor = state.primaryKey;
9639
9757
  const toPrimaryKey = typeof primaryKeyDescriptor === "function" ? (data) => primaryKeyDescriptor(data) : (data) => data[primaryKeyDescriptor];
9758
+ let groupRowsState = props.groupRowsState || state.groupRowsState || props.defaultGroupRowsState;
9759
+ if (groupRowsState && !(groupRowsState instanceof GroupRowsState)) {
9760
+ groupRowsState = new GroupRowsState(groupRowsState);
9761
+ }
9762
+ groupRowsState = groupRowsState || new GroupRowsState(state.lazyLoad ? { expandedRows: [], collapsedRows: true } : {
9763
+ expandedRows: true,
9764
+ collapsedRows: []
9765
+ });
9640
9766
  const result = {
9641
9767
  selectionMode,
9768
+ groupRowsState,
9642
9769
  rowSelection: rowSelectionState,
9643
9770
  toPrimaryKey,
9644
9771
  operatorsByFilterType,
@@ -10644,7 +10771,8 @@ function useCellRendering(param) {
10644
10771
  rowClassName,
10645
10772
  onScrollToTop,
10646
10773
  onScrollToBottom,
10647
- scrollToBottomOffset
10774
+ scrollToBottomOffset,
10775
+ ready
10648
10776
  } = componentState;
10649
10777
  const repaintId = dataSourceState.updatedAt;
10650
10778
  useYourBrain({
@@ -10685,12 +10813,16 @@ function useCellRendering(param) {
10685
10813
  if (!bodySize.height) {
10686
10814
  return;
10687
10815
  }
10688
- const { onReady } = getState();
10689
10816
  componentActions.ready = true;
10817
+ }, [!!bodySize.height]);
10818
+ useEffect19(() => {
10819
+ if (!ready) {
10820
+ }
10821
+ const { onReady } = getState();
10690
10822
  if (onReady) {
10691
10823
  onReady(imperativeApi);
10692
10824
  }
10693
- }, [!!bodySize.height]);
10825
+ }, [ready]);
10694
10826
  const [, rerender] = useRerender();
10695
10827
  useEffect19(() => {
10696
10828
  rerender();
@@ -12382,7 +12514,7 @@ var useLicense = (licenseKey = "") => {
12382
12514
  const valid = useMemo11(() => {
12383
12515
  let valid2 = isValidLicense(licenseKey, {
12384
12516
  publishedAt: 1624970570587,
12385
- version: "0.4.8"
12517
+ version: "0.4.11"
12386
12518
  });
12387
12519
  if (!licenseKey && !valid2 && isInsidePlayground) {
12388
12520
  return true;
@@ -13301,3 +13433,4 @@ export {
13301
13433
  useInfiniteColumnCell,
13302
13434
  useInfiniteHeaderCell
13303
13435
  };
13436
+ //!collapsed || lazyLoad;
package/index.js CHANGED
@@ -4323,6 +4323,10 @@ function useCellClassName(column, baseClasses, variants, extraFlags) {
4323
4323
  if (extraFlags.rowSelected) {
4324
4324
  result.push(...baseClasses.map((c) => `${c}--row-selected`));
4325
4325
  }
4326
+ if (extraFlags.groupRow) {
4327
+ result.push(...baseClasses.map((c) => `${c}--group-row`));
4328
+ result.push(...baseClasses.map((c) => `${c}--${extraFlags.rowExpanded ? "group-row-expanded" : "group-row-collapsed"}`));
4329
+ }
4326
4330
  if (column.computedPinned) {
4327
4331
  result.push(...baseClasses.map((c) => `${c}--pinned-${column.computedPinned}`));
4328
4332
  } else {
@@ -5849,7 +5853,14 @@ function InfiniteTableColumnCellFn(props) {
5849
5853
  onClick,
5850
5854
  onMouseDown,
5851
5855
  cssEllipsis: (_a = column.cssEllipsis) != null ? _a : true,
5852
- className: join(useCellClassName(column, [InfiniteTableColumnCellClassName, InfiniteTableCellClassName], ColumnCellRecipe, { dragging: false, zebra, rowActive, rowSelected }), colClassName, rowComputedClassName),
5856
+ className: join(useCellClassName(column, [InfiniteTableColumnCellClassName, InfiniteTableCellClassName], ColumnCellRecipe, {
5857
+ dragging: false,
5858
+ zebra,
5859
+ rowActive,
5860
+ rowSelected,
5861
+ groupRow: rowInfo.isGroupRow,
5862
+ rowExpanded: rowInfo.isGroupRow ? !rowInfo.collapsed : false
5863
+ }), colClassName, rowComputedClassName),
5853
5864
  renderChildren
5854
5865
  };
5855
5866
  return /* @__PURE__ */ React21.createElement(InfiniteTableCell, __spreadValues({}, cellProps));
@@ -6886,7 +6897,9 @@ function InfiniteTableHeaderCell(props) {
6886
6897
  dragging,
6887
6898
  rowSelected: false,
6888
6899
  zebra: false,
6889
- rowActive: false
6900
+ rowActive: false,
6901
+ groupRow: false,
6902
+ rowExpanded: false
6890
6903
  }), CellCls),
6891
6904
  cssEllipsis: (_e = (_d = column.headerCssEllipsis) != null ? _d : column.cssEllipsis) != null ? _e : true,
6892
6905
  afterChildren: /* @__PURE__ */ React28.createElement(React28.Fragment, null, showColumnFilters ? column.computedFilterable ? /* @__PURE__ */ React28.createElement(InfiniteTableColumnHeaderFilter, {
@@ -7606,6 +7619,14 @@ function lazyGroup(groupParams, rootData) {
7606
7619
  if (currentGroupKeys.length == groupBy.length && groupBy.length) {
7607
7620
  if (current) {
7608
7621
  current.items = dataArray;
7622
+ for (let i = 0, len = currentGroupKeys.length; i < len; i++) {
7623
+ const currentKeys = currentGroupKeys.slice(0, i);
7624
+ const deepMapGroupValue = deepMap.get(currentKeys);
7625
+ if (deepMapGroupValue) {
7626
+ deepMapGroupValue.items = deepMapGroupValue.items || [];
7627
+ deepMapGroupValue.items = deepMapGroupValue.items.concat(dataArray);
7628
+ }
7629
+ }
7609
7630
  indexer.indexArray(dataArray, toPrimaryKey);
7610
7631
  }
7611
7632
  return next == null ? void 0 : next();
@@ -7626,7 +7647,7 @@ function lazyGroup(groupParams, rootData) {
7626
7647
  continue;
7627
7648
  }
7628
7649
  const dataObject = dataArray[i].data;
7629
- const dataKeys = dataArray[i].keys;
7650
+ const dataKeys = dataArray[i].keys || [];
7630
7651
  if (dataKeys.length) {
7631
7652
  const key = dataKeys[dataKeys.length - 1];
7632
7653
  currentGroupKeys.push(key);
@@ -7804,7 +7825,7 @@ function flatten(groupResult) {
7804
7825
  }
7805
7826
  function getEnhancedGroupData(options, deepMapValue) {
7806
7827
  var _a;
7807
- const { groupBy, groupKeys, collapsed, parents, reducers, lazyLoad } = options;
7828
+ const { groupBy, groupKeys, parents, reducers, lazyLoad } = options;
7808
7829
  const groupNesting = groupKeys.length;
7809
7830
  const {
7810
7831
  items: groupItems,
@@ -7839,7 +7860,7 @@ function getEnhancedGroupData(options, deepMapValue) {
7839
7860
  selectedChildredCount: 0,
7840
7861
  deselectedChildredCount: 0,
7841
7862
  id: `${groupKeys}`,
7842
- collapsed,
7863
+ collapsed: false,
7843
7864
  dataSourceHasGrouping: true,
7844
7865
  selfLoaded,
7845
7866
  error: options.error,
@@ -7898,7 +7919,7 @@ function enhancedFlatten(param) {
7898
7919
  var _a, _b;
7899
7920
  const items = deepMapValue.items;
7900
7921
  const groupNesting = groupKeys.length;
7901
- const collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
7922
+ let collapsed = (_a = groupRowsState == null ? void 0 : groupRowsState.isGroupRowCollapsed(groupKeys)) != null ? _a : false;
7902
7923
  indexInParentGroups.push(indexInGroup);
7903
7924
  const enhancedGroupData = getEnhancedGroupData({
7904
7925
  lazyLoad,
@@ -7911,11 +7932,10 @@ function enhancedFlatten(param) {
7911
7932
  groupKeys,
7912
7933
  error: deepMapValue.error,
7913
7934
  totalChildrenCount: deepMapValue.totalChildrenCount,
7914
- childrenLoading: deepMapValue.childrenLoading,
7935
+ childrenLoading: (deepMapValue.childrenLoading || !collapsed && !deepMapValue.childrenAvailable) && lazyLoad,
7915
7936
  childrenAvailable: deepMapValue.childrenAvailable,
7916
7937
  directChildrenCount: groupKeys.length === groupByStrings.length ? deepMapValue.items.length : deepMap.getDirectChildrenSizeFor(groupKeys),
7917
- directChildrenLoadedCount: 0,
7918
- collapsed
7938
+ directChildrenLoadedCount: 0
7919
7939
  }, deepMapValue);
7920
7940
  if (isRowSelected) {
7921
7941
  enhancedGroupData.rowSelected = isRowSelected(enhancedGroupData);
@@ -7927,6 +7947,10 @@ function enhancedFlatten(param) {
7927
7947
  }
7928
7948
  const parent = parents[parents.length - 1];
7929
7949
  const parentCollapsed = (_b = parent == null ? void 0 : parent.collapsed) != null ? _b : false;
7950
+ if (parentCollapsed) {
7951
+ collapsed = true;
7952
+ }
7953
+ enhancedGroupData.collapsed = collapsed;
7930
7954
  let include = generateGroupRows || collapsed;
7931
7955
  if (parentCollapsed) {
7932
7956
  include = false;
@@ -7934,27 +7958,16 @@ function enhancedFlatten(param) {
7934
7958
  if (include) {
7935
7959
  result.push(enhancedGroupData);
7936
7960
  }
7937
- if (collapsed) {
7938
- enhancedGroupData.collapsedChildrenCount = enhancedGroupData.groupCount;
7939
- parents.forEach((parent2) => {
7940
- if (!parentCollapsed) {
7941
- parent2.deepRowInfoArray.push(enhancedGroupData);
7942
- }
7943
- parent2.collapsedChildrenCount += enhancedGroupData.groupCount;
7944
- parent2.collapsedGroupsCount += 1;
7945
- });
7946
- } else {
7947
- if (!parentCollapsed) {
7948
- parents.forEach((parent2) => {
7949
- parent2.deepRowInfoArray.push(enhancedGroupData);
7950
- });
7951
- }
7952
- }
7961
+ enhancedGroupData.collapsedChildrenCount = 0;
7962
+ parents.forEach((parent2) => {
7963
+ parent2.deepRowInfoArray.push(enhancedGroupData);
7964
+ parent2.collapsedGroupsCount += collapsed ? 1 : 0;
7965
+ });
7953
7966
  if (parent && enhancedGroupData.selfLoaded && lazyLoad) {
7954
7967
  parent.directChildrenLoadedCount += 1;
7955
7968
  }
7956
7969
  parents.push(enhancedGroupData);
7957
- const continueWithChildren = !collapsed || lazyLoad;
7970
+ const continueWithChildren = true;
7958
7971
  if (continueWithChildren) {
7959
7972
  if (!next) {
7960
7973
  if (!pivot) {
@@ -7992,9 +8005,10 @@ function enhancedFlatten(param) {
7992
8005
  if (last && item) {
7993
8006
  parent2.directChildrenLoadedCount += 1;
7994
8007
  }
7995
- if (!parentCollapsed) {
7996
- parent2.deepRowInfoArray.push(rowInfo);
8008
+ if (collapsed) {
8009
+ parent2.collapsedChildrenCount += 1;
7997
8010
  }
8011
+ parent2.deepRowInfoArray.push(rowInfo);
7998
8012
  });
7999
8013
  if (!collapsed) {
8000
8014
  result[startIndex + index] = rowInfo;
@@ -8660,8 +8674,10 @@ function useLazyLoadRange() {
8660
8674
  const {
8661
8675
  lazyLoadBatchSize,
8662
8676
  lazyLoad,
8677
+ originalLazyGroupDataChangeDetect,
8663
8678
  notifyRenderRangeChange,
8664
8679
  dataArray,
8680
+ groupRowsState,
8665
8681
  scrollStopDelayUpdatedByTable
8666
8682
  } = componentState;
8667
8683
  const latestRenderRangeRef = (0, import_react30.useRef)(null);
@@ -8690,20 +8706,27 @@ function useLazyLoadRange() {
8690
8706
  }, cache);
8691
8707
  };
8692
8708
  const debouncedLoadRange = (0, import_react30.useMemo)(() => debounce(loadRange, { wait: scrollStopDelayUpdatedByTable }), [scrollStopDelayUpdatedByTable]);
8693
- (0, import_react30.useEffect)(() => {
8709
+ useEffectWithChanges((changes) => {
8694
8710
  if (lazyLoad) {
8711
+ if (changes.originalLazyGroupDataChangeDetect || changes.groupRowsState) {
8712
+ loadRange(notifyRenderRangeChange.get());
8713
+ }
8695
8714
  return notifyRenderRangeChange.onChange((renderRange) => {
8696
8715
  latestRenderRangeRef.current = renderRange;
8697
8716
  loadRange(renderRange);
8698
8717
  });
8699
8718
  }
8700
8719
  return;
8701
- }, [lazyLoadBatchSize, lazyLoad]);
8720
+ }, {
8721
+ lazyLoadBatchSize,
8722
+ lazyLoad,
8723
+ originalLazyGroupDataChangeDetect,
8724
+ groupRowsState
8725
+ });
8702
8726
  (0, import_react30.useEffect)(() => {
8703
8727
  if (lazyLoadBatchSize && lazyLoadBatchSize > 0) {
8704
8728
  debouncedLoadRange();
8705
8729
  }
8706
- return;
8707
8730
  }, [dataArray]);
8708
8731
  }
8709
8732
  function lazyLoadRange(options, cache) {
@@ -8801,11 +8824,16 @@ var RowSelectionState = class {
8801
8824
  this.defaultSelection = false;
8802
8825
  this.selectedMap = new DeepMap();
8803
8826
  this.deselectedMap = new DeepMap();
8827
+ this.onlyUsePrimaryKeys = false;
8804
8828
  this.selectionCache = new DeepMap();
8805
8829
  this.selectionCountCache = new DeepMap();
8806
8830
  this.mapSet = (name, key) => {
8807
8831
  if (!Array.isArray(key)) {
8808
- key = [...this.getGroupKeysForPrimaryKey(key), key];
8832
+ if (this.onlyUsePrimaryKeys) {
8833
+ key = [key];
8834
+ } else {
8835
+ key = [...this.getGroupKeysForPrimaryKey(key), key];
8836
+ }
8809
8837
  }
8810
8838
  this.xcache();
8811
8839
  if (name === "selected") {
@@ -8822,6 +8850,7 @@ var RowSelectionState = class {
8822
8850
  };
8823
8851
  const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? state.getState() : state;
8824
8852
  this.getConfig = getConfig;
8853
+ this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
8825
8854
  if (_forTestingOnly) {
8826
8855
  Object.assign(this, _forTestingOnly);
8827
8856
  }
@@ -8851,6 +8880,15 @@ var RowSelectionState = class {
8851
8880
  const { groupDeepMap } = this.getConfig();
8852
8881
  return (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith(groupKeys, true, 1)) || [];
8853
8882
  }
8883
+ getAllPrimaryKeysInsideGroup(groupKeys) {
8884
+ const { groupDeepMap } = this.getConfig();
8885
+ if (!groupKeys.length) {
8886
+ const topLevelKeys = (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith([], true, 1)) || [];
8887
+ return topLevelKeys.map((groupKeys2) => this.getAllPrimaryKeysInsideGroup(groupKeys2)).flat();
8888
+ }
8889
+ const group2 = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
8890
+ return group2 ? group2.items.map(this.getConfig().toPrimaryKey) : [];
8891
+ }
8854
8892
  getGroupByLength() {
8855
8893
  return this.getConfig().groupBy.length;
8856
8894
  }
@@ -8875,7 +8913,12 @@ var RowSelectionState = class {
8875
8913
  getState() {
8876
8914
  const normalize = (allKeys) => {
8877
8915
  const groupByLength = this.getGroupByLength();
8878
- return allKeys.map((keys) => keys.length > groupByLength ? keys.pop() : keys);
8916
+ return allKeys.map((keys) => {
8917
+ if (this.onlyUsePrimaryKeys) {
8918
+ return keys[0];
8919
+ }
8920
+ return keys.length > groupByLength ? keys.pop() : keys;
8921
+ });
8879
8922
  };
8880
8923
  const selectedRows = normalize(this.selectedMap.topDownKeys());
8881
8924
  const deselectedRows = normalize(this.deselectedMap.topDownKeys());
@@ -8906,6 +8949,9 @@ var RowSelectionState = class {
8906
8949
  return this.defaultSelection === false;
8907
8950
  }
8908
8951
  isRowSelected(key, groupKeys) {
8952
+ if (this.onlyUsePrimaryKeys) {
8953
+ return this.defaultSelection ? !this.deselectedMap.has([key]) : this.selectedMap.has([key]);
8954
+ }
8909
8955
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
8910
8956
  const finalKey = [...groupKeys, key];
8911
8957
  const cachedResult = this.selectionCache.get(finalKey);
@@ -8962,7 +9008,7 @@ var RowSelectionState = class {
8962
9008
  if (cachedResult !== void 0) {
8963
9009
  return cachedResult;
8964
9010
  }
8965
- const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
9011
+ const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.onlyUsePrimaryKeys ? void 0 : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
8966
9012
  const result = selectedCount && deselectedCount ? null : selectedCount ? true : false;
8967
9013
  this.selectionCache.set(initialGroupKeys, result);
8968
9014
  return result;
@@ -9003,28 +9049,67 @@ var RowSelectionState = class {
9003
9049
  return this.getGroupRowSelectionState(groupKeys) === false;
9004
9050
  }
9005
9051
  selectGroupRow(groupKeys) {
9052
+ if (this.onlyUsePrimaryKeys) {
9053
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9054
+ keys.forEach((key) => {
9055
+ if (this.defaultSelection === true) {
9056
+ this.deselectedMap.delete([key]);
9057
+ } else {
9058
+ this._selectedMapSet(key);
9059
+ }
9060
+ });
9061
+ this.xcache();
9062
+ return;
9063
+ }
9006
9064
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
9007
9065
  selectedKeys.forEach((groupKeys2) => {
9008
9066
  this.selectedMap.delete(groupKeys2);
9009
9067
  });
9010
- this._selectedMapSet(groupKeys);
9068
+ if (groupKeys.length === 1 && this.defaultSelection === true) {
9069
+ } else {
9070
+ this._selectedMapSet(groupKeys);
9071
+ }
9011
9072
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
9012
9073
  deselectedKeys.forEach((groupKeys2) => {
9013
9074
  this.deselectedMap.delete(groupKeys2);
9014
9075
  });
9015
9076
  }
9016
9077
  deselectGroupRow(groupKeys) {
9078
+ if (this.onlyUsePrimaryKeys) {
9079
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9080
+ keys.forEach((key) => {
9081
+ if (this.defaultSelection === false) {
9082
+ this.selectedMap.delete([key]);
9083
+ } else {
9084
+ this._deselectedMapSet(key);
9085
+ }
9086
+ });
9087
+ this.xcache();
9088
+ return;
9089
+ }
9017
9090
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys, true);
9018
9091
  deselectedKeys.forEach((groupKeys2) => {
9019
9092
  this.deselectedMap.delete(groupKeys2);
9020
9093
  });
9021
- this._deselectedMapSet(groupKeys);
9094
+ if (groupKeys.length === 1 && this.defaultSelection === false) {
9095
+ } else {
9096
+ this._deselectedMapSet(groupKeys);
9097
+ }
9022
9098
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
9023
9099
  selectedKeys.forEach((groupKeys2) => {
9024
9100
  this.selectedMap.delete(groupKeys2);
9025
9101
  });
9026
9102
  }
9027
9103
  setRowAsSelected(key, groupKeys) {
9104
+ if (this.onlyUsePrimaryKeys) {
9105
+ if (this.defaultSelection) {
9106
+ this.deselectedMap.delete([key]);
9107
+ } else {
9108
+ this._selectedMapSet(key);
9109
+ }
9110
+ this.xcache();
9111
+ return;
9112
+ }
9028
9113
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9029
9114
  const finalKey = [...groupKeys, key];
9030
9115
  this.deselectedMap.delete(finalKey);
@@ -9037,9 +9122,19 @@ var RowSelectionState = class {
9037
9122
  }
9038
9123
  }
9039
9124
  setRowAsDeselected(key, groupKeys) {
9125
+ if (this.onlyUsePrimaryKeys) {
9126
+ if (this.defaultSelection) {
9127
+ this._deselectedMapSet(key);
9128
+ } else {
9129
+ this.selectedMap.delete([key]);
9130
+ }
9131
+ this.xcache();
9132
+ return;
9133
+ }
9040
9134
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9041
9135
  const finalKey = [...groupKeys, key];
9042
9136
  this.selectedMap.delete(finalKey);
9137
+ this.xcache();
9043
9138
  if (this.getGroupRowSelectionState(groupKeys) !== false) {
9044
9139
  this._deselectedMapSet(finalKey);
9045
9140
  if (this.getGroupRowSelectionState(groupKeys) === false) {
@@ -9080,7 +9175,8 @@ var RowSelectionState = class {
9080
9175
  if (cachedResult != null) {
9081
9176
  return cachedResult;
9082
9177
  }
9083
- if (groupKeys.length > this.getGroupByLength()) {
9178
+ const groupByLength = this.getGroupByLength();
9179
+ if (groupKeys.length > groupByLength) {
9084
9180
  const result2 = this.isRowSelected(groupKeys) ? { selectedCount: 1, deselectedCount: 0 } : {
9085
9181
  selectedCount: 0,
9086
9182
  deselectedCount: 1
@@ -9088,6 +9184,32 @@ var RowSelectionState = class {
9088
9184
  this.selectionCountCache.set(groupKeys, result2);
9089
9185
  return result2;
9090
9186
  }
9187
+ if (groupByLength && this.onlyUsePrimaryKeys) {
9188
+ const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
9189
+ let selectedCount2 = 0;
9190
+ let deselectedCount2 = 0;
9191
+ allKeys2.forEach((key) => {
9192
+ if (this.defaultSelection) {
9193
+ if (this.deselectedMap.has([key])) {
9194
+ deselectedCount2++;
9195
+ return;
9196
+ }
9197
+ selectedCount2++;
9198
+ } else {
9199
+ if (this.selectedMap.has([key])) {
9200
+ selectedCount2++;
9201
+ return;
9202
+ }
9203
+ deselectedCount2++;
9204
+ }
9205
+ });
9206
+ const result2 = {
9207
+ selectedCount: selectedCount2,
9208
+ deselectedCount: deselectedCount2
9209
+ };
9210
+ this.selectionCountCache.set(groupKeys, result2);
9211
+ return result2;
9212
+ }
9091
9213
  parentSelected = parentSelected != null ? parentSelected : this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
9092
9214
  let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
9093
9215
  if (groupKeys.length === this.getGroupByLength()) {
@@ -9144,6 +9266,8 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
9144
9266
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
9145
9267
  return {
9146
9268
  lazyLoad: !!state.lazyLoad,
9269
+ toPrimaryKey: state.toPrimaryKey,
9270
+ onlyUsePrimaryKeys: !state.useGroupKeysForMultiRowSelection,
9147
9271
  groupBy: state.groupBy,
9148
9272
  groupDeepMap: state.groupDeepMap,
9149
9273
  indexer: state.indexer,
@@ -9298,18 +9422,20 @@ function getSelectionApi(param) {
9298
9422
  rowSelectionState.toggleGroupRowSelection(groupKeys);
9299
9423
  dataSourceActions.rowSelection = rowSelectionState;
9300
9424
  },
9301
- getGroupRowSelectionState(groupKeys) {
9302
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
9425
+ getGroupRowSelectionState(groupKeys, rowSelection) {
9426
+ const state = getDataSourceState();
9427
+ const { selectionMode, groupBy } = state;
9428
+ const rowSelectionState = rowSelection ? new RowSelectionState(rowSelection, rowSelectionStateConfigGetter(state)) : state.rowSelection;
9303
9429
  if (selectionMode !== "multi-row") {
9304
9430
  throw 'Selection mode should be "multi-row"';
9305
9431
  }
9306
9432
  if (!groupBy) {
9307
9433
  throw "No grouping specified";
9308
9434
  }
9309
- if (!(rowSelection instanceof RowSelectionState)) {
9435
+ if (!(rowSelectionState instanceof RowSelectionState)) {
9310
9436
  throw "Invalid row selection";
9311
9437
  }
9312
- return rowSelection.getGroupRowSelectionState(groupKeys);
9438
+ return rowSelectionState.getGroupRowSelectionState(groupKeys);
9313
9439
  },
9314
9440
  getSelectedPrimaryKeys: (rowSelection) => {
9315
9441
  const state = getDataSourceState();
@@ -9463,6 +9589,7 @@ var forwardProps3 = (setupState) => {
9463
9589
  livePagination: 1,
9464
9590
  filterFunction: 1,
9465
9591
  filterValue: 1,
9592
+ useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) => useGroupKeysForMultiRowSelection != null ? useGroupKeysForMultiRowSelection : false,
9466
9593
  filterDelay: (filterDelay) => filterDelay != null ? filterDelay : 200,
9467
9594
  filterTypes: (filterTypes) => {
9468
9595
  return __spreadValues(__spreadValues({}, defaultFilterTypes), filterTypes);
@@ -9476,16 +9603,7 @@ var forwardProps3 = (setupState) => {
9476
9603
  collapseGroupRowsOnDataFunctionChange: (collapseGroupRowsOnDataFunctionChange) => collapseGroupRowsOnDataFunctionChange != null ? collapseGroupRowsOnDataFunctionChange : true,
9477
9604
  loading: (loading) => loading != null ? loading : false,
9478
9605
  sortInfo: (sortInfo) => normalizeSortInfo(sortInfo, setupState.propsCache.get("sortInfo")),
9479
- groupBy: (groupBy) => groupBy != null ? groupBy : [],
9480
- groupRowsState: (groupRowsState) => {
9481
- if (groupRowsState && !(groupRowsState instanceof GroupRowsState)) {
9482
- groupRowsState = new GroupRowsState(groupRowsState);
9483
- }
9484
- return groupRowsState || new GroupRowsState({
9485
- expandedRows: true,
9486
- collapsedRows: []
9487
- });
9488
- }
9606
+ groupBy: (groupBy) => groupBy != null ? groupBy : []
9489
9607
  };
9490
9608
  };
9491
9609
  function getLivePaginationCursorValue(livePaginationCursorProp, state) {
@@ -9544,8 +9662,17 @@ function mapPropsToState(params) {
9544
9662
  }
9545
9663
  const primaryKeyDescriptor = state.primaryKey;
9546
9664
  const toPrimaryKey = typeof primaryKeyDescriptor === "function" ? (data) => primaryKeyDescriptor(data) : (data) => data[primaryKeyDescriptor];
9665
+ let groupRowsState = props.groupRowsState || state.groupRowsState || props.defaultGroupRowsState;
9666
+ if (groupRowsState && !(groupRowsState instanceof GroupRowsState)) {
9667
+ groupRowsState = new GroupRowsState(groupRowsState);
9668
+ }
9669
+ groupRowsState = groupRowsState || new GroupRowsState(state.lazyLoad ? { expandedRows: [], collapsedRows: true } : {
9670
+ expandedRows: true,
9671
+ collapsedRows: []
9672
+ });
9547
9673
  const result = {
9548
9674
  selectionMode,
9675
+ groupRowsState,
9549
9676
  rowSelection: rowSelectionState,
9550
9677
  toPrimaryKey,
9551
9678
  operatorsByFilterType,
@@ -10545,7 +10672,8 @@ function useCellRendering(param) {
10545
10672
  rowClassName,
10546
10673
  onScrollToTop,
10547
10674
  onScrollToBottom,
10548
- scrollToBottomOffset
10675
+ scrollToBottomOffset,
10676
+ ready
10549
10677
  } = componentState;
10550
10678
  const repaintId = dataSourceState.updatedAt;
10551
10679
  useYourBrain({
@@ -10586,12 +10714,16 @@ function useCellRendering(param) {
10586
10714
  if (!bodySize.height) {
10587
10715
  return;
10588
10716
  }
10589
- const { onReady } = getState();
10590
10717
  componentActions.ready = true;
10718
+ }, [!!bodySize.height]);
10719
+ (0, import_react32.useEffect)(() => {
10720
+ if (!ready) {
10721
+ }
10722
+ const { onReady } = getState();
10591
10723
  if (onReady) {
10592
10724
  onReady(imperativeApi);
10593
10725
  }
10594
- }, [!!bodySize.height]);
10726
+ }, [ready]);
10595
10727
  const [, rerender] = useRerender();
10596
10728
  (0, import_react32.useEffect)(() => {
10597
10729
  rerender();
@@ -12283,7 +12415,7 @@ var useLicense = (licenseKey = "") => {
12283
12415
  const valid = (0, import_react44.useMemo)(() => {
12284
12416
  let valid2 = isValidLicense(licenseKey, {
12285
12417
  publishedAt: 1624970570587,
12286
- version: "0.4.8"
12418
+ version: "0.4.11"
12287
12419
  });
12288
12420
  if (!licenseKey && !valid2 && isInsidePlayground) {
12289
12421
  return true;
@@ -13176,3 +13308,4 @@ var components = {
13176
13308
  CheckBox: InfiniteCheckBox,
13177
13309
  LoadMask
13178
13310
  };
13311
+ //!collapsed || lazyLoad;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@infinite-table/infinite-react",
3
3
  "description": "Infinite Table for React",
4
- "version": "0.4.8",
4
+ "version": "0.4.11",
5
5
  "main": "index.js",
6
6
  "module": "index.esm.js",
7
7
  "typings": "index.d.ts",
@@ -14,5 +14,5 @@
14
14
  },
15
15
  "license": "Commercial & Open Source",
16
16
  "//": "will be updated at build time",
17
- "publishedAt": 1660912348938
17
+ "publishedAt": 1661872202933
18
18
  }