UNPKG

undoo

Version:
2 lines 8.32 kB
// [AIV] Undoo Build version: 0.5.0 !function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define("Undoo",[],e):"object"==typeof exports?exports.Undoo=e():t.Undoo=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){"use strict";t.exports=n(1)},function(t,e,n){"use strict";function i(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}var o=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}(),r=n(2),u=n(4),s=function(){function t(e){i(this,t),Object.defineProperties(this,{_opts:{writable:!0},_history:{writable:!0},_position:{writable:!0},_initialState:{writable:!0},_onUpdate:{writable:!0,value:function(){}},_onBeforeSave:{writable:!0,value:function(){}},_onMaxLength:{writable:!0,value:function(){}},_isExceeded:{writable:!0,value:!1},_suspendSave:{writable:!0,value:!1}}),this._opts=r.copy(e,{provider:null,maxLength:20}),this._initiliaze()}return o(t,[{key:"_initiliaze",value:function(){this._initialState=void 0,this._history=[],this._isExceeded=!1,this._position=0}},{key:"_checkMaxLength",value:function(){this._history.length>this._opts.maxLength?(this._history=this._history.slice(1,this._history.length),this._isExceeded||(this._onMaxLength.call(null,this.current(),this.history(),this),this._isExceeded=!0)):this._isExceeded=!1}},{key:"_rejectSave",value:function(t,e){return u(t,this.current())||!1===e||this._suspendSave}},{key:"canUndo",value:function(){return this._position>1}},{key:"canRedo",value:function(){return this._position<this._history.length}},{key:"import",value:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];if(!Array.isArray(t))throw new TypeError("Items must be an array");return this._initiliaze(),this._history=t,this._position=this._history.length,this._initialState=t[0],this}},{key:"history",value:function(){return this._history}},{key:"save",value:function(t){void 0===t&&"function"==typeof this._opts.provider&&(t=this._opts.provider());var e=this._onBeforeSave.call(null,t,this);return t=e||t,this._rejectSave(t,e)?this:(this._position<this._history.length&&(this._history=this._history.slice(0,this._position)),void 0!==t&&(this._history.push(t),void 0===this._initialState&&(this._initialState=t)),this._checkMaxLength(),this._position=this._history.length,this._onUpdate.call(null,this.current(),"save",this.history(),this),this)}},{key:"suspendSave",value:function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return this._suspendSave=t,this}},{key:"allowedSave",value:function(){return!this._suspendSave}},{key:"clear",value:function(){return this._initiliaze(),this._onUpdate.call(null,null,"clear",this.history(),this),this}},{key:"undo",value:function(t){return this.canUndo()&&(this._position--,"function"==typeof t&&t(this.current()),this._onUpdate.call(null,this.current(),"undo",this.history(),this)),this}},{key:"redo",value:function(t){return this.canRedo()&&(this._position++,"function"==typeof t&&t(this.current()),this._onUpdate.call(null,this.current(),"redo",this.history(),this)),this}},{key:"current",value:function(){return this._history.length?this._history[this._position-1]:null}},{key:"count",value:function(){return this._history.length?this._history.length-1:0}},{key:"initialState",value:function(){return this._initialState}},{key:"onUpdate",value:function(e){return t.callbackError(e),this._onUpdate=e,this}},{key:"onMaxLength",value:function(e){return t.callbackError(e),this._onMaxLength=e,this}},{key:"onBeforeSave",value:function(e){return t.callbackError(e),this._onBeforeSave=e,this}}],[{key:"callbackError",value:function(t){if("function"!=typeof t)throw new TypeError("callback must be a function")}}]),t}();t.exports=s},function(t,e,n){"use strict";(function(t){var n,i,o,r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};!function(u,s){"object"===r(e)&&"object"===r(t)?t.exports=s():(i=[],n=s,void 0!==(o="function"==typeof n?n.apply(e,i):n)&&(t.exports=o))}("undefined"!=typeof self&&self,function(){return function(t){function e(i){if(n[i])return n[i].exports;var o=n[i]={i:i,l:!1,exports:{}};return t[i].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,i){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:i})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=0)}([function(t,e,n){t.exports=n(1)},function(t,e,n){var i="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return void 0===t?"undefined":r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":r(t)},o=n(2),u=function t(e,n){var o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];for(var r in n)n.hasOwnProperty(r)&&-1===o.indexOf(r)&&(e.hasOwnProperty(r)&&void 0!==e[r]?"object"===i(e[r])&&t(e[r],n[r]):e[r]=n[r]);return e},s=function(){for(var t=arguments.length,e=Array(t),n=0;n<t;n++)e[n]=arguments[n];return e[0]=o(e[0]),u.apply(void 0,e)};t.exports=u,t.exports.copy=s},function(t,e,n){var i,o,u="function"==typeof Symbol&&"symbol"===r(Symbol.iterator)?function(t){return void 0===t?"undefined":r(t)}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":void 0===t?"undefined":r(t)};!function(r,s,a){"object"===u(e)?t.exports=a():(i=a,void 0!==(o="function"==typeof i?i.call(e,n,e,t):i)&&(t.exports=o))}(0,0,function(){function t(t,e,n){return t instanceof Array?(t.push(n),t[t.length-1]):t instanceof Object?(t[e]=n,t[e]):void 0}return function(e){function n(e,i){for(var o in e){var r=e[o];if(r instanceof Date){var u=new Date(r.getTime());t(i,o,u)}else if(r instanceof Function){var u=r;t(i,o,u)}else if(r instanceof Array){var u=[],s=t(i,o,u);n(r,s)}else if(r instanceof Object){var u={},s=t(i,o,u);n(r,s)}else{var u=r;t(i,o,u)}}}if(/number|string|boolean/.test(void 0===e?"undefined":u(e)))return e;if(e instanceof Date)return new Date(e.getTime());var i=e instanceof Array?[]:{};return n(e,i),i}})}])})}).call(e,n(3)(t))},function(t,e,n){"use strict";t.exports=function(t){return t.webpackPolyfill||(t.deprecate=function(){},t.paths=[],t.children||(t.children=[]),Object.defineProperty(t,"loaded",{enumerable:!0,get:function(){return t.l}}),Object.defineProperty(t,"id",{enumerable:!0,get:function(){return t.i}}),t.webpackPolyfill=1),t}},function(t,e,n){"use strict";var i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t};t.exports=function t(e,n){if(e===n)return!0;var o,r=Array.isArray(e),u=Array.isArray(n);if(r&&u){if(e.length!=n.length)return!1;for(o=0;o<e.length;o++)if(!t(e[o],n[o]))return!1;return!0}if(r!=u)return!1;if(e&&n&&"object"===(void 0===e?"undefined":i(e))&&"object"===(void 0===n?"undefined":i(n))){var s=Object.keys(e);if(s.length!==Object.keys(n).length)return!1;var a=e instanceof Date,c=n instanceof Date;if(a&&c)return e.getTime()==n.getTime();if(a!=c)return!1;var l=e instanceof RegExp,f=n instanceof RegExp;if(l&&f)return e.toString()==n.toString();if(l!=f)return!1;for(o=0;o<s.length;o++)if(!Object.prototype.hasOwnProperty.call(n,s[o]))return!1;for(o=0;o<s.length;o++)if(!t(e[s[o]],n[s[o]]))return!1;return!0}return!1}}])});