From a081bd0ed8d348958b3b602ddb61b7c02f2cb27b Mon Sep 17 00:00:00 2001 From: iMrDJAi <42304709+iMrDJAi@users.noreply.github.com> Date: Fri, 17 Jul 2020 16:01:29 +0100 Subject: [PATCH] 1.1.0 Release --- README.md | 69 +++++++++++++------------- index.html | 84 ++++++++++++++++---------------- package.json | 13 ++--- src/UndoRedo.js | 125 ++++++++++++++++++++++++------------------------ 4 files changed, 146 insertions(+), 145 deletions(-) diff --git a/README.md b/README.md index 849ca7e..4d73c8c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # UndoRedo.js [![npm](https://img.shields.io/npm/v/undoredo.js?color=red)](https://www.npmjs.com/package/undoredo.js) -A powerful and simple javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐 +A powerful and simple Javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐 *** ## Install: **Node.js**: @@ -12,7 +12,7 @@ npm install undoredo.js --save ``` Then simply require it: ```js -const UndoRedojs = require("undoredo.js"); +const UndoRedojs = require("undoredo.js") ``` **Browser**: @@ -38,58 +38,61 @@ By the same way you can use `UndoRedo.min.js` instead, which is a minified versi The main function will be declared as `window.UndoRedojs`: ```js -const UndoRedojs = window.UndoRedojs; +const UndoRedojs = window.UndoRedojs ``` +You can also bundle it info your project using [Webpack](https://webpack.js.org/guides/getting-started/). You can use it in anyway you want, it's just another npm packege after all! 😅 + ## Usage: -This package is useful for any step-by-step tasks, for example: +This package is useful for any step-by-step task, for example: - Undo/Redo functionality for a text input. - Something like a browser history. - A settings page. +- A files explorer. - And more... **Basic usage**: >Lets setup our history: ```js - const myHistory = UndoRedojs(5); + const myHistory = new UndoRedojs(5) ``` ->This function will return an object with the methods and the properties that we will use later. +>This will return a class object with the methods and the properties that we will use later. > >As you can see, we added the number **5** as a parameter, this will be used for cooldowns, keep reading for more details. > >To push new elements to the history, use the `record` method: ```js -myHistory.record('1'); -myHistory.record('12'); -myHistory.record('123'); -myHistory.record('1234'); -myHistory.record('12345'); -myHistory.record('123456'); -myHistory.record('1234567', true); +myHistory.record('1') +myHistory.record('12') +myHistory.record('123') +myHistory.record('1234') +myHistory.record('12345') +myHistory.record('123456') +myHistory.record('1234567', true) ``` >To get the history array, use the `stack` property: ```js -console.log(myHistory.stack); +console.log(myHistory.stack) // output => Array(4) [ "", "12345", "123456", "1234567" ] ``` >You can get the current history position using the `currentNumber` property: ```js -console.log(myHistory.currentNumber); +console.log(myHistory.currentNumber) // output => 3 ``` >Remember that arrays always start from **0**, so the number **3** here is actually the **4th** element, wanna check? ```js -console.log(myHistory.stack[myHistory.currentNumber]); +console.log(myHistory.stack[myHistory.currentNumber]) // output => "1234567" ``` >There is another way to get the current element, using the `current` method: ```js -console.log(myHistory.current()); +console.log(myHistory.current()) // output => "1234567" ``` ->The history array always starts with an empty element, this is helpful. +>The history array always starts with an empty element, this can be very helpful for text areas. > >So we called the `record` method 7 times, but we only got 3 recorded elements (without the 1st empty one). Why? > @@ -99,7 +102,7 @@ console.log(myHistory.current()); > >To disable that, just use the number **1**, or keep it empty because the default `cooldownNumber` is **1**: ```js - const myHistory = UndoRedojs(); + const myHistory = UndoRedojs() ``` > >But we see that the `"1234567"` element is recorded during a cooldown. Why? @@ -108,10 +111,10 @@ console.log(myHistory.current()); > >To undo, just use the `undo` method: ```js -const undo = myHistory.undo(); -console.log(undo); +const undo = myHistory.undo() +console.log(undo) // output => "123456" -console.log(myHistory.current()); +console.log(myHistory.current()) // output => "123456" ``` >So the `undo` method will make you step back once inside the array and will return the previous element. @@ -128,13 +131,13 @@ console.log(myHistory.current()); > >To redo, just use the `redo` method: ```js -const redo = myHistory.redo(); -console.log(redo); +const redo = myHistory.redo() +console.log(redo) // output => "1234567" -console.log(myHistory.current()); +console.log(myHistory.current()) // output => "1234567" ``` ->So the `undo` method will make you step forward once inside the array and will return the next element. +>So the `redo` method will make you step forward once inside the array and will return the next element. > >What if we add `true` as a parameter? ```js @@ -148,9 +151,9 @@ console.log(myHistory.current()); > >What if we undo then record then redo again? ```js -myHistory.undo(); -myHistory.record('12345678'); -console.log(myHistory.redo()); +myHistory.undo() +myHistory.record('12345678') +console.log(myHistory.redo()) // output => undefined ``` >Why? Because the `record` method will remove every next element. @@ -165,10 +168,12 @@ You can find a good example of a textarea with working undo/redo buttons [here]( That's a [live demo](https://imrdjai.github.io/UndoRedo.js). +## Dependents Projects: +Wanna use **UndoRedo.js** on your next big project? Let me now and it will be listed here! :) + ## Notes: -- This package has made by [${Mr.DJA}](https://invite.gg/MrDJA). -- This is my first package, leave a star if you like it. -- You are free to suggest anything and I will add it soon if I found it useful. +- This is my first package, leave a star if you like it <3. +- You are free to suggest anything and I will try to add it soon if I found it useful. - If you found any mistake (including the README file) feel free to help to fix it. - Please report any bugs. - **Made with ❤ in Algeria 🇩🇿**. diff --git a/index.html b/index.html index 7d1cd98..e28fe06 100644 --- a/index.html +++ b/index.html @@ -2,54 +2,54 @@
- -