@infinite-table/infinite-react 9.1.1 → 9.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.dev.js CHANGED
@@ -2720,6 +2720,27 @@ function resizeClamp(value, min, max, direction) {
2720
2720
  }
2721
2721
  return { value, clamped: false, diff: 0 };
2722
2722
  }
2723
+ function hasFlexDeficit(items, availableSize, reservedWidth) {
2724
+ let hasFlex = false;
2725
+ let totalWidth = 0;
2726
+ for (const item of items) {
2727
+ if (item.computedFlex) {
2728
+ hasFlex = true;
2729
+ }
2730
+ totalWidth += item.computedWidth;
2731
+ }
2732
+ return hasFlex && Math.round(totalWidth) > Math.round(availableSize - reservedWidth);
2733
+ }
2734
+ function getResizeSizingProperty(item, flexDeficit) {
2735
+ return item.computedFlex && !flexDeficit ? "flex" : "width";
2736
+ }
2737
+ function withResizedSize(entry, property, size) {
2738
+ if (property === "width") {
2739
+ const { flex: _flex, ...rest } = entry ?? {};
2740
+ return { ...rest, width: size };
2741
+ }
2742
+ return { ...entry, flex: size };
2743
+ }
2723
2744
  var computeResize = (params) => {
2724
2745
  const { availableSize, reservedWidth = 0 } = params;
2725
2746
  const columnSizing = Object.keys(
@@ -2738,14 +2759,19 @@ var computeResize = (params) => {
2738
2759
  const secondItem = params.items[secondIndex];
2739
2760
  const firstId = firstItem.id;
2740
2761
  const secondId = secondItem?.id;
2762
+ const flexDeficit = hasFlexDeficit(
2763
+ params.items,
2764
+ availableSize,
2765
+ reservedWidth
2766
+ );
2741
2767
  const firstSize = firstItem.computedWidth;
2742
2768
  const firstMinSize = firstItem.computedMinWidth;
2743
2769
  const firstMaxSize = firstItem.computedMaxWidth;
2744
- const firstPropertyToAdjust = firstItem.computedFlex ? "flex" : "width";
2770
+ const firstPropertyToAdjust = getResizeSizingProperty(firstItem, flexDeficit);
2745
2771
  const secondSize = secondItem?.computedWidth;
2746
2772
  const secondMinSize = secondItem?.computedMinWidth;
2747
2773
  const secondMaxSize = secondItem?.computedMaxWidth;
2748
- const secondPropertyToAdjust = secondItem?.computedFlex ? "flex" : "width";
2774
+ const secondPropertyToAdjust = secondItem ? getResizeSizingProperty(secondItem, flexDeficit) : "width";
2749
2775
  let maxReached = false;
2750
2776
  let minReached = false;
2751
2777
  const direction = dragHandleOffset > 0 ? 1 : -1;
@@ -2754,17 +2780,18 @@ var computeResize = (params) => {
2754
2780
  clamped: firstClamped,
2755
2781
  diff: firstDiff
2756
2782
  } = resizeClamp(
2757
- firstSize + dragHandleOffset,
2783
+ Math.round(firstSize + dragHandleOffset),
2758
2784
  firstMinSize,
2759
2785
  firstMaxSize,
2760
2786
  direction
2761
2787
  );
2762
2788
  if (params.shareSpaceOnResize) {
2763
2789
  if (secondItem == null) {
2764
- columnSizing[firstId] = {
2765
- ...columnSizing[firstId],
2766
- [firstPropertyToAdjust]: firstAdjustedSize
2767
- };
2790
+ columnSizing[firstId] = withResizedSize(
2791
+ columnSizing[firstId],
2792
+ firstPropertyToAdjust,
2793
+ firstAdjustedSize
2794
+ );
2768
2795
  minReached = firstClamped === "min";
2769
2796
  maxReached = firstClamped === "max";
2770
2797
  const adjustedDiff2 = firstAdjustedSize - firstSize;
@@ -2782,7 +2809,7 @@ var computeResize = (params) => {
2782
2809
  clamped: secondClamped,
2783
2810
  diff: secondDiff
2784
2811
  } = resizeClamp(
2785
- secondSize - dragHandleOffset,
2812
+ Math.round(secondSize - dragHandleOffset),
2786
2813
  secondMinSize,
2787
2814
  secondMaxSize,
2788
2815
  direction
@@ -2797,7 +2824,7 @@ var computeResize = (params) => {
2797
2824
  if (!firstClamped && !secondClamped) {
2798
2825
  } else if (firstClamped) {
2799
2826
  const clampResultForSecond = resizeClamp(
2800
- secondSize - dragHandleOffset - firstDiff,
2827
+ Math.round(secondSize - dragHandleOffset - firstDiff),
2801
2828
  secondMinSize,
2802
2829
  secondMaxSize,
2803
2830
  direction
@@ -2807,7 +2834,7 @@ var computeResize = (params) => {
2807
2834
  secondDiff = clampResultForSecond.diff;
2808
2835
  } else if (secondClamped) {
2809
2836
  const clampResultForFirst = resizeClamp(
2810
- firstSize + dragHandleOffset + secondDiff,
2837
+ Math.round(firstSize + dragHandleOffset + secondDiff),
2811
2838
  firstMinSize,
2812
2839
  firstMaxSize,
2813
2840
  direction
@@ -2816,28 +2843,31 @@ var computeResize = (params) => {
2816
2843
  firstClamped = clampResultForFirst.clamped;
2817
2844
  firstDiff = clampResultForFirst.diff;
2818
2845
  }
2819
- columnSizing[firstId] = {
2820
- ...columnSizing[firstId],
2821
- [firstPropertyToAdjust]: firstAdjustedSize
2822
- };
2823
- columnSizing[secondId] = {
2824
- ...columnSizing[secondId],
2825
- [secondPropertyToAdjust]: secondAdjustedSize
2826
- };
2846
+ columnSizing[firstId] = withResizedSize(
2847
+ columnSizing[firstId],
2848
+ firstPropertyToAdjust,
2849
+ firstAdjustedSize
2850
+ );
2851
+ columnSizing[secondId] = withResizedSize(
2852
+ columnSizing[secondId],
2853
+ secondPropertyToAdjust,
2854
+ secondAdjustedSize
2855
+ );
2827
2856
  minReached = firstClamped === "min" || secondClamped === "min";
2828
2857
  maxReached = firstClamped === "max" || secondClamped === "max";
2829
2858
  } else {
2830
- columnSizing[firstId] = {
2831
- ...columnSizing[firstId],
2832
- [firstPropertyToAdjust]: firstAdjustedSize
2833
- };
2859
+ columnSizing[firstId] = withResizedSize(
2860
+ columnSizing[firstId],
2861
+ firstPropertyToAdjust,
2862
+ firstAdjustedSize
2863
+ );
2834
2864
  minReached = firstClamped === "min";
2835
2865
  maxReached = firstClamped === "max";
2836
2866
  }
2837
2867
  const adjustedDiff = firstAdjustedSize - firstSize;
2838
2868
  return {
2839
2869
  adjustedDiff,
2840
- reservedWidth: !params.shareSpaceOnResize ? reservedWidth - adjustedDiff : reservedWidth,
2870
+ reservedWidth: !params.shareSpaceOnResize ? Math.round(reservedWidth - adjustedDiff) : reservedWidth,
2841
2871
  columnSizing,
2842
2872
  minReached,
2843
2873
  maxReached,
@@ -2871,8 +2901,13 @@ var computeGroupResize = (params) => {
2871
2901
  const beforeIndexes = [...new Array(params.columnGroupSize)].map((_, index) => params.dragHandlePositionAfter - index).reverse();
2872
2902
  const beforeItems = beforeIndexes.map((i) => params.items[i]);
2873
2903
  const beforeSizes = beforeItems.map((item) => item.computedWidth);
2904
+ const flexDeficit = hasFlexDeficit(
2905
+ params.items,
2906
+ availableSize,
2907
+ reservedWidth
2908
+ );
2874
2909
  const beforePropertiesToAdjust = beforeItems.map(
2875
- (item) => item.computedFlex ? "flex" : "width"
2910
+ (item) => getResizeSizingProperty(item, flexDeficit)
2876
2911
  );
2877
2912
  let unresizableWidth = 0;
2878
2913
  const { computedSizes } = computeFlex({
@@ -2921,10 +2956,11 @@ var computeGroupResize = (params) => {
2921
2956
  columnSizing: currentColumnSizing
2922
2957
  }
2923
2958
  );
2924
- columnSizing[item.id] = {
2925
- ...currentColumnSizing[item.id],
2926
- [propertyToAdjust]: itemSize + adjustedDiff2
2927
- };
2959
+ columnSizing[item.id] = withResizedSize(
2960
+ currentColumnSizing[item.id],
2961
+ propertyToAdjust,
2962
+ Math.round(itemSize + adjustedDiff2)
2963
+ );
2928
2964
  adjustedDiffs.push(adjustedDiff2);
2929
2965
  if (!maxReached) {
2930
2966
  groupMaxReached = false;
@@ -2944,7 +2980,7 @@ var computeGroupResize = (params) => {
2944
2980
  adjustedDiffs,
2945
2981
  adjustedDiff,
2946
2982
  columnSizing,
2947
- reservedWidth: reservedWidth - adjustedDiff
2983
+ reservedWidth: Math.round(reservedWidth - adjustedDiff)
2948
2984
  };
2949
2985
  };
2950
2986
 
@@ -3187,15 +3223,20 @@ var getComputedColumns = ({
3187
3223
  width: colType?.defaultWidth,
3188
3224
  flex: colType?.defaultFlex
3189
3225
  };
3190
- let colSizing = assignNonNull(
3191
- {
3192
- width: column?.defaultWidth,
3193
- flex: column?.defaultFlex,
3194
- minWidth: column?.minWidth,
3195
- maxWidth: column?.maxWidth
3196
- },
3197
- columnSizing[colId]
3198
- );
3226
+ const colDefaultSizing = {
3227
+ width: column?.defaultWidth,
3228
+ flex: column?.defaultFlex,
3229
+ minWidth: column?.minWidth,
3230
+ maxWidth: column?.maxWidth
3231
+ };
3232
+ const colSizingFromProp = columnSizing[colId];
3233
+ if (colSizingFromProp?.width != null && colSizingFromProp.flex == null) {
3234
+ delete colDefaultSizing.flex;
3235
+ }
3236
+ if (colSizingFromProp?.flex != null && colSizingFromProp.width == null) {
3237
+ delete colDefaultSizing.width;
3238
+ }
3239
+ let colSizing = assignNonNull(colDefaultSizing, colSizingFromProp);
3199
3240
  if (colSizing.width != null) {
3200
3241
  delete colTypeSizing.flex;
3201
3242
  }
@@ -8111,6 +8152,9 @@ var React30 = __toESM(require("react"));
8111
8152
  var import_react23 = require("react");
8112
8153
 
8113
8154
  // src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizeShared.ts
8155
+ function getResizeAvailableSize(bodySize) {
8156
+ return Math.max(bodySize.width - getScrollbarWidth(), 0);
8157
+ }
8114
8158
  function computeColumnResizeForDiff(options) {
8115
8159
  const { context, column, diff, shareSpaceOnResize } = options;
8116
8160
  const state = context.getState();
@@ -8133,7 +8177,7 @@ function computeColumnResizeForDiff(options) {
8133
8177
  } : columnSizing;
8134
8178
  return computeResize({
8135
8179
  shareSpaceOnResize,
8136
- availableSize: bodySize.width,
8180
+ availableSize: getResizeAvailableSize(bodySize),
8137
8181
  reservedWidth: viewportReservedWidth || 0,
8138
8182
  dragHandleOffset: diff,
8139
8183
  dragHandlePositionAfter: column.computedVisibleIndex,
@@ -8362,6 +8406,7 @@ function ResizeHandleFn(props) {
8362
8406
  const diff = Math.round(e2.clientX - initialX);
8363
8407
  const adjustedDiff = resizeDiff(diff, { done: true });
8364
8408
  restoreRenderRange();
8409
+ resizer.resize(0);
8365
8410
  props.onResize({ diff: adjustedDiff, shareSpaceOnResize });
8366
8411
  };
8367
8412
  target.addEventListener("pointermove", onPointerMove);
@@ -13771,6 +13816,7 @@ function GroupResizeHandleFn(props) {
13771
13816
  target.removeEventListener("pointerup", onPointerUp);
13772
13817
  const diff = Math.round(e2.clientX - initialX);
13773
13818
  const adjustedDiffs = resizeDiff(diff);
13819
+ resizer.resize(props.groupColumns.map(() => 0));
13774
13820
  props.onResize(adjustedDiffs);
13775
13821
  };
13776
13822
  target.addEventListener("pointermove", onPointerMove);
@@ -13840,7 +13886,7 @@ function useColumnGroupResizeHandle(groupColumns, config) {
13840
13886
  ...columnSizingWithFlex
13841
13887
  } : columnSizing;
13842
13888
  const result = computeGroupResize({
13843
- availableSize: bodySize.width,
13889
+ availableSize: getResizeAvailableSize(bodySize),
13844
13890
  reservedWidth: viewportReservedWidth || 0,
13845
13891
  dragHandleOffset: diff,
13846
13892
  dragHandlePositionAfter: lastColumnInGroup.computedVisibleIndex,
@@ -22388,6 +22434,23 @@ function computeFilterValueForRemote(filterValue, {
22388
22434
  }
22389
22435
  );
22390
22436
  }
22437
+ function createRemoteFilterValueMemo() {
22438
+ let prev;
22439
+ return (filterValue, filterTypes, filterMode) => {
22440
+ if (prev && prev.filterValue === filterValue && prev.filterTypes === filterTypes && prev.filterMode === filterMode) {
22441
+ return prev.result;
22442
+ }
22443
+ let result = computeFilterValueForRemote(filterValue, {
22444
+ filterTypes,
22445
+ filterMode
22446
+ });
22447
+ if (prev && prev.filterValue === filterValue && JSON.stringify(prev.result) === JSON.stringify(result)) {
22448
+ result = prev.result;
22449
+ }
22450
+ prev = { filterValue, filterTypes, filterMode, result };
22451
+ return result;
22452
+ };
22453
+ }
22391
22454
  var getRafPromise = () => new Promise((resolve) => {
22392
22455
  raf(resolve);
22393
22456
  });
@@ -22400,6 +22463,10 @@ function getDetailReady(masterContext, getDataSourceState) {
22400
22463
  isDetailReady
22401
22464
  };
22402
22465
  }
22466
+ function isFirstLazyBatchRequested(componentState) {
22467
+ const { lazyLoad, lazyLoadBatchSize, lazyLoadCacheOfLoadedBatches } = componentState;
22468
+ return !!lazyLoad && !!lazyLoadBatchSize && lazyLoadBatchSize > 0 && lazyLoadCacheOfLoadedBatches.has([0]);
22469
+ }
22403
22470
  function lazyLoadRange(options, cache) {
22404
22471
  const {
22405
22472
  startIndex,
@@ -24996,12 +25063,15 @@ function useLoadData(options) {
24996
25063
  }
24997
25064
  }
24998
25065
  }, [scrollbars.vertical]);
24999
- const computedFilterValue = (0, import_react41.useMemo)(() => {
25000
- return computeFilterValueForRemote(filterValue, {
25001
- filterTypes,
25002
- filterMode
25003
- });
25004
- }, [filterValue, filterMode, filterTypes]);
25066
+ const getRemoteFilterValue = (0, import_react41.useMemo)(
25067
+ () => createRemoteFilterValueMemo(),
25068
+ []
25069
+ );
25070
+ const computedFilterValue = getRemoteFilterValue(
25071
+ filterValue,
25072
+ filterTypes,
25073
+ filterMode
25074
+ );
25005
25075
  const depsObject = {
25006
25076
  // #sortMode_vs_shouldReloadData.sortInfo
25007
25077
  sortInfo: shouldReloadData.sortInfo ? sortInfo : null,
@@ -25012,14 +25082,19 @@ function useLoadData(options) {
25012
25082
  cursorId: livePagination ? stateCursorId : null
25013
25083
  };
25014
25084
  const initialRef = (0, import_react41.useRef)(true);
25015
- useLazyLoadRange(options, {
25016
- sortInfo,
25017
- groupBy,
25018
- pivotBy,
25019
- filterValue,
25020
- refetchKey,
25021
- cursorId: livePagination ? stateCursorId : null
25022
- });
25085
+ const lazyRangeReloadedRef = (0, import_react41.useRef)(false);
25086
+ useLazyLoadRange(
25087
+ options,
25088
+ {
25089
+ sortInfo,
25090
+ groupBy,
25091
+ pivotBy,
25092
+ filterValue,
25093
+ refetchKey,
25094
+ cursorId: livePagination ? stateCursorId : null
25095
+ },
25096
+ lazyRangeReloadedRef
25097
+ );
25023
25098
  const getMasterContext = useGetMasterDetailContext();
25024
25099
  const dataChangeTimestampsRef = (0, import_react41.useRef)([]);
25025
25100
  useEffectWithChanges(
@@ -25083,6 +25158,9 @@ function useLoadData(options) {
25083
25158
  }
25084
25159
  const componentState = getDataSourceState();
25085
25160
  if (typeof componentState.data === "function") {
25161
+ if (lazyRangeReloadedRef.current && !appendWhenLivePagination && isFirstLazyBatchRequested(componentState)) {
25162
+ return;
25163
+ }
25086
25164
  let marker;
25087
25165
  if (componentState.debugId) {
25088
25166
  marker = getMarker(
@@ -25104,6 +25182,9 @@ function useLoadData(options) {
25104
25182
  },
25105
25183
  { ...depsObject, data }
25106
25184
  );
25185
+ (0, import_react41.useEffect)(() => {
25186
+ lazyRangeReloadedRef.current = false;
25187
+ });
25107
25188
  useEffectWithChanges(() => {
25108
25189
  const componentState = getDataSourceState();
25109
25190
  if (initialRef.current) {
@@ -25117,7 +25198,7 @@ function useLoadData(options) {
25117
25198
  }
25118
25199
  }, depsObject);
25119
25200
  }
25120
- function useLazyLoadRange(options, dependencies) {
25201
+ function useLazyLoadRange(options, dependencies, reloadedRef) {
25121
25202
  const { getDataSourceState, dataSourceActions, dataSourceState } = options;
25122
25203
  (0, import_react41.useEffect)(() => {
25123
25204
  dataSourceActions.lazyLoadCacheOfLoadedBatches = new DeepMap();
@@ -25173,6 +25254,7 @@ function useLazyLoadRange(options, dependencies) {
25173
25254
  loadRange(notifyRenderRangeChange.get(), {
25174
25255
  dismissLoadedRows: true
25175
25256
  });
25257
+ reloadedRef.current = true;
25176
25258
  } else {
25177
25259
  if (changes.originalLazyGroupDataChangeDetect || changes.groupRowsState) {
25178
25260
  loadRange(notifyRenderRangeChange.get());
@@ -27811,7 +27893,7 @@ var useLicense = (licenseKey = "") => {
27811
27893
  }
27812
27894
  let valid2 = isValidLicense(licenseKey, {
27813
27895
  publishedAt: 1624970570587,
27814
- version: "9.1.1"
27896
+ version: "9.1.3"
27815
27897
  });
27816
27898
  if (!licenseKey && !valid2 && isInsidePlayground) {
27817
27899
  return true;