@infinite-table/infinite-react 9.1.0 → 9.1.2

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,
@@ -22425,6 +22471,40 @@ function lazyLoadRange(options, cache) {
22425
22471
  }, initialPromise);
22426
22472
  }
22427
22473
 
22474
+ // src/components/InfiniteTable/utils/getEditingCellContext.ts
22475
+ function resolveEditingCellRowIndex(context, editingCell) {
22476
+ const { rowIndex, primaryKey } = editingCell;
22477
+ const { dataArray } = context.getDataSourceState();
22478
+ if (primaryKey !== void 0) {
22479
+ const indexByKey = context.dataSourceApi.getIndexByPrimaryKey(primaryKey);
22480
+ if (indexByKey !== -1) {
22481
+ return indexByKey;
22482
+ }
22483
+ if (dataArray[rowIndex]?.id !== primaryKey) {
22484
+ return -1;
22485
+ }
22486
+ }
22487
+ return dataArray[rowIndex] ? rowIndex : -1;
22488
+ }
22489
+ function getEditingCellContext(context, editingCell) {
22490
+ const rowIndex = resolveEditingCellRowIndex(context, editingCell);
22491
+ if (rowIndex === -1) {
22492
+ return null;
22493
+ }
22494
+ return getCellContext({
22495
+ ...context,
22496
+ rowIndex,
22497
+ columnId: editingCell.columnId
22498
+ });
22499
+ }
22500
+ function warnEditedRowGone(callbackName, editingCell) {
22501
+ console.warn(
22502
+ `Skipping "${callbackName}": the edited row (primaryKey: ${String(
22503
+ editingCell.primaryKey
22504
+ )}, rowIndex: ${editingCell.rowIndex}) is no longer in the data array.`
22505
+ );
22506
+ }
22507
+
22428
22508
  // src/components/InfiniteTable/api/realignColumnContextMenu.ts
22429
22509
  function realignColumnContextMenu(param) {
22430
22510
  const { getComputed, getState, actions } = param;
@@ -23301,9 +23381,28 @@ var InfiniteTableApiImpl = class {
23301
23381
  waiting: "persist"
23302
23382
  };
23303
23383
  }
