Detalhes do pacote

undoo

fabioricali69.6kMIT0.5.0

Undo/redo manager

history, redo, undo, manager

readme (leia-me)

Undoo

Undo/redo manager

Installation

Node.js

npm install undoo --save

Browser

Local

<script src="node_modules/undoo/dist/undoo.min.js"></script>

CDN unpkg

<script src="https://unpkg.com/undoo/dist/undoo.min.js"></script>

Example

const Undoo = require('undoo');

const myHistory = new Undoo();

myHistory
    .save('one')
    .save('two')
    .save('three')
    .save('four');

myHistory.undo((item)=>{
    console.log(item); //=> three
});

myHistory.current(); //=> three

myHistory.redo((item)=>{
    console.log(item); //=> four
});

Use provider

const Undoo = require('undoo');

const myHistory = new Undoo({
    provider: () => document.getElementById('myTextArea').value
});

myHistory.save();

API

Undoo

Kind: global class

new Undoo([opts])

Create instance

ParamTypeDefaultDescription
[opts]Object

configuration object

[opts.provider]function

optional function called on save that returns new state for history

[opts.maxLength]number20

max length history

undoo.canUndo() ⇒ boolean

Check if undo is available

Kind: instance method of Undoo

undoo.canRedo() ⇒ boolean

Kind: instance method of Undoo
Check: if redo is available

undoo.import(history) ⇒ Undoo

Import external history

Kind: instance method of Undoo

ParamType
historyArray

undoo.history() ⇒ Array

Get history

Kind: instance method of Undoo

undoo.save([item]) ⇒ Undoo

Save history

Kind: instance method of Undoo

ParamType
[item]*

undoo.suspendSave([state]) ⇒ Undoo

Suspend save method

Kind: instance method of Undoo

ParamTypeDefault
[state]booleantrue

undoo.allowedSave() ⇒ boolean

Check if save is allowed

Kind: instance method of Undoo

undoo.clear() ⇒ Undoo

Clear history

Kind: instance method of Undoo

undoo.undo([callback]) ⇒ Undoo

Undo

Kind: instance method of Undoo

ParamTypeDescription
[callback]undoCallback

callback function

undoo.redo([callback]) ⇒ Undoo

Redo

Kind: instance method of Undoo

ParamTypeDescription
[callback]redoCallback

callback function

undoo.current() ⇒ *

Get current item in history

Kind: instance method of Undoo

undoo.count() ⇒ number

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.onUpdate(callback) ⇒ Undoo

Triggered when history is updated

Kind: instance method of Undoo

ParamTypeDescription
callbackupdateCallback

callback function

undoo.onMaxLength(callback) ⇒ Undoo

Triggered when maxLength is exceeded

Kind: instance method of Undoo

ParamTypeDescription
callbackmaxLengthCallback

callback function

undoo.onBeforeSave(callback) ⇒ Undoo

Triggered before save

Kind: instance method of Undoo

ParamTypeDescription
callbackbeforeSaveCallback

callback function

Example

// If callback returns `false` the save command will not be executed
myHistory.onBeforeSave(()=>false)

// You can overwrite item before save
myHistory.onBeforeSave((item)=>{
     return item.toUpperCase();
})

Undoo~undoCallback : function

undo callback

Kind: inner typedef of Undoo

ParamTypeDescription
item*

current history item

Undoo~redoCallback : function

redo callback

Kind: inner typedef of Undoo

ParamTypeDescription
item*

current history item

Undoo~updateCallback : function

onUpdate callback

Kind: inner typedef of Undoo

ParamTypeDescription
item*

current history item

actionstring

action that has called update event. Can be: redo, undo, save, clear

historyArray

history array

istanceUndoo

Undoo~maxLengthCallback : function

onMaxLength callback

Kind: inner typedef of Undoo

ParamTypeDescription
item*

current history item

historyArray

history array

istanceUndoo

Undoo~beforeSaveCallback : function

onBeforeSave callback

Kind: inner typedef of Undoo

ParamTypeDescription
item*

current history item

istanceUndoo

Changelog

You can view the changelog here

License

Undoo is open-sourced software licensed under the MIT license

Author

Fabio Ricali

changelog (log de mudanças)

Change Log

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

[0.5.0] - 2018-02-15

  • Added suspendSave method
  • Added allowedSave method

[0.4.0] - 2018-02-15

  • Added onMaxLength event
  • Added initialState method

[0.3.2] - 2018-02-15

  • Fixed canUndo issue

[0.3.1] - 2018-02-15

  • Changed canRedo and canUndo method, now are public
  • Improved onUpdate now last argument returns history array

[0.3.0] - 2018-02-15

  • Added onBeforeSave method

[0.2.0] - 2018-02-14

  • Added import method, now it's possible load external array history
  • Added history method, now it's possible get current history

[0.1.0] - 2018-02-13

  • Added items equals check,
  • Changed now onUpdate returns the instance
  • Minor fix

[0.0.1] - 2018-02-12

  • First release