@alaarab/ogrid-react 2.1.6 → 2.1.7

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 (2) hide show
  1. package/dist/esm/index.js +50 -20
  2. package/package.json +2 -2
package/dist/esm/index.js CHANGED
@@ -1631,7 +1631,7 @@ var EMPTY_LOADING_OPTIONS2 = {};
1631
1631
  function useOGrid(props, ref) {
1632
1632
  const {
1633
1633
  columns: columnsProp,
1634
- getRowId,
1634
+ getRowId: getRowIdProp,
1635
1635
  data,
1636
1636
  dataSource,
1637
1637
  page: controlledPage,
@@ -1646,7 +1646,7 @@ function useOGrid(props, ref) {
1646
1646
  onFiltersChange,
1647
1647
  onVisibleColumnsChange,
1648
1648
  columnOrder,
1649
- onColumnOrderChange,
1649
+ onColumnOrderChange: onColumnOrderChangeProp,
1650
1650
  onColumnResized,
1651
1651
  onColumnPinned,
1652
1652
  defaultPageSize = DEFAULT_PAGE_SIZE,
@@ -1661,9 +1661,9 @@ function useOGrid(props, ref) {
1661
1661
  suppressHorizontalScroll,
1662
1662
  editable,
1663
1663
  cellSelection,
1664
- onCellValueChanged,
1665
- onUndo,
1666
- onRedo,
1664
+ onCellValueChanged: onCellValueChangedProp,
1665
+ onUndo: onUndoProp,
1666
+ onRedo: onRedoProp,
1667
1667
  canUndo,
1668
1668
  canRedo,
1669
1669
  rowSelection = "none",
@@ -1685,6 +1685,32 @@ function useOGrid(props, ref) {
1685
1685
  "aria-label": ariaLabel,
1686
1686
  "aria-labelledby": ariaLabelledBy
1687
1687
  } = props;
1688
+ const getRowIdStableRef = useLatestRef(getRowIdProp);
1689
+ const getRowId = useCallback((item) => getRowIdStableRef.current(item), [getRowIdStableRef]);
1690
+ const onColumnOrderChangeRef = useLatestRef(onColumnOrderChangeProp);
1691
+ const onColumnOrderChange = useMemo(
1692
+ () => onColumnOrderChangeProp ? (order) => onColumnOrderChangeRef.current?.(order) : void 0,
1693
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1694
+ [!!onColumnOrderChangeProp]
1695
+ );
1696
+ const onCellValueChangedRef = useLatestRef(onCellValueChangedProp);
1697
+ const onCellValueChanged = useMemo(
1698
+ () => onCellValueChangedProp ? (event) => onCellValueChangedRef.current?.(event) : void 0,
1699
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1700
+ [!!onCellValueChangedProp]
1701
+ );
1702
+ const onUndoRef = useLatestRef(onUndoProp);
1703
+ const onUndo = useMemo(
1704
+ () => onUndoProp ? () => onUndoRef.current?.() : void 0,
1705
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1706
+ [!!onUndoProp]
1707
+ );
1708
+ const onRedoRef = useLatestRef(onRedoProp);
1709
+ const onRedo = useMemo(
1710
+ () => onRedoProp ? () => onRedoRef.current?.() : void 0,
1711
+ // eslint-disable-next-line react-hooks/exhaustive-deps
1712
+ [!!onRedoProp]
1713
+ );
1688
1714
  const columnChooserPlacement = columnChooserProp === false ? "none" : columnChooserProp === "sidebar" ? "sidebar" : "toolbar";
1689
1715
  const columns = useMemo(() => flattenColumns(columnsProp), [columnsProp]);
1690
1716
  const isServerSide = dataSource != null;
@@ -2865,6 +2891,7 @@ function useKeyboardNavigation(params) {
2865
2891
  }
2866
2892
  function useUndoRedo(params) {
2867
2893
  const { onCellValueChanged, maxUndoDepth = 100 } = params;
2894
+ const onCellValueChangedRef = useLatestRef(onCellValueChanged);
2868
2895
  const stackRef = useRef(null);
2869
2896
  if (stackRef.current === null) {
2870
2897
  stackRef.current = new UndoRedoStack(maxUndoDepth);
@@ -2878,16 +2905,17 @@ function useUndoRedo(params) {
2878
2905
  }, []);
2879
2906
  const wrapped = useCallback(
2880
2907
  (event) => {
2881
- if (!onCellValueChanged) return;
2908
+ if (!onCellValueChangedRef.current) return;
2882
2909
  const stack = getStack();
2883
2910
  stack.record(event);
2884
2911
  if (!stack.isBatching) {
2885
2912
  setHistoryLength(stack.historyLength);
2886
2913
  setRedoLength(stack.redoLength);
2887
2914
  }
2888
- onCellValueChanged(event);
2915
+ onCellValueChangedRef.current(event);
2889
2916
  },
2890
- [onCellValueChanged, getStack]
2917
+ // eslint-disable-next-line react-hooks/exhaustive-deps
2918
+ [getStack]
2891
2919
  );
2892
2920
  const beginBatch = useCallback(() => {
2893
2921
  getStack().beginBatch();
@@ -2899,7 +2927,7 @@ function useUndoRedo(params) {
2899
2927
  setRedoLength(stack.redoLength);
2900
2928
  }, [getStack]);
2901
2929
  const undo = useCallback(() => {
2902
- if (!onCellValueChanged) return;
2930
+ if (!onCellValueChangedRef.current) return;
2903
2931
  const stack = getStack();
2904
2932
  const lastBatch = stack.undo();
2905
2933
  if (!lastBatch) return;
@@ -2907,24 +2935,24 @@ function useUndoRedo(params) {
2907
2935
  setRedoLength(stack.redoLength);
2908
2936
  for (let i = lastBatch.length - 1; i >= 0; i--) {
2909
2937
  const ev = lastBatch[i];
2910
- onCellValueChanged({
2938
+ onCellValueChangedRef.current({
2911
2939
  ...ev,
2912
2940
  oldValue: ev.newValue,
2913
2941
  newValue: ev.oldValue
2914
2942
  });
2915
2943
  }
2916
- }, [onCellValueChanged, getStack]);
2944
+ }, [getStack]);
2917
2945
  const redo = useCallback(() => {
2918
- if (!onCellValueChanged) return;
2946
+ if (!onCellValueChangedRef.current) return;
2919
2947
  const stack = getStack();
2920
2948
  const nextBatch = stack.redo();
2921
2949
  if (!nextBatch) return;
2922
2950
  setHistoryLength(stack.historyLength);
2923
2951
  setRedoLength(stack.redoLength);
2924
2952
  for (const ev of nextBatch) {
2925
- onCellValueChanged(ev);
2953
+ onCellValueChangedRef.current(ev);
2926
2954
  }
2927
- }, [onCellValueChanged, getStack]);
2955
+ }, [getStack]);
2928
2956
  return {
2929
2957
  onCellValueChanged: onCellValueChanged ? wrapped : void 0,
2930
2958
  undo,
@@ -2952,7 +2980,7 @@ function useFillHandle(params) {
2952
2980
  items,
2953
2981
  visibleCols,
2954
2982
  editable,
2955
- onCellValueChanged,
2983
+ onCellValueChanged: onCellValueChangedProp,
2956
2984
  selectionRange,
2957
2985
  setSelectionRange,
2958
2986
  setActiveCell,
@@ -2961,13 +2989,14 @@ function useFillHandle(params) {
2961
2989
  beginBatch,
2962
2990
  endBatch
2963
2991
  } = params;
2992
+ const onCellValueChangedRef = useLatestRef(onCellValueChangedProp);
2964
2993
  const [fillDrag, setFillDrag] = useState(null);
2965
2994
  const fillDragEndRef = useRef({ endRow: 0, endCol: 0 });
2966
2995
  const rafRef = useRef(0);
2967
2996
  const liveFillRangeRef = useRef(null);
2968
2997
  const colOffsetRef = useLatestRef(colOffset);
2969
2998
  useEffect(() => {
2970
- if (!fillDrag || editable === false || !onCellValueChanged || !wrapperRef.current) return;
2999
+ if (!fillDrag || editable === false || !onCellValueChangedRef.current || !wrapperRef.current) return;
2971
3000
  fillDragEndRef.current = { endRow: fillDrag.startRow, endCol: fillDrag.startCol };
2972
3001
  liveFillRangeRef.current = null;
2973
3002
  const markedCells = /* @__PURE__ */ new Set();
@@ -3081,7 +3110,7 @@ function useFillHandle(params) {
3081
3110
  const fillEvents = applyFillValues(norm, fillDrag.startRow, fillDrag.startCol, items, visibleCols);
3082
3111
  if (fillEvents.length > 0) {
3083
3112
  beginBatch?.();
3084
- for (const evt of fillEvents) onCellValueChanged(evt);
3113
+ for (const evt of fillEvents) onCellValueChangedRef.current?.(evt);
3085
3114
  endBatch?.();
3086
3115
  }
3087
3116
  setFillDrag(null);
@@ -3101,7 +3130,6 @@ function useFillHandle(params) {
3101
3130
  visibleCols,
3102
3131
  setSelectionRange,
3103
3132
  setActiveCell,
3104
- onCellValueChanged,
3105
3133
  beginBatch,
3106
3134
  endBatch,
3107
3135
  colOffsetRef,
@@ -3582,6 +3610,7 @@ function useDataGridEditing(params) {
3582
3610
  const [popoverAnchorEl, setPopoverAnchorEl] = useState(null);
3583
3611
  const visibleColsRef = useLatestRef(params.visibleCols);
3584
3612
  const itemsLengthRef = useLatestRef(params.itemsLength);
3613
+ const onCellValueChangedRef = useLatestRef(onCellValueChanged);
3585
3614
  const commitCellEdit = useCallback(
3586
3615
  (item, columnId, oldValue, newValue, rowIndex, globalColIndex) => {
3587
3616
  const col = visibleColsRef.current.find((c) => c.columnId === columnId);
@@ -3595,7 +3624,7 @@ function useDataGridEditing(params) {
3595
3624
  }
3596
3625
  newValue = result.value;
3597
3626
  }
3598
- onCellValueChanged?.({
3627
+ onCellValueChangedRef.current?.({
3599
3628
  item,
3600
3629
  columnId,
3601
3630
  oldValue,
@@ -3609,7 +3638,8 @@ function useDataGridEditing(params) {
3609
3638
  setActiveCell({ rowIndex: rowIndex + 1, columnIndex: globalColIndex });
3610
3639
  }
3611
3640
  },
3612
- [onCellValueChanged, setEditingCell, setPendingEditorValue, setActiveCell, visibleColsRef, itemsLengthRef]
3641
+ // eslint-disable-next-line react-hooks/exhaustive-deps
3642
+ [setEditingCell, setPendingEditorValue, setActiveCell, visibleColsRef, itemsLengthRef]
3613
3643
  );
3614
3644
  const cancelPopoverEdit = useCallback(() => {
3615
3645
  setEditingCell(null);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alaarab/ogrid-react",
3
- "version": "2.1.6",
3
+ "version": "2.1.7",
4
4
  "description": "OGrid React – React hooks, headless components, and utilities for OGrid data grids.",
5
5
  "main": "dist/esm/index.js",
6
6
  "module": "dist/esm/index.js",
@@ -39,7 +39,7 @@
39
39
  "node": ">=18"
40
40
  },
41
41
  "dependencies": {
42
- "@alaarab/ogrid-core": "2.1.6",
42
+ "@alaarab/ogrid-core": "2.1.7",
43
43
  "@tanstack/react-virtual": "^3.0.0"
44
44
  },
45
45
  "peerDependencies": {