reaflow
reaflow copied to clipboard
Feature request - Initialize Undo/Redo with existing history
It'd be great to be able to load an external history upon initializing the undo/redo feature.
It's already supported by the Undoo lib, through the import(history)
API, so it should be trivial to implement.
https://github.com/fabioricali/undoo#undooimporthistory--undoo
I suppose changing the UndoProps
by adding a initialHistory
prop would do the trick:
export interface UndoProps {
nodes: NodeData[];
edges: EdgeData[];
maxHistory?: number;
disabled?: boolean;
onUndoRedo: (state: UndoRedoEvent) => void;
initialHistory?: { nodes: NodeData[]; edges: EdgeData[]};
}
And then, instead of https://github.com/reaviz/reaflow/blob/147d64c4e8a5013cd12c98a6931e4d9e86519c7e/src/helpers/useUndo.ts#L42-L46:
const undoo = new Undoo({
maxLength: maxHistory
});
const manager = useRef<Undoo>(undoo);
manager.import({nodes, edges});
I guess that'd be it?
Ya - totally happy to accept that change.
I'll make a PR for this then. Thanks for confirming!
Started in https://github.com/reaviz/reaflow/pull/69