23384
+ const rowIndex = resolveEditingCellRowIndex(
23385
+ { ...this.context, api: this },
23386
+ editingCell
23387
+ );
23388
+ if (rowIndex === -1) {
23389
+ const error4 = new Error(
23390
+ `Cannot persist edit: the edited row (primaryKey: ${String(
23391
+ editingCell.primaryKey
23392
+ )}, rowIndex: ${editingCell.rowIndex}) is no longer in the data array.`
23393
+ );
23394
+ this.actions.editingCell = {
23395
+ ...editingCell,
23396
+ active: false,
23397
+ accepted: false,
23398
+ waiting: false,
23399
+ persisted: error4
23400
+ };
23401
+ return Promise.resolve(error4);
23402
+ }
23304
23403
  const params = {
23305
23404
  ...getCellContext({
23306
- rowIndex: editingCell.rowIndex,
23405
+ rowIndex,
23307
23406
  columnId: editingCell.columnId,
23308
23407
  ...this.context,
23309
23408
  api: this
@@ -27697,7 +27796,7 @@ var useLicense = (licenseKey = "") => {
27697
27796
  }
27698
27797
  let valid2 = isValidLicense(licenseKey, {
27699
27798
  publishedAt: 1624970570587,
27700
- version: "9.1.0"
27799
+ version: "9.1.2"
27701
27800
  });
27702
27801
  if (!licenseKey && !valid2 && isInsidePlayground) {
27703
27802
  return true;
@@ -30352,15 +30451,19 @@ function useOnEditCancelled() {
30352
30451
  const cancelled = editingCell && !editingCell.active ? editingCell.cancelled : void 0;
30353
30452
  useEffect33(() => {
30354
30453
  if (cancelled) {
30355
- const { rowIndex, columnId, initialValue } = getState().editingCell;
30356
30454
  const { onEditCancelled } = getState();
30357
- onEditCancelled?.({
30358
- ...getCellContext({
30359
- rowIndex,
30360
- columnId,
30361
- ...context
30362
- }),
30363
- initialValue
30455
+ const editingCell2 = getState().editingCell;
30456
+ if (!onEditCancelled) {
30457
+ return;
30458
+ }
30459
+ const cellContext = getEditingCellContext(context, editingCell2);
30460
+ if (!cellContext) {
30461
+ warnEditedRowGone("onEditCancelled", editingCell2);
30462
+ return;
30463
+ }
30464
+ onEditCancelled({
30465
+ ...cellContext,
30466
+ initialValue: editingCell2.initialValue
30364
30467
  });
30365
30468
  }
30366
30469
  }, [cancelled]);
@@ -30376,17 +30479,21 @@ function useOnEditRejected() {
30376
30479
  const rejected = editingCell && !editingCell.active && editingCell.accepted instanceof Error ? editingCell.accepted : void 0;
30377
30480
  useEffect33(() => {
30378
30481
  if (rejected) {
30379
- const { rowIndex, columnId, value, initialValue } = getState().editingCell;
30380
30482
  const { onEditRejected } = getState();
30381
- onEditRejected?.({
30382
- ...getCellContext({
30383
- rowIndex,
30384
- columnId,
30385
- ...context
30386
- }),
30387
- value,
30483
+ const editingCell2 = getState().editingCell;
30484
+ if (!onEditRejected) {
30485
+ return;
30486
+ }
30487
+ const cellContext = getEditingCellContext(context, editingCell2);
30488
+ if (!cellContext) {
30489
+ warnEditedRowGone("onEditRejected", editingCell2);
30490
+ return;
30491
+ }
30492
+ onEditRejected({
30493
+ ...cellContext,
30494
+ value: editingCell2.value,
30388
30495
  error: rejected,
30389
- initialValue
30496
+ initialValue: editingCell2.initialValue
30390
30497
  });
30391
30498
  }
30392
30499
  }, [rejected]);
@@ -30417,18 +30524,17 @@ function useOnEditAccepted() {
30417
30524
  const accepted = editingCell && !editingCell.active && !editingCell.cancelled && editingCell.accepted === true;
30418
30525
  useEffect33(() => {
30419
30526
  if (accepted) {
30420
- const { editingCell: editingCell2 } = getState();
30421
- const { value, rowIndex, columnId, initialValue } = editingCell2;
30422
- const editParams = {
30423
- ...getCellContext({
30424
- rowIndex,
30425
- columnId,
30426
- ...context
30427
- }),
30428
- value,
30429
- initialValue
30430
- };
30431
- getState().onEditAccepted?.(editParams);
30527
+ const { onEditAccepted } = getState();
30528
+ const editingCell2 = getState().editingCell;
30529
+ const { value, initialValue } = editingCell2;
30530
+ if (onEditAccepted) {
30531
+ const cellContext = getEditingCellContext(context, editingCell2);
30532
+ if (cellContext) {
30533
+ onEditAccepted({ ...cellContext, value, initialValue });
30534
+ } else {
30535
+ warnEditedRowGone("onEditAccepted", editingCell2);
30536
+ }
30537
+ }
30432
30538
  context.api.persistEdit({ value });
30433
30539
  }
30434
30540
  }, [accepted]);
@@ -30448,15 +30554,19 @@ function useOnEditPersisted() {
30448
30554
  if (!editingCell2) {
30449
30555
  return;
30450
30556
  }
30451
- const { rowIndex, columnId, value, initialValue } = editingCell2;
30557
+ const callbackName = persisted instanceof Error ? "onEditPersistError" : "onEditPersistSuccess";
30558
+ if (!getState()[callbackName]) {
30559
+ return;
30560
+ }
30561
+ const cellContext = getEditingCellContext(context, editingCell2);
30562
+ if (!cellContext) {
30563
+ warnEditedRowGone(callbackName, editingCell2);
30564
+ return;
30565
+ }
30452
30566
  const params = {
30453
- ...getCellContext({
30454
- rowIndex,
30455
- columnId,
30456
- ...context
30457
- }),
30458
- value,
30459
- initialValue
30567
+ ...cellContext,
30568
+ value: editingCell2.value,
30569
+ initialValue: editingCell2.initialValue
30460
30570
  };
30461
30571
  if (persisted instanceof Error) {
30462
30572
  onEditPersistError?.({ ...params, error: persisted });