undo-anything.js

Universal Ctrl+Z for any web action.
DOM mutations, inputs, custom actions. 2 lines of code.

๐Ÿ“ฆ npm v0.1.0 โญ GitHub ๐Ÿ“– Docs
$ npm install undo-anything
๐Ÿงฌ

DOM mutations

Any element added or removed is automatically tracked and restorable

โœ๏ธ

Input changes

Text field modifications are saved on blur and fully reversible

โšก

Custom actions

Push any action with your own undo/redo logic via Undo.push()

โšก Quick start

import Undo from 'undo-anything' // Watch any container Undo.watch('#my-list') // Custom action Undo.push({ label: 'My action', undo: () => revert(), redo: () => apply(), }) // Manual control Undo.undo() Undo.redo() Undo.clear()

๐Ÿงช Live demo

๐Ÿ“ Task list โ€” delete items then Ctrl+Z

  • Buy groceries
  • Call the doctor
  • Finish the project

โšก Custom actions

๐Ÿ’ก DevTools open? Try Ctrl+Z right now

Waiting for actions...

๐Ÿ“‹ All options

Undo.watch('#container', { maxHistory: 50, shortcut: true, toast: true, onUndo: (action) => {}, onRedo: (action) => {}, })

โŒจ๏ธ Keyboard shortcuts

ShortcutAction
Ctrl+Z / Cmd+ZUndo last action
Ctrl+YRedo
Ctrl+Shift+ZRedo (alt)

โœ… What gets tracked

Action
Element removedโœ… restored at position
Element addedโœ… removed on undo
Attribute changedโœ… reverted
Input blurโœ… value reverted
Custom push()โœ… anything you define

โš›๏ธ React

import Undo from 'undo-anything' import { useEffect } from 'react' function TaskList() { useEffect(() => { Undo.watch('#list') return () => Undo.unwatch('#list') }, []) return <ul id="list">...</ul> }