Undoo
Undo/redo manager
Installation
Node.js
npm install undoo --save
Browser
Local
CDN unpkg
Example
const Undoo = ; const myHistory = ; myHistory ; myHistory; myHistorycurrent; //=> three myHistory;
Use provider
const Undoo = ; const myHistory = documentvalue; myHistory;
API
Undoo
Kind: global class
- Undoo
- new Undoo([opts])
- instance
- .canUndo() ⇒
boolean
- .canRedo() ⇒
boolean
- .import(history) ⇒
Undoo
- .history() ⇒
Array
- .save([item]) ⇒
Undoo
- .suspendSave([state]) ⇒
Undoo
- .allowedSave() ⇒
boolean
- .clear() ⇒
Undoo
- .undo([callback]) ⇒
Undoo
- .redo([callback]) ⇒
Undoo
- .current() ⇒
*
- .count() ⇒
number
- .initialState() ⇒
*
- .onUpdate(callback) ⇒
Undoo
- .onMaxLength(callback) ⇒
Undoo
- .onBeforeSave(callback) ⇒
Undoo
- .canUndo() ⇒
- inner
- ~undoCallback :
function
- ~redoCallback :
function
- ~updateCallback :
function
- ~maxLengthCallback :
function
- ~beforeSaveCallback :
function
- ~undoCallback :
new Undoo([opts])
Create instance
Param | Type | Default | Description |
---|---|---|---|
[opts] | Object | configuration object |
|
[opts.provider] | function |
| optional function called on save that returns new state for history |
[opts.maxLength] | number | 20 | max length history |
boolean
undoo.canUndo() ⇒ Check if undo is available
Kind: instance method of Undoo
boolean
undoo.canRedo() ⇒ Kind: instance method of Undoo
Check: if redo is available
Undoo
undoo.import(history) ⇒ Import external history
Kind: instance method of Undoo
Param | Type |
---|---|
history | Array |
Array
undoo.history() ⇒ Get history
Kind: instance method of Undoo
Undoo
undoo.save([item]) ⇒ Save history
Kind: instance method of Undoo
Param | Type |
---|---|
[item] | * |
Undoo
undoo.suspendSave([state]) ⇒ Suspend save method
Kind: instance method of Undoo
Param | Type | Default |
---|---|---|
[state] | boolean | true |
boolean
undoo.allowedSave() ⇒ Check if save is allowed
Kind: instance method of Undoo
Undoo
undoo.clear() ⇒ Clear history
Kind: instance method of Undoo
Undoo
undoo.undo([callback]) ⇒ Undo
Kind: instance method of Undoo
Param | Type | Description |
---|---|---|
[callback] | undoCallback | callback function |
Undoo
undoo.redo([callback]) ⇒ Redo
Kind: instance method of Undoo
Param | Type | Description |
---|---|---|
[callback] | redoCallback | callback function |
*
undoo.current() ⇒ Get current item in history
Kind: instance method of Undoo
number
undoo.count() ⇒ Count history items, the first element is not considered
Kind: instance method of Undoo
*
undoo.initialState() ⇒ Get initial state history
Kind: instance method of Undoo
Undoo
undoo.onUpdate(callback) ⇒ Triggered when history is updated
Kind: instance method of Undoo
Param | Type | Description |
---|---|---|
callback | updateCallback | callback function |
Undoo
undoo.onMaxLength(callback) ⇒ Triggered when maxLength is exceeded
Kind: instance method of Undoo
Param | Type | Description |
---|---|---|
callback | maxLengthCallback | callback function |
Undoo
undoo.onBeforeSave(callback) ⇒ Triggered before save
Kind: instance method of Undoo
Param | Type | Description |
---|---|---|
callback | beforeSaveCallback | callback function |
Example
// If callback returns `false` the save command will not be executedmyHistory // You can overwrite item before savemyHistory
function
Undoo~undoCallback : undo callback
Kind: inner typedef of Undoo
Param | Type | Description |
---|---|---|
item | * | current history item |
function
Undoo~redoCallback : redo callback
Kind: inner typedef of Undoo
Param | Type | Description |
---|---|---|
item | * | current history item |
function
Undoo~updateCallback : onUpdate callback
Kind: inner typedef of Undoo
Param | Type | Description |
---|---|---|
item | * | current history item |
action | string | action that has called update event. Can be: redo, undo, save, clear |
history | Array | history array |
istance | Undoo |
function
Undoo~maxLengthCallback : onMaxLength callback
Kind: inner typedef of Undoo
Param | Type | Description |
---|---|---|
item | * | current history item |
history | Array | history array |
istance | Undoo |
function
Undoo~beforeSaveCallback : onBeforeSave callback
Kind: inner typedef of Undoo
Param | Type | Description |
---|---|---|
item | * | current history item |
istance | Undoo |
Changelog
You can view the changelog here
License
Undoo is open-sourced software licensed under the MIT license