@infinite-table/infinite-react 0.4.6 → 0.4.9

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 +136 -21
  3. package/index.js +136 -21
  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
+ usePrimaryKeysForMultiRowSelection: NonUndefined<DataSourceProps<T>['usePrimaryKeysForMultiRowSelection']>;
1158
1164
  onDataParamsChange: DataSourceProps<T>['onDataParamsChange'];
1159
1165
  data: DataSourceProps<T>['data'];
1160
1166
  sortMode: DataSourceProps<T>['sortMode'];
@@ -1267,6 +1273,7 @@ declare type DataSourceProps<T> = {
1267
1273
  fields?: (keyof T)[];
1268
1274
  data: DataSourceData<T>;
1269
1275
  selectionMode?: DataSourcePropSelectionMode;
1276
+ usePrimaryKeysForMultiRowSelection?: boolean;
1270
1277
  rowSelection?: DataSourcePropRowSelection_MultiRow | DataSourcePropRowSelection_SingleRow;
1271
1278
  defaultRowSelection?: DataSourcePropRowSelection_MultiRow | DataSourcePropRowSelection_SingleRow;
1272
1279
  cellSelection?: DataSourcePropCellSelection;
@@ -1703,7 +1710,7 @@ declare type InfiniteTableSelectionApi = {
1703
1710
  deselectGroupRow(groupKeys: any[], children?: ArrayOfIds): void;
1704
1711
  toggleGroupRowSelection(groupKeys: any[], children?: ArrayOfIds): void;
1705
1712
  getGroupRowSelectionState(groupKeys: any[]): boolean | null;
1706
- getSelectedPrimaryKeys(): (string | number)[];
1713
+ getSelectedPrimaryKeys(rowSelection?: RowSelectionStateObject): (string | number)[];
1707
1714
  selectAll(): void;
1708
1715
  deselectAll(): void;
1709
1716
  };
package/index.esm.js CHANGED
@@ -6785,6 +6785,7 @@ function InfiniteTableHeaderCell(props) {
6785
6785
  };
6786
6786
  const align = column.align || "start";
6787
6787
  const renderChildren = () => {
6788
+ var _a2;
6788
6789
  if (column.renderSortIcon) {
6789
6790
  renderParam.renderBag.sortIcon = /* @__PURE__ */ createElement25(RenderHeaderCellHookComponent, {
6790
6791
  render: column.renderSortIcon,
@@ -6798,9 +6799,10 @@ function InfiniteTableHeaderCell(props) {
6798
6799
  render: defaultRenderSelectionCheckBox2,
6799
6800
  renderParam
6800
6801
  });
6801
- if (column.renderHeaderSelectionCheckBox && column.renderHeaderSelectionCheckBox !== true) {
6802
+ const renderHeaderSelectionCheckBox = (_a2 = column.renderHeaderSelectionCheckBox) != null ? _a2 : column.renderSelectionCheckBox;
6803
+ if (renderHeaderSelectionCheckBox && renderHeaderSelectionCheckBox !== true) {
6802
6804
  renderParam.renderBag.selectionCheckBox = /* @__PURE__ */ createElement25(RenderHeaderCellHookComponent, {
6803
- render: column.renderHeaderSelectionCheckBox,
6805
+ render: renderHeaderSelectionCheckBox,
6804
6806
  renderParam: __spreadProps(__spreadValues({}, renderParam), {
6805
6807
  renderBag: __spreadValues({}, renderParam.renderBag)
6806
6808
  })
@@ -8892,11 +8894,16 @@ var RowSelectionState = class {
8892
8894
  this.defaultSelection = false;
8893
8895
  this.selectedMap = new DeepMap();
8894
8896
  this.deselectedMap = new DeepMap();
8897
+ this.onlyUsePrimaryKeys = false;
8895
8898
  this.selectionCache = new DeepMap();
8896
8899
  this.selectionCountCache = new DeepMap();
8897
8900
  this.mapSet = (name, key) => {
8898
8901
  if (!Array.isArray(key)) {
8899
- key = [...this.getGroupKeysForPrimaryKey(key), key];
8902
+ if (this.onlyUsePrimaryKeys) {
8903
+ key = [key];
8904
+ } else {
8905
+ key = [...this.getGroupKeysForPrimaryKey(key), key];
8906
+ }
8900
8907
  }
8901
8908
  this.xcache();
8902
8909
  if (name === "selected") {
@@ -8913,6 +8920,7 @@ var RowSelectionState = class {
8913
8920
  };
8914
8921
  const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? state.getState() : state;
8915
8922
  this.getConfig = getConfig;
8923
+ this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
8916
8924
  if (_forTestingOnly) {
8917
8925
  Object.assign(this, _forTestingOnly);
8918
8926
  }
@@ -8942,6 +8950,15 @@ var RowSelectionState = class {
8942
8950
  const { groupDeepMap } = this.getConfig();
8943
8951
  return (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith(groupKeys, true, 1)) || [];
8944
8952
  }
8953
+ getAllPrimaryKeysInsideGroup(groupKeys) {
8954
+ const { groupDeepMap } = this.getConfig();
8955
+ if (!groupKeys.length) {
8956
+ const topLevelKeys = (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith([], true, 1)) || [];
8957
+ return topLevelKeys.map((groupKeys2) => this.getAllPrimaryKeysInsideGroup(groupKeys2)).flat();
8958
+ }
8959
+ const group2 = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
8960
+ return group2 ? group2.items.map(this.getConfig().toPrimaryKey) : [];
8961
+ }
8945
8962
  getGroupByLength() {
8946
8963
  return this.getConfig().groupBy.length;
8947
8964
  }
@@ -8966,7 +8983,12 @@ var RowSelectionState = class {
8966
8983
  getState() {
8967
8984
  const normalize = (allKeys) => {
8968
8985
  const groupByLength = this.getGroupByLength();
8969
- return allKeys.map((keys) => keys.length > groupByLength ? keys.pop() : keys);
8986
+ return allKeys.map((keys) => {
8987
+ if (this.onlyUsePrimaryKeys) {
8988
+ return keys[0];
8989
+ }
8990
+ return keys.length > groupByLength ? keys.pop() : keys;
8991
+ });
8970
8992
  };
8971
8993
  const selectedRows = normalize(this.selectedMap.topDownKeys());
8972
8994
  const deselectedRows = normalize(this.deselectedMap.topDownKeys());
@@ -8997,6 +9019,9 @@ var RowSelectionState = class {
8997
9019
  return this.defaultSelection === false;
8998
9020
  }
8999
9021
  isRowSelected(key, groupKeys) {
9022
+ if (this.onlyUsePrimaryKeys) {
9023
+ return this.defaultSelection ? !this.deselectedMap.has([key]) : this.selectedMap.has([key]);
9024
+ }
9000
9025
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9001
9026
  const finalKey = [...groupKeys, key];
9002
9027
  const cachedResult = this.selectionCache.get(finalKey);
@@ -9053,7 +9078,7 @@ var RowSelectionState = class {
9053
9078
  if (cachedResult !== void 0) {
9054
9079
  return cachedResult;
9055
9080
  }
9056
- const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
9081
+ const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.onlyUsePrimaryKeys ? void 0 : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
9057
9082
  const result = selectedCount && deselectedCount ? null : selectedCount ? true : false;
9058
9083
  this.selectionCache.set(initialGroupKeys, result);
9059
9084
  return result;
@@ -9094,28 +9119,67 @@ var RowSelectionState = class {
9094
9119
  return this.getGroupRowSelectionState(groupKeys) === false;
9095
9120
  }
9096
9121
  selectGroupRow(groupKeys) {
9122
+ if (this.onlyUsePrimaryKeys) {
9123
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9124
+ keys.forEach((key) => {
9125
+ if (this.defaultSelection === true) {
9126
+ this.deselectedMap.delete([key]);
9127
+ } else {
9128
+ this._selectedMapSet(key);
9129
+ }
9130
+ });
9131
+ this.xcache();
9132
+ return;
9133
+ }
9097
9134
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
9098
9135
  selectedKeys.forEach((groupKeys2) => {
9099
9136
  this.selectedMap.delete(groupKeys2);
9100
9137
  });
9101
- this._selectedMapSet(groupKeys);
9138
+ if (groupKeys.length === 1 && this.defaultSelection === true) {
9139
+ } else {
9140
+ this._selectedMapSet(groupKeys);
9141
+ }
9102
9142
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
9103
9143
  deselectedKeys.forEach((groupKeys2) => {
9104
9144
  this.deselectedMap.delete(groupKeys2);
9105
9145
  });
9106
9146
  }
9107
9147
  deselectGroupRow(groupKeys) {
9148
+ if (this.onlyUsePrimaryKeys) {
9149
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9150
+ keys.forEach((key) => {
9151
+ if (this.defaultSelection === false) {
9152
+ this.selectedMap.delete([key]);
9153
+ } else {
9154
+ this._deselectedMapSet(key);
9155
+ }
9156
+ });
9157
+ this.xcache();
9158
+ return;
9159
+ }
9108
9160
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys, true);
9109
9161
  deselectedKeys.forEach((groupKeys2) => {
9110
9162
  this.deselectedMap.delete(groupKeys2);
9111
9163
  });
9112
- this._deselectedMapSet(groupKeys);
9164
+ if (groupKeys.length === 1 && this.defaultSelection === false) {
9165
+ } else {
9166
+ this._deselectedMapSet(groupKeys);
9167
+ }
9113
9168
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
9114
9169
  selectedKeys.forEach((groupKeys2) => {
9115
9170
  this.selectedMap.delete(groupKeys2);
9116
9171
  });
9117
9172
  }
9118
9173
  setRowAsSelected(key, groupKeys) {
9174
+ if (this.onlyUsePrimaryKeys) {
9175
+ if (this.defaultSelection) {
9176
+ this.deselectedMap.delete([key]);
9177
+ } else {
9178
+ this._selectedMapSet(key);
9179
+ }
9180
+ this.xcache();
9181
+ return;
9182
+ }
9119
9183
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9120
9184
  const finalKey = [...groupKeys, key];
9121
9185
  this.deselectedMap.delete(finalKey);
@@ -9128,9 +9192,19 @@ var RowSelectionState = class {
9128
9192
  }
9129
9193
  }
9130
9194
  setRowAsDeselected(key, groupKeys) {
9195
+ if (this.onlyUsePrimaryKeys) {
9196
+ if (this.defaultSelection) {
9197
+ this._deselectedMapSet(key);
9198
+ } else {
9199
+ this.selectedMap.delete([key]);
9200
+ }
9201
+ this.xcache();
9202
+ return;
9203
+ }
9131
9204
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9132
9205
  const finalKey = [...groupKeys, key];
9133
9206
  this.selectedMap.delete(finalKey);
9207
+ this.xcache();
9134
9208
  if (this.getGroupRowSelectionState(groupKeys) !== false) {
9135
9209
  this._deselectedMapSet(finalKey);
9136
9210
  if (this.getGroupRowSelectionState(groupKeys) === false) {
@@ -9179,6 +9253,32 @@ var RowSelectionState = class {
9179
9253
  this.selectionCountCache.set(groupKeys, result2);
9180
9254
  return result2;
9181
9255
  }
9256
+ if (this.onlyUsePrimaryKeys) {
9257
+ const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
9258
+ let selectedCount2 = 0;
9259
+ let deselectedCount2 = 0;
9260
+ allKeys2.forEach((key) => {
9261
+ if (this.defaultSelection) {
9262
+ if (this.deselectedMap.has([key])) {
9263
+ deselectedCount2++;
9264
+ return;
9265
+ }
9266
+ selectedCount2++;
9267
+ } else {
9268
+ if (this.selectedMap.has([key])) {
9269
+ selectedCount2++;
9270
+ return;
9271
+ }
9272
+ deselectedCount2++;
9273
+ }
9274
+ });
9275
+ const result2 = {
9276
+ selectedCount: selectedCount2,
9277
+ deselectedCount: deselectedCount2
9278
+ };
9279
+ this.selectionCountCache.set(groupKeys, result2);
9280
+ return result2;
9281
+ }
9182
9282
  parentSelected = parentSelected != null ? parentSelected : this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
9183
9283
  let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
9184
9284
  if (groupKeys.length === this.getGroupByLength()) {
@@ -9235,6 +9335,8 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
9235
9335
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
9236
9336
  return {
9237
9337
  lazyLoad: !!state.lazyLoad,
9338
+ toPrimaryKey: state.toPrimaryKey,
9339
+ onlyUsePrimaryKeys: state.usePrimaryKeysForMultiRowSelection,
9238
9340
  groupBy: state.groupBy,
9239
9341
  groupDeepMap: state.groupDeepMap,
9240
9342
  indexer: state.indexer,
@@ -9389,24 +9491,32 @@ function getSelectionApi(param) {
9389
9491
  rowSelectionState.toggleGroupRowSelection(groupKeys);
9390
9492
  dataSourceActions.rowSelection = rowSelectionState;
9391
9493
  },
9392
- getGroupRowSelectionState(groupKeys) {
9393
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
9494
+ getGroupRowSelectionState(groupKeys, rowSelection) {
9495
+ const state = getDataSourceState();
9496
+ const { selectionMode, groupBy } = state;
9497
+ const rowSelectionState = rowSelection ? new RowSelectionState(rowSelection, rowSelectionStateConfigGetter(state)) : state.rowSelection;
9394
9498
  if (selectionMode !== "multi-row") {
9395
9499
  throw 'Selection mode should be "multi-row"';
9396
9500
  }
9397
9501
  if (!groupBy) {
9398
9502
  throw "No grouping specified";
9399
9503
  }
9400
- if (!(rowSelection instanceof RowSelectionState)) {
9504
+ if (!(rowSelectionState instanceof RowSelectionState)) {
9401
9505
  throw "Invalid row selection";
9402
9506
  }
9403
- return rowSelection.getGroupRowSelectionState(groupKeys);
9507
+ return rowSelectionState.getGroupRowSelectionState(groupKeys);
9404
9508
  },
9405
- getSelectedPrimaryKeys: () => {
9509
+ getSelectedPrimaryKeys: (rowSelection) => {
9510
+ const state = getDataSourceState();
9511
+ const rowSelectionState = rowSelection ? new RowSelectionState(rowSelection, rowSelectionStateConfigGetter(state)) : state.rowSelection;
9406
9512
  const selected = [];
9407
- getDataSourceState().dataArray.forEach((rowInfo) => {
9408
- if (!rowInfo.isGroupRow && rowInfo.rowSelected) {
9409
- selected.push(rowInfo.id);
9513
+ if (state.lazyLoad) {
9514
+ console.error(`getSelectedPrimaryKeys should not be called for lazy-loaded datasources as it wont return reliable results`);
9515
+ }
9516
+ state.originalDataArray.forEach((data) => {
9517
+ const id = state.toPrimaryKey(data);
9518
+ if (rowSelectionState.isRowSelected(id)) {
9519
+ selected.push(id);
9410
9520
  }
9411
9521
  });
9412
9522
  return selected;
@@ -9548,6 +9658,7 @@ var forwardProps3 = (setupState) => {
9548
9658
  livePagination: 1,
9549
9659
  filterFunction: 1,
9550
9660
  filterValue: 1,
9661
+ usePrimaryKeysForMultiRowSelection: (usePrimaryKeysForMultiRowSelection) => usePrimaryKeysForMultiRowSelection != null ? usePrimaryKeysForMultiRowSelection : false,
9551
9662
  filterDelay: (filterDelay) => filterDelay != null ? filterDelay : 200,
9552
9663
  filterTypes: (filterTypes) => {
9553
9664
  return __spreadValues(__spreadValues({}, defaultFilterTypes), filterTypes);
@@ -10636,7 +10747,8 @@ function useCellRendering(param) {
10636
10747
  rowClassName,
10637
10748
  onScrollToTop,
10638
10749
  onScrollToBottom,
10639
- scrollToBottomOffset
10750
+ scrollToBottomOffset,
10751
+ ready
10640
10752
  } = componentState;
10641
10753
  const repaintId = dataSourceState.updatedAt;
10642
10754
  useYourBrain({
@@ -10677,12 +10789,16 @@ function useCellRendering(param) {
10677
10789
  if (!bodySize.height) {
10678
10790
  return;
10679
10791
  }
10680
- const { onReady } = getState();
10681
10792
  componentActions.ready = true;
10793
+ }, [!!bodySize.height]);
10794
+ useEffect19(() => {
10795
+ if (!ready) {
10796
+ }
10797
+ const { onReady } = getState();
10682
10798
  if (onReady) {
10683
10799
  onReady(imperativeApi);
10684
10800
  }
10685
- }, [!!bodySize.height]);
10801
+ }, [ready]);
10686
10802
  const [, rerender] = useRerender();
10687
10803
  useEffect19(() => {
10688
10804
  rerender();
@@ -12374,7 +12490,7 @@ var useLicense = (licenseKey = "") => {
12374
12490
  const valid = useMemo11(() => {
12375
12491
  let valid2 = isValidLicense(licenseKey, {
12376
12492
  publishedAt: 1624970570587,
12377
- version: "0.4.6"
12493
+ version: "0.4.9"
12378
12494
  });
12379
12495
  if (!licenseKey && !valid2 && isInsidePlayground) {
12380
12496
  return true;
@@ -12436,7 +12552,7 @@ function useScrollToActiveRow(activeRowIndex, dataCount, imperativeApi) {
12436
12552
  times++;
12437
12553
  rafId.current = requestAnimationFrame(() => {
12438
12554
  didScrollRef.current = imperativeApi.scrollRowIntoView(activeRowIndex, {
12439
- offset: 30
12555
+ offset: 0
12440
12556
  });
12441
12557
  if (!didScrollRef.current && times < RETRIES2) {
12442
12558
  tryScroll(times);
@@ -12993,7 +13109,6 @@ function handleKeyboardSelection(context) {
12993
13109
  const event = __spreadValues({}, context);
12994
13110
  const { renderSelectionCheckBox } = context.getComputed();
12995
13111
  if (renderSelectionCheckBox) {
12996
- event.shiftKey = false;
12997
13112
  event.metaKey = false;
12998
13113
  event.ctrlKey = true;
12999
13114
  }
package/index.js CHANGED
@@ -6717,6 +6717,7 @@ function InfiniteTableHeaderCell(props) {
6717
6717
  };
6718
6718
  const align = column.align || "start";
6719
6719
  const renderChildren = () => {
6720
+ var _a2;
6720
6721
  if (column.renderSortIcon) {
6721
6722
  renderParam.renderBag.sortIcon = /* @__PURE__ */ React28.createElement(RenderHeaderCellHookComponent, {
6722
6723
  render: column.renderSortIcon,
@@ -6730,9 +6731,10 @@ function InfiniteTableHeaderCell(props) {
6730
6731
  render: defaultRenderSelectionCheckBox2,
6731
6732
  renderParam
6732
6733
  });
6733
- if (column.renderHeaderSelectionCheckBox && column.renderHeaderSelectionCheckBox !== true) {
6734
+ const renderHeaderSelectionCheckBox = (_a2 = column.renderHeaderSelectionCheckBox) != null ? _a2 : column.renderSelectionCheckBox;
6735
+ if (renderHeaderSelectionCheckBox && renderHeaderSelectionCheckBox !== true) {
6734
6736
  renderParam.renderBag.selectionCheckBox = /* @__PURE__ */ React28.createElement(RenderHeaderCellHookComponent, {
6735
- render: column.renderHeaderSelectionCheckBox,
6737
+ render: renderHeaderSelectionCheckBox,
6736
6738
  renderParam: __spreadProps(__spreadValues({}, renderParam), {
6737
6739
  renderBag: __spreadValues({}, renderParam.renderBag)
6738
6740
  })
@@ -8799,11 +8801,16 @@ var RowSelectionState = class {
8799
8801
  this.defaultSelection = false;
8800
8802
  this.selectedMap = new DeepMap();
8801
8803
  this.deselectedMap = new DeepMap();
8804
+ this.onlyUsePrimaryKeys = false;
8802
8805
  this.selectionCache = new DeepMap();
8803
8806
  this.selectionCountCache = new DeepMap();
8804
8807
  this.mapSet = (name, key) => {
8805
8808
  if (!Array.isArray(key)) {
8806
- key = [...this.getGroupKeysForPrimaryKey(key), key];
8809
+ if (this.onlyUsePrimaryKeys) {
8810
+ key = [key];
8811
+ } else {
8812
+ key = [...this.getGroupKeysForPrimaryKey(key), key];
8813
+ }
8807
8814
  }
8808
8815
  this.xcache();
8809
8816
  if (name === "selected") {
@@ -8820,6 +8827,7 @@ var RowSelectionState = class {
8820
8827
  };
8821
8828
  const stateObject = state instanceof Object.getPrototypeOf(this).constructor ? state.getState() : state;
8822
8829
  this.getConfig = getConfig;
8830
+ this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
8823
8831
  if (_forTestingOnly) {
8824
8832
  Object.assign(this, _forTestingOnly);
8825
8833
  }
@@ -8849,6 +8857,15 @@ var RowSelectionState = class {
8849
8857
  const { groupDeepMap } = this.getConfig();
8850
8858
  return (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith(groupKeys, true, 1)) || [];
8851
8859
  }
8860
+ getAllPrimaryKeysInsideGroup(groupKeys) {
8861
+ const { groupDeepMap } = this.getConfig();
8862
+ if (!groupKeys.length) {
8863
+ const topLevelKeys = (groupDeepMap == null ? void 0 : groupDeepMap.getKeysStartingWith([], true, 1)) || [];
8864
+ return topLevelKeys.map((groupKeys2) => this.getAllPrimaryKeysInsideGroup(groupKeys2)).flat();
8865
+ }
8866
+ const group2 = groupDeepMap == null ? void 0 : groupDeepMap.get(groupKeys);
8867
+ return group2 ? group2.items.map(this.getConfig().toPrimaryKey) : [];
8868
+ }
8852
8869
  getGroupByLength() {
8853
8870
  return this.getConfig().groupBy.length;
8854
8871
  }
@@ -8873,7 +8890,12 @@ var RowSelectionState = class {
8873
8890
  getState() {
8874
8891
  const normalize = (allKeys) => {
8875
8892
  const groupByLength = this.getGroupByLength();
8876
- return allKeys.map((keys) => keys.length > groupByLength ? keys.pop() : keys);
8893
+ return allKeys.map((keys) => {
8894
+ if (this.onlyUsePrimaryKeys) {
8895
+ return keys[0];
8896
+ }
8897
+ return keys.length > groupByLength ? keys.pop() : keys;
8898
+ });
8877
8899
  };
8878
8900
  const selectedRows = normalize(this.selectedMap.topDownKeys());
8879
8901
  const deselectedRows = normalize(this.deselectedMap.topDownKeys());
@@ -8904,6 +8926,9 @@ var RowSelectionState = class {
8904
8926
  return this.defaultSelection === false;
8905
8927
  }
8906
8928
  isRowSelected(key, groupKeys) {
8929
+ if (this.onlyUsePrimaryKeys) {
8930
+ return this.defaultSelection ? !this.deselectedMap.has([key]) : this.selectedMap.has([key]);
8931
+ }
8907
8932
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
8908
8933
  const finalKey = [...groupKeys, key];
8909
8934
  const cachedResult = this.selectionCache.get(finalKey);
@@ -8960,7 +8985,7 @@ var RowSelectionState = class {
8960
8985
  if (cachedResult !== void 0) {
8961
8986
  return cachedResult;
8962
8987
  }
8963
- const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
8988
+ const { selectedCount, deselectedCount } = this.getSelectionCountFor(initialGroupKeys, this.onlyUsePrimaryKeys ? void 0 : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys));
8964
8989
  const result = selectedCount && deselectedCount ? null : selectedCount ? true : false;
8965
8990
  this.selectionCache.set(initialGroupKeys, result);
8966
8991
  return result;
@@ -9001,28 +9026,67 @@ var RowSelectionState = class {
9001
9026
  return this.getGroupRowSelectionState(groupKeys) === false;
9002
9027
  }
9003
9028
  selectGroupRow(groupKeys) {
9029
+ if (this.onlyUsePrimaryKeys) {
9030
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9031
+ keys.forEach((key) => {
9032
+ if (this.defaultSelection === true) {
9033
+ this.deselectedMap.delete([key]);
9034
+ } else {
9035
+ this._selectedMapSet(key);
9036
+ }
9037
+ });
9038
+ this.xcache();
9039
+ return;
9040
+ }
9004
9041
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
9005
9042
  selectedKeys.forEach((groupKeys2) => {
9006
9043
  this.selectedMap.delete(groupKeys2);
9007
9044
  });
9008
- this._selectedMapSet(groupKeys);
9045
+ if (groupKeys.length === 1 && this.defaultSelection === true) {
9046
+ } else {
9047
+ this._selectedMapSet(groupKeys);
9048
+ }
9009
9049
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
9010
9050
  deselectedKeys.forEach((groupKeys2) => {
9011
9051
  this.deselectedMap.delete(groupKeys2);
9012
9052
  });
9013
9053
  }
9014
9054
  deselectGroupRow(groupKeys) {
9055
+ if (this.onlyUsePrimaryKeys) {
9056
+ const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
9057
+ keys.forEach((key) => {
9058
+ if (this.defaultSelection === false) {
9059
+ this.selectedMap.delete([key]);
9060
+ } else {
9061
+ this._deselectedMapSet(key);
9062
+ }
9063
+ });
9064
+ this.xcache();
9065
+ return;
9066
+ }
9015
9067
  const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys, true);
9016
9068
  deselectedKeys.forEach((groupKeys2) => {
9017
9069
  this.deselectedMap.delete(groupKeys2);
9018
9070
  });
9019
- this._deselectedMapSet(groupKeys);
9071
+ if (groupKeys.length === 1 && this.defaultSelection === false) {
9072
+ } else {
9073
+ this._deselectedMapSet(groupKeys);
9074
+ }
9020
9075
  const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
9021
9076
  selectedKeys.forEach((groupKeys2) => {
9022
9077
  this.selectedMap.delete(groupKeys2);
9023
9078
  });
9024
9079
  }
9025
9080
  setRowAsSelected(key, groupKeys) {
9081
+ if (this.onlyUsePrimaryKeys) {
9082
+ if (this.defaultSelection) {
9083
+ this.deselectedMap.delete([key]);
9084
+ } else {
9085
+ this._selectedMapSet(key);
9086
+ }
9087
+ this.xcache();
9088
+ return;
9089
+ }
9026
9090
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9027
9091
  const finalKey = [...groupKeys, key];
9028
9092
  this.deselectedMap.delete(finalKey);
@@ -9035,9 +9099,19 @@ var RowSelectionState = class {
9035
9099
  }
9036
9100
  }
9037
9101
  setRowAsDeselected(key, groupKeys) {
9102
+ if (this.onlyUsePrimaryKeys) {
9103
+ if (this.defaultSelection) {
9104
+ this._deselectedMapSet(key);
9105
+ } else {
9106
+ this.selectedMap.delete([key]);
9107
+ }
9108
+ this.xcache();
9109
+ return;
9110
+ }
9038
9111
  groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
9039
9112
  const finalKey = [...groupKeys, key];
9040
9113
  this.selectedMap.delete(finalKey);
9114
+ this.xcache();
9041
9115
  if (this.getGroupRowSelectionState(groupKeys) !== false) {
9042
9116
  this._deselectedMapSet(finalKey);
9043
9117
  if (this.getGroupRowSelectionState(groupKeys) === false) {
@@ -9086,6 +9160,32 @@ var RowSelectionState = class {
9086
9160
  this.selectionCountCache.set(groupKeys, result2);
9087
9161
  return result2;
9088
9162
  }
9163
+ if (this.onlyUsePrimaryKeys) {
9164
+ const allKeys2 = this.getAllPrimaryKeysInsideGroup(groupKeys);
9165
+ let selectedCount2 = 0;
9166
+ let deselectedCount2 = 0;
9167
+ allKeys2.forEach((key) => {
9168
+ if (this.defaultSelection) {
9169
+ if (this.deselectedMap.has([key])) {
9170
+ deselectedCount2++;
9171
+ return;
9172
+ }
9173
+ selectedCount2++;
9174
+ } else {
9175
+ if (this.selectedMap.has([key])) {
9176
+ selectedCount2++;
9177
+ return;
9178
+ }
9179
+ deselectedCount2++;
9180
+ }
9181
+ });
9182
+ const result2 = {
9183
+ selectedCount: selectedCount2,
9184
+ deselectedCount: deselectedCount2
9185
+ };
9186
+ this.selectionCountCache.set(groupKeys, result2);
9187
+ return result2;
9188
+ }
9089
9189
  parentSelected = parentSelected != null ? parentSelected : this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
9090
9190
  let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
9091
9191
  if (groupKeys.length === this.getGroupByLength()) {
@@ -9142,6 +9242,8 @@ function rowSelectionStateConfigGetter(stateOrStateGetter) {
9142
9242
  const state = typeof stateOrStateGetter === "function" ? stateOrStateGetter() : stateOrStateGetter;
9143
9243
  return {
9144
9244
  lazyLoad: !!state.lazyLoad,
9245
+ toPrimaryKey: state.toPrimaryKey,
9246
+ onlyUsePrimaryKeys: state.usePrimaryKeysForMultiRowSelection,
9145
9247
  groupBy: state.groupBy,
9146
9248
  groupDeepMap: state.groupDeepMap,
9147
9249
  indexer: state.indexer,
@@ -9296,24 +9398,32 @@ function getSelectionApi(param) {
9296
9398
  rowSelectionState.toggleGroupRowSelection(groupKeys);
9297
9399
  dataSourceActions.rowSelection = rowSelectionState;
9298
9400
  },
9299
- getGroupRowSelectionState(groupKeys) {
9300
- const { selectionMode, rowSelection, groupBy } = getDataSourceState();
9401
+ getGroupRowSelectionState(groupKeys, rowSelection) {
9402
+ const state = getDataSourceState();
9403
+ const { selectionMode, groupBy } = state;
9404
+ const rowSelectionState = rowSelection ? new RowSelectionState(rowSelection, rowSelectionStateConfigGetter(state)) : state.rowSelection;
9301
9405
  if (selectionMode !== "multi-row") {
9302
9406
  throw 'Selection mode should be "multi-row"';
9303
9407
  }
9304
9408
  if (!groupBy) {
9305
9409
  throw "No grouping specified";
9306
9410
  }
9307
- if (!(rowSelection instanceof RowSelectionState)) {
9411
+ if (!(rowSelectionState instanceof RowSelectionState)) {
9308
9412
  throw "Invalid row selection";
9309
9413
  }
9310
- return rowSelection.getGroupRowSelectionState(groupKeys);
9414
+ return rowSelectionState.getGroupRowSelectionState(groupKeys);
9311
9415
  },
9312
- getSelectedPrimaryKeys: () => {
9416
+ getSelectedPrimaryKeys: (rowSelection) => {
9417
+ const state = getDataSourceState();
9418
+ const rowSelectionState = rowSelection ? new RowSelectionState(rowSelection, rowSelectionStateConfigGetter(state)) : state.rowSelection;
9313
9419
  const selected = [];
9314
- getDataSourceState().dataArray.forEach((rowInfo) => {
9315
- if (!rowInfo.isGroupRow && rowInfo.rowSelected) {
9316
- selected.push(rowInfo.id);
9420
+ if (state.lazyLoad) {
9421
+ console.error(`getSelectedPrimaryKeys should not be called for lazy-loaded datasources as it wont return reliable results`);
9422
+ }
9423
+ state.originalDataArray.forEach((data) => {
9424
+ const id = state.toPrimaryKey(data);
9425
+ if (rowSelectionState.isRowSelected(id)) {
9426
+ selected.push(id);
9317
9427
  }
9318
9428
  });
9319
9429
  return selected;
@@ -9455,6 +9565,7 @@ var forwardProps3 = (setupState) => {
9455
9565
  livePagination: 1,
9456
9566
  filterFunction: 1,
9457
9567
  filterValue: 1,
9568
+ usePrimaryKeysForMultiRowSelection: (usePrimaryKeysForMultiRowSelection) => usePrimaryKeysForMultiRowSelection != null ? usePrimaryKeysForMultiRowSelection : false,
9458
9569
  filterDelay: (filterDelay) => filterDelay != null ? filterDelay : 200,
9459
9570
  filterTypes: (filterTypes) => {
9460
9571
  return __spreadValues(__spreadValues({}, defaultFilterTypes), filterTypes);
@@ -10537,7 +10648,8 @@ function useCellRendering(param) {
10537
10648
  rowClassName,
10538
10649
  onScrollToTop,
10539
10650
  onScrollToBottom,
10540
- scrollToBottomOffset
10651
+ scrollToBottomOffset,
10652
+ ready
10541
10653
  } = componentState;
10542
10654
  const repaintId = dataSourceState.updatedAt;
10543
10655
  useYourBrain({
@@ -10578,12 +10690,16 @@ function useCellRendering(param) {
10578
10690
  if (!bodySize.height) {
10579
10691
  return;
10580
10692
  }
10581
- const { onReady } = getState();
10582
10693
  componentActions.ready = true;
10694
+ }, [!!bodySize.height]);
10695
+ (0, import_react32.useEffect)(() => {
10696
+ if (!ready) {
10697
+ }
10698
+ const { onReady } = getState();
10583
10699
  if (onReady) {
10584
10700
  onReady(imperativeApi);
10585
10701
  }
10586
- }, [!!bodySize.height]);
10702
+ }, [ready]);
10587
10703
  const [, rerender] = useRerender();
10588
10704
  (0, import_react32.useEffect)(() => {
10589
10705
  rerender();
@@ -12275,7 +12391,7 @@ var useLicense = (licenseKey = "") => {
12275
12391
  const valid = (0, import_react44.useMemo)(() => {
12276
12392
  let valid2 = isValidLicense(licenseKey, {
12277
12393
  publishedAt: 1624970570587,
12278
- version: "0.4.6"
12394
+ version: "0.4.9"
12279
12395
  });
12280
12396
  if (!licenseKey && !valid2 && isInsidePlayground) {
12281
12397
  return true;
@@ -12337,7 +12453,7 @@ function useScrollToActiveRow(activeRowIndex, dataCount, imperativeApi) {
12337
12453
  times++;
12338
12454
  rafId.current = requestAnimationFrame(() => {
12339
12455
  didScrollRef.current = imperativeApi.scrollRowIntoView(activeRowIndex, {
12340
- offset: 30
12456
+ offset: 0
12341
12457
  });
12342
12458
  if (!didScrollRef.current && times < RETRIES2) {
12343
12459
  tryScroll(times);
@@ -12894,7 +13010,6 @@ function handleKeyboardSelection(context) {
12894
13010
  const event = __spreadValues({}, context);
12895
13011
  const { renderSelectionCheckBox } = context.getComputed();
12896
13012
  if (renderSelectionCheckBox) {
12897
- event.shiftKey = false;
12898
13013
  event.metaKey = false;
12899
13014
  event.ctrlKey = true;
12900
13015
  }
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.6",
4
+ "version": "0.4.9",
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": 1660896701925
17
+ "publishedAt": 1661328172572
18
18
  }