Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-undoable

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-undoable - npm Package Compare versions

Comparing version 0.1.3 to 0.2.0

yarn-error.log

18

dist/index.d.ts

@@ -7,15 +7,10 @@ import * as React from 'react';

interface IUndoableMethods<T> {
pushState(state: T): void;
pushState(state: T | Partial<T>): void;
redo(): T | undefined;
resetState(state?: T): void;
undo(): T | undefined;
updateState(state: T): void;
updateState(state: T | Partial<T>): void;
}
export interface IUndoable<T> {
export interface IUndoable<T> extends IUndoableMethods<T> {
currentState?: T;
pushState(state: T): void;
redo(): T | undefined;
resetState(state?: T): void;
undo(): T | undefined;
updateState(state: T): void;
}

@@ -27,2 +22,5 @@ interface IUndoableState<T> {

}
declare type Partial<T> = {
[P in keyof T]?: T[P];
};
export default class Undoable<T> extends React.Component<IUndoableProps<T>, IUndoableState<T>> {

@@ -39,7 +37,7 @@ readonly state: {

redo: () => undefined;
pushState: (state: T) => void;
pushState: (state: T | Partial<T>) => void;
resetState: (state: T) => void;
updateState: (state: T) => void;
updateState: (state: T | Partial<T>) => void;
render(): {} | null | undefined;
}
export {};

@@ -1,1 +0,1 @@

"use strict";var __extends=this&&this.__extends||function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),Undoable=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.state={currentState:void 0,previousState:[],nextState:[]},i.undo=function(){var t=i.state,e=t.previousState,r=t.nextState,n=t.currentState;if(e.length){var a=e.slice(),o=a.pop(),s=n;return i.setState({currentState:o,nextState:r.concat([s]),previousState:a}),o}},i.redo=function(){var t=i.state,e=t.previousState,r=t.nextState,n=t.currentState;if(r.length){var a=r.slice(),o=a.pop(),s=n;return i.setState({currentState:o,nextState:a,previousState:e.concat([s])}),o}},i.pushState=function(t){var e=i.state,r=e.currentState,n=e.previousState;i.setState({currentState:t,nextState:[],previousState:n.concat([r])})},i.resetState=function(t){i.setState({currentState:t,nextState:[],previousState:[]})},i.updateState=function(t){i.setState({currentState:t})},i}return __extends(e,t),e.getDerivedStateFromProps=function(t,e){return t.initialState&&void 0===e.currentState?{currentState:t.initialState}:null},e.prototype.render=function(){var t=this.props.children,e=__assign({},this.state,{undo:this.undo,redo:this.redo,pushState:this.pushState,resetState:this.resetState,updateState:this.updateState});return!!t&&t(e)},e}(React.Component);exports.default=Undoable;
"use strict";var __extends=this&&this.__extends||function(){var n=function(t,e){return(n=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])})(t,e)};return function(t,e){function r(){this.constructor=t}n(t,e),t.prototype=null===e?Object.create(e):(r.prototype=e.prototype,new r)}}(),__assign=this&&this.__assign||function(){return(__assign=Object.assign||function(t){for(var e,r=1,n=arguments.length;r<n;r++)for(var a in e=arguments[r])Object.prototype.hasOwnProperty.call(e,a)&&(t[a]=e[a]);return t}).apply(this,arguments)};Object.defineProperty(exports,"__esModule",{value:!0});var React=require("react"),deepMerge=require("deepmerge"),Undoable=function(t){function e(){var i=null!==t&&t.apply(this,arguments)||this;return i.state={currentState:void 0,previousState:[],nextState:[]},i.undo=function(){var t=i.state,e=t.previousState,r=t.nextState,n=t.currentState;if(e.length){var a=e.slice(),o=a.pop(),u=n;return i.setState({currentState:o,nextState:r.concat([u]),previousState:a}),o}},i.redo=function(){var t=i.state,e=t.previousState,r=t.nextState,n=t.currentState;if(r.length){var a=r.slice(),o=a.pop(),u=n;return i.setState({currentState:o,nextState:a,previousState:e.concat([u])}),o}},i.pushState=function(t){var e=i.state,r=e.currentState,n=e.previousState,a=deepMerge(r||{},t);i.setState({currentState:a,nextState:[],previousState:n.concat([r])})},i.resetState=function(t){i.setState({currentState:t,nextState:[],previousState:[]})},i.updateState=function(e){var t=i.state,r=t.currentState,n=t.nextState,a=t.previousState,o=deepMerge(r||{},e);i.setState({currentState:o,previousState:a.map(function(t){return deepMerge(t,e)}),nextState:n.map(function(t){return deepMerge(t,e)})})},i}return __extends(e,t),e.getDerivedStateFromProps=function(t,e){return t.initialState&&void 0===e.currentState?{currentState:t.initialState}:null},e.prototype.render=function(){var t=this.props.children,e=__assign({},this.state,{undo:this.undo,redo:this.redo,pushState:this.pushState,resetState:this.resetState,updateState:this.updateState});return!!t&&t(e)},e}(React.Component);exports.default=Undoable;
{
"name": "react-undoable",
"version": "0.1.3",
"version": "0.2.0",
"description": "Easily undo/redo any state in React, no external dependencies",

@@ -31,3 +31,5 @@ "scripts": {

},
"dependencies": {}
"dependencies": {
"deepmerge": "^3.1.0"
}
}

@@ -7,3 +7,3 @@ # react-undoable 🔄

Easily undo/redo any state in React, no external dependencies.
Easily undo/redo any state in React, no redux required.

@@ -185,4 +185,13 @@ ![minified size](https://badgen.net/bundlephobia/min/react-undoable)

## Use Cases
[Astral TableTop](https://www.astraltabletop.com) allows Game Masters to build feature-rich
dungeons and maps using a "Map Builder", a feature which resembles many familiar photo editing
interfaces and contains basic functionality such as undo/redo for editing actions. This library
allows developers to create undo/redo functionality for any React Component with minimal overhead.
We open-sourced this library in hopes that other projects might find it useful 💙
## License
MIT

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc