@infinite-table/infinite-react 4.3.4 → 4.3.6

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.js CHANGED
@@ -6950,6 +6950,7 @@ function reorderColumnsOnDrag(params) {
6950
6950
  infiniteDOMNode,
6951
6951
  brain,
6952
6952
  dragColumnHeaderTargetRect,
6953
+ draggableColumnsRestrictTo,
6953
6954
  tableRect,
6954
6955
  setProxyPosition,
6955
6956
  api: imperativeApi
@@ -6978,8 +6979,9 @@ function reorderColumnsOnDrag(params) {
6978
6979
  const scrollLeft2 = brain.getScrollPosition().scrollLeft;
6979
6980
  return col.computedOffset >= scrollLeft2 + getCurrentPinnedWidth("start") && col.computedOffset + col.computedWidth < scrollLeft2 + tableRect.width - getCurrentPinnedWidth("end");
6980
6981
  }
6981
- const getBreakPoints = (columns) => {
6982
- const breakpoints = [];
6982
+ const getBreakPoints = (columns, options) => {
6983
+ const { restrictToParentGroup, dragColumn: dragColumn2 } = options;
6984
+ let breakpoints = [];
6983
6985
  columns.forEach((c) => {
6984
6986
  const b = {
6985
6987
  columnId: c.id,
@@ -6993,6 +6995,26 @@ function reorderColumnsOnDrag(params) {
6993
6995
  breakpoints.push(b);
6994
6996
  }
6995
6997
  });
6998
+ if (restrictToParentGroup) {
6999
+ let checkAllowedColumnsInDirection2 = function(colIndex, dir2, disallowedTargets2) {
7000
+ const col = columns[colIndex];
7001
+ if (!col) {
7002
+ return;
7003
+ }
7004
+ if (col.columnGroup !== dragColumn2.columnGroup) {
7005
+ disallowedTargets2.add(col.id);
7006
+ }
7007
+ checkAllowedColumnsInDirection2(colIndex + dir2, dir2, disallowedTargets2);
7008
+ };
7009
+ var checkAllowedColumnsInDirection = checkAllowedColumnsInDirection2;
7010
+ const dragColIndex = dragColumn2.computedVisibleIndex;
7011
+ const disallowedTargets = /* @__PURE__ */ new Set();
7012
+ checkAllowedColumnsInDirection2(dragColIndex - 1, -1, disallowedTargets);
7013
+ checkAllowedColumnsInDirection2(dragColIndex + 1, 1, disallowedTargets);
7014
+ breakpoints = breakpoints.filter((b) => {
7015
+ return !disallowedTargets.has(b.columnId);
7016
+ });
7017
+ }
6996
7018
  return breakpoints;
6997
7019
  };
6998
7020
  const initialPinnedStartCount = computedPinnedStartColumns.length;
@@ -7171,7 +7193,10 @@ function reorderColumnsOnDrag(params) {
7171
7193
  imperativeApi.scrollLeft = value;
7172
7194
  }
7173
7195
  });
7174
- const breakpoints = getBreakPoints(computedVisibleColumns);
7196
+ const breakpoints = getBreakPoints(computedVisibleColumns, {
7197
+ dragColumn,
7198
+ restrictToParentGroup: draggableColumnsRestrictTo === "group"
7199
+ });
7175
7200
  let currentPos = dir === -1 ? dragColumn.computedOffset + diffX : dragColumn.computedOffset + dragColumn.computedWidth + diffX;
7176
7201
  let idx = (0, import_binary_search2.default)(
7177
7202
  breakpoints,
@@ -7330,7 +7355,7 @@ var useColumnPointerEvents = ({
7330
7355
  if (((_a2 = e.target) == null ? void 0 : _a2.tagName) === "INPUT") {
7331
7356
  return;
7332
7357
  }
7333
- const { brain } = getState();
7358
+ const { brain, draggableColumnsRestrictTo } = getState();
7334
7359
  const {
7335
7360
  computedVisibleColumns,
7336
7361
  computedVisibleColumnsMap,
@@ -7352,6 +7377,7 @@ var useColumnPointerEvents = ({
7352
7377
  let didDragAtLeastOnce = false;
7353
7378
  const dragger = reorderColumnsOnDrag({
7354
7379
  brain,
7380
+ draggableColumnsRestrictTo,
7355
7381
  columnOffsetAtIndexCSSVar: columnOffsetAtIndex4,
7356
7382
  columnWidthAtIndexCSSVar: columnWidthAtIndex3,
7357
7383
  computedPinnedEndColumns,
@@ -9960,6 +9986,7 @@ function InfiniteTableHeaderFn(props) {
9960
9986
  } = props;
9961
9987
  const {
9962
9988
  computed,
9989
+ getState,
9963
9990
  state: { headerBrain, headerOptions, showColumnFilters }
9964
9991
  } = useInfiniteTable();
9965
9992
  const { computedColumnsMap } = computed;
@@ -10012,7 +10039,8 @@ function InfiniteTableHeaderFn(props) {
10012
10039
  computedWidth: colGroupItem.computedWidth,
10013
10040
  groupOffset: colGroupItem.groupOffset
10014
10041
  });
10015
- return /* @__PURE__ */ React46.createElement(
10042
+ const visible = getState().columnGroupVisibility[colGroupItem.id] !== false;
10043
+ return visible ? /* @__PURE__ */ React46.createElement(
10016
10044
  InfiniteTableHeaderGroup,
10017
10045
  {
10018
10046
  bodyBrain,
@@ -10023,7 +10051,7 @@ function InfiniteTableHeaderFn(props) {
10023
10051
  height,
10024
10052
  columnGroup: computedColumnGroup
10025
10053
  }
10026
- );
10054
+ ) : null;
10027
10055
  }
10028
10056
  return /* @__PURE__ */ React46.createElement(
10029
10057
  InfiniteTableHeaderCell,
@@ -14883,136 +14911,6 @@ function useDataSourceInternal(props) {
14883
14911
  };
14884
14912
  }
14885
14913
 
14886
- // src/utils/FixedSizeMap.ts
14887
- var _FixedSizeMap = class {
14888
- constructor(clone, size) {
14889
- this.keysInOrder = [];
14890
- if (typeof clone === "number") {
14891
- this.maxSize = clone;
14892
- this.currentMap = /* @__PURE__ */ new Map();
14893
- } else {
14894
- this.maxSize = size != null ? size : _FixedSizeMap.DEFAULT_SIZE;
14895
- if (clone) {
14896
- const arr = Array.from(clone);
14897
- if (this.maxSize < arr.length) {
14898
- arr.slice(arr.length - this.maxSize);
14899
- }
14900
- this.currentMap = /* @__PURE__ */ new Map();
14901
- arr.forEach(([k, v]) => {
14902
- this.set(k, v);
14903
- });
14904
- } else {
14905
- this.currentMap = /* @__PURE__ */ new Map();
14906
- }
14907
- }
14908
- }
14909
- values() {
14910
- return this.currentMap.values();
14911
- }
14912
- get size() {
14913
- return this.currentMap.size;
14914
- }
14915
- delete(key) {
14916
- if (this.currentMap.has(key)) {
14917
- this.currentMap.delete(key);
14918
- this.keysInOrder = this.keysInOrder.filter((k) => k !== key);
14919
- return true;
14920
- }
14921
- return false;
14922
- }
14923
- has(key) {
14924
- return this.currentMap.has(key);
14925
- }
14926
- get(key) {
14927
- return this.currentMap.get(key);
14928
- }
14929
- set(key, el) {
14930
- if (this.has(key)) {
14931
- this.delete(key);
14932
- }
14933
- const canAddCount = this.maxSize - this.currentMap.size;
14934
- if (canAddCount <= 0) {
14935
- const [removedKey] = this.keysInOrder.splice(0, 1);
14936
- if (removedKey != void 0) {
14937
- this.currentMap.delete(removedKey);
14938
- }
14939
- }
14940
- this.keysInOrder.push(key);
14941
- this.currentMap.set(key, el);
14942
- return this;
14943
- }
14944
- };
14945
- var FixedSizeMap = _FixedSizeMap;
14946
- FixedSizeMap.DEFAULT_SIZE = 10;
14947
-
14948
- // src/components/DataSource/RowDetailCache.ts
14949
- var RowDetailNoCacheStorage = class {
14950
- add(_key, _value) {
14951
- return;
14952
- }
14953
- get(_key) {
14954
- return void 0;
14955
- }
14956
- delete(_key) {
14957
- return;
14958
- }
14959
- has(_key) {
14960
- return false;
14961
- }
14962
- };
14963
- var RowDetailFixedSizeCacheStorage = class {
14964
- constructor(maxSize) {
14965
- this.storage = new FixedSizeMap(maxSize);
14966
- }
14967
- add(key, value) {
14968
- this.storage.set(key, value);
14969
- }
14970
- get(key) {
14971
- return this.storage.get(key);
14972
- }
14973
- delete(key) {
14974
- this.storage.delete(key);
14975
- }
14976
- has(key) {
14977
- return this.storage.has(key);
14978
- }
14979
- };
14980
- var RowDetailFullCacheStorage = class {
14981
- constructor() {
14982
- this.storage = /* @__PURE__ */ new Map();
14983
- }
14984
- add(key, value) {
14985
- this.storage.set(key, value);
14986
- }
14987
- get(key) {
14988
- return this.storage.get(key);
14989
- }
14990
- delete(key) {
14991
- this.storage.delete(key);
14992
- }
14993
- has(key) {
14994
- return this.storage.has(key);
14995
- }
14996
- };
14997
- var RowDetailCache = class {
14998
- // public instanceIndex: number = 0;
14999
- constructor(cache) {
15000
- this.cacheStorage = cache === false ? new RowDetailNoCacheStorage() : cache === true ? new RowDetailFullCacheStorage() : typeof cache === "number" ? new RowDetailFixedSizeCacheStorage(cache) : new RowDetailFixedSizeCacheStorage(5);
15001
- }
15002
- add(key, value) {
15003
- this.cacheStorage.add(key, value);
15004
- }
15005
- get(key) {
15006
- return this.cacheStorage.get(key);
15007
- }
15008
- delete(key) {
15009
- this.cacheStorage.delete(key);
15010
- }
15011
- has(key) {
15012
- return this.cacheStorage.has(key);
15013
- }
15014
- };
15015
-
15016
14914
  // src/components/DataSource/BooleanCollectionState.ts
15017
14915
  var BooleanCollectionState = class {
15018
14916
  constructor(state) {
@@ -15210,6 +15108,136 @@ var RowDetailState = class extends BooleanCollectionState {
15210
15108
  }
15211
15109
  };
15212
15110
 
15111
+ // src/utils/FixedSizeMap.ts
15112
+ var _FixedSizeMap = class {
15113
+ constructor(clone, size) {
15114
+ this.keysInOrder = [];
15115
+ if (typeof clone === "number") {
15116
+ this.maxSize = clone;
15117
+ this.currentMap = /* @__PURE__ */ new Map();
15118
+ } else {
15119
+ this.maxSize = size != null ? size : _FixedSizeMap.DEFAULT_SIZE;
15120
+ if (clone) {
15121
+ const arr = Array.from(clone);
15122
+ if (this.maxSize < arr.length) {
15123
+ arr.slice(arr.length - this.maxSize);
15124
+ }
15125
+ this.currentMap = /* @__PURE__ */ new Map();
15126
+ arr.forEach(([k, v]) => {
15127
+ this.set(k, v);
15128
+ });
15129
+ } else {
15130
+ this.currentMap = /* @__PURE__ */ new Map();
15131
+ }
15132
+ }
15133
+ }
15134
+ values() {
15135
+ return this.currentMap.values();
15136
+ }
15137
+ get size() {
15138
+ return this.currentMap.size;
15139
+ }
15140
+ delete(key) {
15141
+ if (this.currentMap.has(key)) {
15142
+ this.currentMap.delete(key);
15143
+ this.keysInOrder = this.keysInOrder.filter((k) => k !== key);
15144
+ return true;
15145
+ }
15146
+ return false;
15147
+ }
15148
+ has(key) {
15149
+ return this.currentMap.has(key);
15150
+ }
15151
+ get(key) {
15152
+ return this.currentMap.get(key);
15153
+ }
15154
+ set(key, el) {
15155
+ if (this.has(key)) {
15156
+ this.delete(key);
15157
+ }
15158
+ const canAddCount = this.maxSize - this.currentMap.size;
15159
+ if (canAddCount <= 0) {
15160
+ const [removedKey] = this.keysInOrder.splice(0, 1);
15161
+ if (removedKey != void 0) {
15162
+ this.currentMap.delete(removedKey);
15163
+ }
15164
+ }
15165
+ this.keysInOrder.push(key);
15166
+ this.currentMap.set(key, el);
15167
+ return this;
15168
+ }
15169
+ };
15170
+ var FixedSizeMap = _FixedSizeMap;
15171
+ FixedSizeMap.DEFAULT_SIZE = 10;
15172
+
15173
+ // src/components/DataSource/RowDetailCache.ts
15174
+ var RowDetailNoCacheStorage = class {
15175
+ add(_key, _value) {
15176
+ return;
15177
+ }
15178
+ get(_key) {
15179
+ return void 0;
15180
+ }
15181
+ delete(_key) {
15182
+ return;
15183
+ }
15184
+ has(_key) {
15185
+ return false;
15186
+ }
15187
+ };
15188
+ var RowDetailFixedSizeCacheStorage = class {
15189
+ constructor(maxSize) {
15190
+ this.storage = new FixedSizeMap(maxSize);
15191
+ }
15192
+ add(key, value) {
15193
+ this.storage.set(key, value);
15194
+ }
15195
+ get(key) {
15196
+ return this.storage.get(key);
15197
+ }
15198
+ delete(key) {
15199
+ this.storage.delete(key);
15200
+ }
15201
+ has(key) {
15202
+ return this.storage.has(key);
15203
+ }
15204
+ };
15205
+ var RowDetailFullCacheStorage = class {
15206
+ constructor() {
15207
+ this.storage = /* @__PURE__ */ new Map();
15208
+ }
15209
+ add(key, value) {
15210
+ this.storage.set(key, value);
15211
+ }
15212
+ get(key) {
15213
+ return this.storage.get(key);
15214
+ }
15215
+ delete(key) {
15216
+ this.storage.delete(key);
15217
+ }
15218
+ has(key) {
15219
+ return this.storage.has(key);
15220
+ }
15221
+ };
15222
+ var RowDetailCache = class {
15223
+ // public instanceIndex: number = 0;
15224
+ constructor(cache) {
15225
+ this.cacheStorage = cache === false ? new RowDetailNoCacheStorage() : cache === true ? new RowDetailFullCacheStorage() : typeof cache === "number" ? new RowDetailFixedSizeCacheStorage(cache) : new RowDetailFixedSizeCacheStorage(5);
15226
+ }
15227
+ add(key, value) {
15228
+ this.cacheStorage.add(key, value);
15229
+ }
15230
+ get(key) {
15231
+ return this.cacheStorage.get(key);
15232
+ }
15233
+ delete(key) {
15234
+ this.cacheStorage.delete(key);
15235
+ }
15236
+ has(key) {
15237
+ return this.cacheStorage.has(key);
15238
+ }
15239
+ };
15240
+
15213
15241
  // src/components/DataSource/types.ts
15214
15242
  var DataSourceActionType = /* @__PURE__ */ ((DataSourceActionType2) => {
15215
15243
  DataSourceActionType2["INIT"] = "INIT";
@@ -17333,12 +17361,18 @@ var ScrollListener = class {
17333
17361
  };
17334
17362
 
17335
17363
  // src/components/InfiniteTable/state/computeColumnGroupsDepths.ts
17336
- function computeColumnGroupsDepths(columnGroups) {
17364
+ function computeColumnGroupsDepths(columnGroups, columnGroupVisibility) {
17337
17365
  const map2 = /* @__PURE__ */ new Map();
17366
+ function isVisible(colGroupId) {
17367
+ return columnGroupVisibility[colGroupId] !== false;
17368
+ }
17338
17369
  Object.keys(columnGroups).forEach((colGroupId) => {
17339
17370
  const colGroup = columnGroups[colGroupId];
17340
17371
  let parentGroupId = colGroup.columnGroup;
17341
17372
  let depth = 0;
17373
+ if (!isVisible(colGroupId)) {
17374
+ depth = -1;
17375
+ }
17342
17376
  while (parentGroupId) {
17343
17377
  const parent = columnGroups[parentGroupId];
17344
17378
  if (!parent) {
@@ -17347,7 +17381,9 @@ function computeColumnGroupsDepths(columnGroups) {
17347
17381
  }
17348
17382
  break;
17349
17383
  }
17350
- depth++;
17384
+ if (isVisible(parentGroupId)) {
17385
+ depth++;
17386
+ }
17351
17387
  parentGroupId = parent.columnGroup;
17352
17388
  }
17353
17389
  map2.set(colGroupId, depth);
@@ -17364,6 +17400,7 @@ function getRowDetailRendererFromComponent(RowDetail) {
17364
17400
  }
17365
17401
 
17366
17402
  // src/components/InfiniteTable/state/getInitialState.ts
17403
+ var EMPTY_OBJECT = {};
17367
17404
  function createRenderer2(brain) {
17368
17405
  const renderer = new ReactHeadlessTableRenderer(brain);
17369
17406
  const onRenderUpdater = buildSubscriptionCallback();
@@ -17511,6 +17548,7 @@ var forwardProps4 = (_setupState) => {
17511
17548
  onScrollbarsChange: 1,
17512
17549
  autoSizeColumnsKey: 1,
17513
17550
  columnDefaultFlex: 1,
17551
+ draggableColumnsRestrictTo: (draggableColumnsRestrictTo) => draggableColumnsRestrictTo != null ? draggableColumnsRestrictTo : false,
17514
17552
  columnMenuRealignDelay: (columnMenuRealignDelay) => columnMenuRealignDelay != null ? columnMenuRealignDelay : 50,
17515
17553
  scrollStopDelay: (scrollStopDelay) => scrollStopDelay != null ? scrollStopDelay : 250,
17516
17554
  viewportReservedWidth: (viewportReservedWidth) => viewportReservedWidth != null ? viewportReservedWidth : 0,
@@ -17549,7 +17587,8 @@ var forwardProps4 = (_setupState) => {
17549
17587
  rowDetailHeight: (rowDetailHeight) => typeof rowDetailHeight === "number" || typeof rowDetailHeight === "function" ? rowDetailHeight : 300,
17550
17588
  columnHeaderHeight: (columnHeaderHeight) => typeof columnHeaderHeight === "number" ? columnHeaderHeight : 30,
17551
17589
  columns: 1,
17552
- columnVisibility: (columnVisibility) => columnVisibility != null ? columnVisibility : {},
17590
+ columnVisibility: (columnVisibility) => columnVisibility != null ? columnVisibility : EMPTY_OBJECT,
17591
+ columnGroupVisibility: (columnGroupVisibility) => columnGroupVisibility != null ? columnGroupVisibility : EMPTY_OBJECT,
17553
17592
  // TODO check if columnPinning works when the value for a pinned col is `true` instead of `"start"`
17554
17593
  columnSizing: (columnSizing) => columnSizing || {},
17555
17594
  columnTypes: (columnTypes) => columnTypes || {},
@@ -17630,7 +17669,10 @@ var mapPropsToState = (params) => {
17630
17669
  var _a, _b, _c, _d, _e;
17631
17670
  const { props, state, oldState, parentState } = params;
17632
17671
  const computedColumnGroups = state.pivotColumnGroups || state.columnGroups;
17633
- const columnGroupsDepthsMap = state.columnGroups && state.columnGroups != (oldState == null ? void 0 : oldState.columnGroups) || state.pivotColumnGroups && state.pivotColumnGroups != (oldState == null ? void 0 : oldState.pivotColumnGroups) ? computeColumnGroupsDepths(computedColumnGroups) : state.columnGroupsDepthsMap;
17672
+ const columnGroupsDepthsMap = state.columnGroups && state.columnGroups != (oldState == null ? void 0 : oldState.columnGroups) || state.columnGroups && state.columnGroupVisibility != (oldState == null ? void 0 : oldState.columnGroupVisibility) || state.pivotColumnGroups && state.pivotColumnGroups != (oldState == null ? void 0 : oldState.pivotColumnGroups) ? computeColumnGroupsDepths(
17673
+ computedColumnGroups,
17674
+ state.columnGroupVisibility
17675
+ ) : state.columnGroupsDepthsMap;
17634
17676
  const groupBy = parentState == null ? void 0 : parentState.groupBy;
17635
17677
  const groupRenderStrategy = getGroupRenderStrategy({
17636
17678
  groupRenderStrategy: props.groupRenderStrategy,
@@ -17685,7 +17727,11 @@ var mapPropsToState = (params) => {
17685
17727
  keyboardNavigation: (_c = props.keyboardNavigation) != null ? _c : state.activeCellIndex != null ? "cell" : state.activeRowIndex != null ? "row" : "cell",
17686
17728
  columnHeaderCssEllipsis: (_e = (_d = props.columnHeaderCssEllipsis) != null ? _d : props.columnCssEllipsis) != null ? _e : true,
17687
17729
  columnGroupsDepthsMap,
17688
- columnGroupsMaxDepth: columnGroupsDepthsMap != state.columnGroupsDepthsMap ? Math.max(...columnGroupsDepthsMap.values(), 0) : state.columnGroupsMaxDepth,
17730
+ columnGroupsMaxDepth: columnGroupsDepthsMap != state.columnGroupsDepthsMap ? (
17731
+ // was 0, but after implementing columnGroupVisibility
17732
+ // it can be -1, to denote that no column group is visible
17733
+ Math.max(...columnGroupsDepthsMap.values(), -1)
17734
+ ) : state.columnGroupsMaxDepth,
17689
17735
  computedColumnGroups,
17690
17736
  rowHeightCSSVar: typeof props.rowHeight === "string" ? props.rowHeight : "",
17691
17737
  rowDetailHeightCSSVar: typeof props.rowDetailHeight === "string" ? props.rowDetailHeight : "",
@@ -18611,7 +18657,11 @@ function useComputed() {
18611
18657
  const computedPinnedEndOverflow = computedPinnedEndWidth ? computedPinnedEndColumnsWidth > computedPinnedEndWidth : false;
18612
18658
  const [multiRowSelector] = (0, import_react49.useState)(() => {
18613
18659
  const multiRowSelector2 = new MultiRowSelector({
18614
- getIdForIndex: (index) => getDataSourceState().dataArray[index].id
18660
+ getIdForIndex: (index) => {
18661
+ var _a2;
18662
+ const dataItem = getDataSourceState().dataArray[index];
18663
+ return (_a2 = dataItem == null ? void 0 : dataItem.id) != null ? _a2 : -1;
18664
+ }
18615
18665
  });
18616
18666
  return multiRowSelector2;
18617
18667
  });
@@ -18843,7 +18893,7 @@ var useLicense = (licenseKey = "") => {
18843
18893
  }
18844
18894
  let valid2 = isValidLicense(licenseKey, {
18845
18895
  publishedAt: 1624970570587,
18846
- version: "4.3.4"
18896
+ version: "4.3.6"
18847
18897
  });
18848
18898
  if (!licenseKey && !valid2 && isInsidePlayground) {
18849
18899
  return true;
@@ -22560,7 +22610,8 @@ function InfiniteTableBody() {
22560
22610
  components: components2,
22561
22611
  bodySize,
22562
22612
  activeCellIndex,
22563
- rowDetailRenderer
22613
+ rowDetailRenderer,
22614
+ showHoverRows
22564
22615
  } = componentState;
22565
22616
  const LoadMaskCmp = (_a = components2 == null ? void 0 : components2.LoadMask) != null ? _a : LoadMask;
22566
22617
  const computed = getComputed();
@@ -22628,7 +22679,7 @@ function InfiniteTableBody() {
22628
22679
  activeCellRowHeight,
22629
22680
  renderCell,
22630
22681
  renderDetailRow: rowDetailRenderer ? renderDetailRow : void 0,
22631
- cellHoverClassNames: HOVERED_CLASS_NAMES,
22682
+ cellHoverClassNames: showHoverRows ? HOVERED_CLASS_NAMES : void 0,
22632
22683
  scrollerDOMRef
22633
22684
  }
22634
22685
  ), /* @__PURE__ */ React68.createElement(LoadMaskCmp, { visible: loading }, loadingText));