synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
54 lines • 1.78 kB
TypeScript
import { DataGridRow, Operation } from '../DataGridTypes';
import { ModelChange } from '../utils/applyModelChange';
/**
* Represents a single action in the grid that can be undone or redone
*/
export type SingleGridAction = {
type: 'CREATE' | 'DELETE' | 'UPDATE';
rowIndex: number;
previousValue?: DataGridRow;
newValue?: DataGridRow;
};
/**
* Composite action for batch undo/redo
*/
export type CompositeGridAction = {
type: 'COMPOSITE';
actions: SingleGridAction[];
};
/**
* GridAction can be a single or composite action
*/
export type GridAction = SingleGridAction | CompositeGridAction;
/**
* Helper to batch multiple single actions into a composite action
*/
export declare function batchGridActions(actions: SingleGridAction[]): CompositeGridAction;
/**
* Hook to manage undo/redo functionality for a grid backed by a CRDT model.
*
* @param onApplyModelChange - Function to apply model changes and commit
*/
export declare function useGridUndoRedo(onApplyModelChange: (change: ModelChange) => void): {
undoPreview: {
lastType: string;
sameTypeCount: number;
totalActions: number;
} | null;
handleUndo: () => void;
addToUndoStack: (action: GridAction) => void;
clearUndoStack: () => void;
addOperationsToUndoStack: (operations: Operation[], rowValues: DataGridRow[], newValue: DataGridRow[]) => void;
undoUI: import("react/jsx-runtime").JSX.Element;
undoTotalActions: number;
redoPreview: {
lastType: string;
sameTypeCount: number;
totalActions: number;
} | null;
redoUI: import("react/jsx-runtime").JSX.Element;
redoTotalActions: number;
handleRedo: () => void;
clearRedoStack: () => void;
};
//# sourceMappingURL=useGridUndoRedo.d.ts.map