@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.mjs CHANGED
@@ -2647,6 +2647,27 @@ function resizeClamp(value, min, max, direction) {
2647
2647
  }
2648
2648
  return { value, clamped: false, diff: 0 };
2649
2649
  }
2650
+ function hasFlexDeficit(items, availableSize, reservedWidth) {
2651
+ let hasFlex = false;
2652
+ let totalWidth = 0;
2653
+ for (const item of items) {
2654
+ if (item.computedFlex) {
2655
+ hasFlex = true;
2656
+ }
2657
+ totalWidth += item.computedWidth;
2658
+ }
2659
+ return hasFlex && Math.round(totalWidth) > Math.round(availableSize - reservedWidth);
2660
+ }
2661
+ function getResizeSizingProperty(item, flexDeficit) {
2662
+ return item.computedFlex && !flexDeficit ? "flex" : "width";
2663
+ }
2664
+ function withResizedSize(entry, property, size) {
2665
+ if (property === "width") {
2666
+ const { flex: _flex, ...rest } = entry ?? {};
2667
+ return { ...rest, width: size };
2668
+ }
2669
+ return { ...entry, flex: size };
2670
+ }
2650
2671
  var computeResize = (params) => {
2651
2672
  const { availableSize, reservedWidth = 0 } = params;
2652
2673
  const columnSizing = Object.keys(
@@ -2665,14 +2686,19 @@ var computeResize = (params) => {
2665
2686
  const secondItem = params.items[secondIndex];
2666
2687
  const firstId = firstItem.id;
2667
2688
  const secondId = secondItem?.id;
2689
+ const flexDeficit = hasFlexDeficit(
2690
+ params.items,
2691
+ availableSize,
2692
+ reservedWidth
2693
+ );
2668
2694
  const firstSize = firstItem.computedWidth;
2669
2695
  const firstMinSize = firstItem.computedMinWidth;
2670
2696
  const firstMaxSize = firstItem.computedMaxWidth;
2671
- const firstPropertyToAdjust = firstItem.computedFlex ? "flex" : "width";
2697
+ const firstPropertyToAdjust = getResizeSizingProperty(firstItem, flexDeficit);
2672
2698
  const secondSize = secondItem?.computedWidth;
2673
2699
  const secondMinSize = secondItem?.computedMinWidth;
2674
2700
  const secondMaxSize = secondItem?.computedMaxWidth;
2675
- const secondPropertyToAdjust = secondItem?.computedFlex ? "flex" : "width";
2701
+ const secondPropertyToAdjust = secondItem ? getResizeSizingProperty(secondItem, flexDeficit) : "width";
2676
2702
  let maxReached = false;
2677
2703
  let minReached = false;
2678
2704
  const direction = dragHandleOffset > 0 ? 1 : -1;
@@ -2681,17 +2707,18 @@ var computeResize = (params) => {
2681
2707
  clamped: firstClamped,
2682
2708
  diff: firstDiff
2683
2709
  } = resizeClamp(
2684
- firstSize + dragHandleOffset,
2710
+ Math.round(firstSize + dragHandleOffset),
2685
2711
  firstMinSize,
2686
2712
  firstMaxSize,
2687
2713
  direction
2688
2714
  );
2689
2715
  if (params.shareSpaceOnResize) {
2690
2716
  if (secondItem == null) {
2691
- columnSizing[firstId] = {
2692
- ...columnSizing[firstId],
2693
- [firstPropertyToAdjust]: firstAdjustedSize
2694
- };
2717
+ columnSizing[firstId] = withResizedSize(
2718
+ columnSizing[firstId],
2719
+ firstPropertyToAdjust,
2720
+ firstAdjustedSize
2721
+ );
2695
2722
  minReached = firstClamped === "min";
2696
2723
  maxReached = firstClamped === "max";
2697
2724
  const adjustedDiff2 = firstAdjustedSize - firstSize;
@@ -2709,7 +2736,7 @@ var computeResize = (params) => {
2709
2736
  clamped: secondClamped,
2710
2737
  diff: secondDiff
2711
2738
  } = resizeClamp(
2712
- secondSize - dragHandleOffset,
2739
+ Math.round(secondSize - dragHandleOffset),
2713
2740
  secondMinSize,
2714
2741
  secondMaxSize,
2715
2742
  direction
@@ -2724,7 +2751,7 @@ var computeResize = (params) => {
2724
2751
  if (!firstClamped && !secondClamped) {
2725
2752
  } else if (firstClamped) {
2726
2753
  const clampResultForSecond = resizeClamp(
2727
- secondSize - dragHandleOffset - firstDiff,
2754
+ Math.round(secondSize - dragHandleOffset - firstDiff),
2728
2755
  secondMinSize,
2729
2756
  secondMaxSize,
2730
2757
  direction
@@ -2734,7 +2761,7 @@ var computeResize = (params) => {
2734
2761
  secondDiff = clampResultForSecond.diff;
2735
2762
  } else if (secondClamped) {
2736
2763
  const clampResultForFirst = resizeClamp(
2737
- firstSize + dragHandleOffset + secondDiff,
2764
+ Math.round(firstSize + dragHandleOffset + secondDiff),
2738
2765
  firstMinSize,
2739
2766
  firstMaxSize,
2740
2767
  direction
@@ -2743,28 +2770,31 @@ var computeResize = (params) => {
2743
2770
  firstClamped = clampResultForFirst.clamped;
2744
2771
  firstDiff = clampResultForFirst.diff;
2745
2772
  }
2746
- columnSizing[firstId] = {
2747
- ...columnSizing[firstId],
2748
- [firstPropertyToAdjust]: firstAdjustedSize
2749
- };
2750
- columnSizing[secondId] = {
2751
- ...columnSizing[secondId],
2752
- [secondPropertyToAdjust]: secondAdjustedSize
2753
- };
2773
+ columnSizing[firstId] = withResizedSize(
2774
+ columnSizing[firstId],
2775
+ firstPropertyToAdjust,
2776
+ firstAdjustedSize
2777
+ );
2778
+ columnSizing[secondId] = withResizedSize(
2779
+ columnSizing[secondId],
2780
+ secondPropertyToAdjust,
2781
+ secondAdjustedSize
2782
+ );
2754
2783
  minReached = firstClamped === "min" || secondClamped === "min";
2755
2784
  maxReached = firstClamped === "max" || secondClamped === "max";
2756
2785
  } else {
2757
- columnSizing[firstId] = {
2758
- ...columnSizing[firstId],
2759
- [firstPropertyToAdjust]: firstAdjustedSize
2760
- };
2786
+ columnSizing[firstId] = withResizedSize(
2787
+ columnSizing[firstId],
2788
+ firstPropertyToAdjust,
2789
+ firstAdjustedSize
2790
+ );
2761
2791
  minReached = firstClamped === "min";
2762
2792
  maxReached = firstClamped === "max";
2763
2793
  }
2764
2794
  const adjustedDiff = firstAdjustedSize - firstSize;
2765
2795
  return {
2766
2796
  adjustedDiff,
2767
- reservedWidth: !params.shareSpaceOnResize ? reservedWidth - adjustedDiff : reservedWidth,
2797
+ reservedWidth: !params.shareSpaceOnResize ? Math.round(reservedWidth - adjustedDiff) : reservedWidth,
2768
2798
  columnSizing,
2769
2799
  minReached,
2770
2800
  maxReached,
@@ -2798,8 +2828,13 @@ var computeGroupResize = (params) => {
2798
2828
  const beforeIndexes = [...new Array(params.columnGroupSize)].map((_, index) => params.dragHandlePositionAfter - index).reverse();
2799
2829
  const beforeItems = beforeIndexes.map((i) => params.items[i]);
2800
2830
  const beforeSizes = beforeItems.map((item) => item.computedWidth);
2831
+ const flexDeficit = hasFlexDeficit(
2832
+ params.items,
2833
+ availableSize,
2834
+ reservedWidth
2835
+ );
2801
2836
  const beforePropertiesToAdjust = beforeItems.map(
2802
- (item) => item.computedFlex ? "flex" : "width"
2837
+ (item) => getResizeSizingProperty(item, flexDeficit)
2803
2838
  );
2804
2839
  let unresizableWidth = 0;
2805
2840
  const { computedSizes } = computeFlex({
@@ -2848,10 +2883,11 @@ var computeGroupResize = (params) => {
2848
2883
  columnSizing: currentColumnSizing
2849
2884
  }
2850
2885
  );
2851
- columnSizing[item.id] = {
2852
- ...currentColumnSizing[item.id],
2853
- [propertyToAdjust]: itemSize + adjustedDiff2
2854
- };
2886
+ columnSizing[item.id] = withResizedSize(
2887
+ currentColumnSizing[item.id],
2888
+ propertyToAdjust,
2889
+ Math.round(itemSize + adjustedDiff2)
2890
+ );
2855
2891
  adjustedDiffs.push(adjustedDiff2);
2856
2892
  if (!maxReached) {
2857
2893
  groupMaxReached = false;
@@ -2871,7 +2907,7 @@ var computeGroupResize = (params) => {
2871
2907
  adjustedDiffs,
2872
2908
  adjustedDiff,
2873
2909
  columnSizing,
2874
- reservedWidth: reservedWidth - adjustedDiff
2910
+ reservedWidth: Math.round(reservedWidth - adjustedDiff)
2875
2911
  };
2876
2912
  };
2877
2913
 
@@ -3114,15 +3150,20 @@ var getComputedColumns = ({
3114
3150
  width: colType?.defaultWidth,
3115
3151
  flex: colType?.defaultFlex
3116
3152
  };
3117
- let colSizing = assignNonNull(
3118
- {
3119
- width: column?.defaultWidth,
3120
- flex: column?.defaultFlex,
3121
- minWidth: column?.minWidth,
3122
- maxWidth: column?.maxWidth
3123
- },
3124
- columnSizing[colId]
3125
- );
3153
+ const colDefaultSizing = {
3154
+ width: column?.defaultWidth,
3155
+ flex: column?.defaultFlex,
3156
+ minWidth: column?.minWidth,
3157
+ maxWidth: column?.maxWidth
3158
+ };
3159
+ const colSizingFromProp = columnSizing[colId];
3160
+ if (colSizingFromProp?.width != null && colSizingFromProp.flex == null) {
3161
+ delete colDefaultSizing.flex;
3162
+ }
3163
+ if (colSizingFromProp?.flex != null && colSizingFromProp.width == null) {
3164
+ delete colDefaultSizing.width;
3165
+ }
3166
+ let colSizing = assignNonNull(colDefaultSizing, colSizingFromProp);
3126
3167
  if (colSizing.width != null) {
3127
3168
  delete colTypeSizing.flex;
3128
3169
  }
@@ -8045,6 +8086,9 @@ import * as React30 from "react";
8045
8086
  import { useCallback as useCallback15 } from "react";
8046
8087
 
8047
8088
  // src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizeShared.ts
8089
+ function getResizeAvailableSize(bodySize) {
8090
+ return Math.max(bodySize.width - getScrollbarWidth(), 0);
8091
+ }
8048
8092
  function computeColumnResizeForDiff(options) {
8049
8093
  const { context, column, diff, shareSpaceOnResize } = options;
8050
8094
  const state = context.getState();
@@ -8067,7 +8111,7 @@ function computeColumnResizeForDiff(options) {
8067
8111
  } : columnSizing;
8068
8112
  return computeResize({
8069
8113
  shareSpaceOnResize,
8070
- availableSize: bodySize.width,
8114
+ availableSize: getResizeAvailableSize(bodySize),
8071
8115
  reservedWidth: viewportReservedWidth || 0,
8072
8116
  dragHandleOffset: diff,
8073
8117
  dragHandlePositionAfter: column.computedVisibleIndex,
@@ -8296,6 +8340,7 @@ function ResizeHandleFn(props) {
8296
8340
  const diff = Math.round(e2.clientX - initialX);
8297
8341
  const adjustedDiff = resizeDiff(diff, { done: true });
8298
8342
  restoreRenderRange();
8343
+ resizer.resize(0);
8299
8344
  props.onResize({ diff: adjustedDiff, shareSpaceOnResize });
8300
8345
  };
8301
8346
  target.addEventListener("pointermove", onPointerMove);
@@ -13705,6 +13750,7 @@ function GroupResizeHandleFn(props) {
13705
13750
  target.removeEventListener("pointerup", onPointerUp);
13706
13751
  const diff = Math.round(e2.clientX - initialX);
13707
13752
  const adjustedDiffs = resizeDiff(diff);
13753
+ resizer.resize(props.groupColumns.map(() => 0));
13708
13754
  props.onResize(adjustedDiffs);
13709
13755
  };
13710
13756
  target.addEventListener("pointermove", onPointerMove);
@@ -13774,7 +13820,7 @@ function useColumnGroupResizeHandle(groupColumns, config) {
13774
13820
  ...columnSizingWithFlex
13775
13821
  } : columnSizing;
13776
13822
  const result = computeGroupResize({
13777
- availableSize: bodySize.width,
13823
+ availableSize: getResizeAvailableSize(bodySize),
13778
13824
  reservedWidth: viewportReservedWidth || 0,
13779
13825
  dragHandleOffset: diff,
13780
13826
  dragHandlePositionAfter: lastColumnInGroup.computedVisibleIndex,
@@ -22322,6 +22368,23 @@ function computeFilterValueForRemote(filterValue, {
22322
22368
  }
22323
22369
  );
22324
22370
  }
22371
+ function createRemoteFilterValueMemo() {
22372
+ let prev;
22373
+ return (filterValue, filterTypes, filterMode) => {
22374
+ if (prev && prev.filterValue === filterValue && prev.filterTypes === filterTypes && prev.filterMode === filterMode) {
22375
+ return prev.result;
22376
+ }
22377
+ let result = computeFilterValueForRemote(filterValue, {
22378
+ filterTypes,
22379
+ filterMode
22380
+ });
22381
+ if (prev && prev.filterValue === filterValue && JSON.stringify(prev.result) === JSON.stringify(result)) {
22382
+ result = prev.result;
22383
+ }
22384
+ prev = { filterValue, filterTypes, filterMode, result };
22385
+ return result;
22386
+ };
22387
+ }
22325
22388
  var getRafPromise = () => new Promise((resolve) => {
22326
22389
  raf(resolve);
22327
22390
  });
@@ -22334,6 +22397,10 @@ function getDetailReady(masterContext, getDataSourceState) {
22334
22397
  isDetailReady
22335
22398
  };
22336
22399
  }
22400
+ function isFirstLazyBatchRequested(componentState) {
22401
+ const { lazyLoad, lazyLoadBatchSize, lazyLoadCacheOfLoadedBatches } = componentState;
22402
+ return !!lazyLoad && !!lazyLoadBatchSize && lazyLoadBatchSize > 0 && lazyLoadCacheOfLoadedBatches.has([0]);
22403
+ }
22337
22404
  function lazyLoadRange(options, cache) {
22338
22405
  const {
22339
22406
  startIndex,
@@ -24935,12 +25002,15 @@ function useLoadData(options) {
24935
25002
  }
24936
25003
  }
24937
25004
  }, [scrollbars.vertical]);
24938
- const computedFilterValue = useMemo11(() => {
24939
- return computeFilterValueForRemote(filterValue, {
24940
- filterTypes,
24941
- filterMode
24942
- });
24943
- }, [filterValue, filterMode, filterTypes]);
25005
+ const getRemoteFilterValue = useMemo11(
25006
+ () => createRemoteFilterValueMemo(),
25007
+ []
25008
+ );
25009
+ const computedFilterValue = getRemoteFilterValue(
25010
+ filterValue,
25011
+ filterTypes,
25012
+ filterMode
25013
+ );
24944
25014
  const depsObject = {
24945
25015
  // #sortMode_vs_shouldReloadData.sortInfo
24946
25016
  sortInfo: shouldReloadData.sortInfo ? sortInfo : null,
@@ -24951,14 +25021,19 @@ function useLoadData(options) {
24951
25021
  cursorId: livePagination ? stateCursorId : null
24952
25022
  };
24953
25023
  const initialRef = useRef25(true);
24954
- useLazyLoadRange(options, {
24955
- sortInfo,
24956
- groupBy,
24957
- pivotBy,
24958
- filterValue,
24959
- refetchKey,
24960
- cursorId: livePagination ? stateCursorId : null
24961
- });
25024
+ const lazyRangeReloadedRef = useRef25(false);
25025
+ useLazyLoadRange(
25026
+ options,
25027
+ {
25028
+ sortInfo,
25029
+ groupBy,
25030
+ pivotBy,
25031
+ filterValue,
25032
+ refetchKey,
25033
+ cursorId: livePagination ? stateCursorId : null
25034
+ },
25035
+ lazyRangeReloadedRef
25036
+ );
24962
25037
  const getMasterContext = useGetMasterDetailContext();
24963
25038
  const dataChangeTimestampsRef = useRef25([]);
24964
25039
  useEffectWithChanges(
@@ -25022,6 +25097,9 @@ function useLoadData(options) {
25022
25097
  }
25023
25098
  const componentState = getDataSourceState();
25024
25099
  if (typeof componentState.data === "function") {
25100
+ if (lazyRangeReloadedRef.current && !appendWhenLivePagination && isFirstLazyBatchRequested(componentState)) {
25101
+ return;
25102
+ }
25025
25103
  let marker;
25026
25104
  if (componentState.debugId) {
25027
25105
  marker = getMarker(
@@ -25043,6 +25121,9 @@ function useLoadData(options) {
25043
25121
  },
25044
25122
  { ...depsObject, data }
25045
25123
  );
25124
+ useEffect21(() => {
25125
+ lazyRangeReloadedRef.current = false;
25126
+ });
25046
25127
  useEffectWithChanges(() => {
25047
25128
  const componentState = getDataSourceState();
25048
25129
  if (initialRef.current) {
@@ -25056,7 +25137,7 @@ function useLoadData(options) {
25056
25137
  }
25057
25138
  }, depsObject);
25058
25139
  }
25059
- function useLazyLoadRange(options, dependencies) {
25140
+ function useLazyLoadRange(options, dependencies, reloadedRef) {
25060
25141
  const { getDataSourceState, dataSourceActions, dataSourceState } = options;
25061
25142
  useEffect21(() => {
25062
25143
  dataSourceActions.lazyLoadCacheOfLoadedBatches = new DeepMap();
@@ -25112,6 +25193,7 @@ function useLazyLoadRange(options, dependencies) {
25112
25193
  loadRange(notifyRenderRangeChange.get(), {
25113
25194
  dismissLoadedRows: true
25114
25195
  });
25196
+ reloadedRef.current = true;
25115
25197
  } else {
25116
25198
  if (changes.originalLazyGroupDataChangeDetect || changes.groupRowsState) {
25117
25199
  loadRange(notifyRenderRangeChange.get());
@@ -27750,7 +27832,7 @@ var useLicense = (licenseKey = "") => {
27750
27832
  }
27751
27833
  let valid2 = isValidLicense(licenseKey, {
27752
27834
  publishedAt: 1624970570587,
27753
- version: "9.1.1"
27835
+ version: "9.1.3"
27754
27836
  });
27755
27837
  if (!licenseKey && !valid2 && isInsidePlayground) {
27756
27838
  return true;