Basic undo and redo prototype implementation on Fabric.js
npm i fabric-history
Node projects
import 'fabric-history';
Or html
<script src="https://raw.githubusercontent.com/lyzerk/fabric-history/master/index.js"></script>
Initialization of the plugin is important, it listening the actions by that event registrations.
Don't call historyInit
more than once. And don't forget to dispose it.
var canvas = new fabric.Canvas('canvas');
// historyInit is registers the events
canvas.historyInit();
// historyDispose is un-register the events
canvas.historyDispose();
Following commands will undo and redo the canvas.
canvas.undo();
canvas.redo();