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

editorjs-undo

Package Overview
Dependencies
Maintainers
2
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

editorjs-undo - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

3

CHANGELOG.md
# Changelog
## 1.0.1 (07.12.2021)
* Updated packages with known security breaches.
## 1.0.0 (22.11.2021)

@@ -4,0 +7,0 @@ * Set the initial stack data to avoid deleting all the blocks in the last undo.

2

dist/bundle.js

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

!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Undo=e():t.Undo=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function n(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)}}t.d(e,{default:()=>s});var i=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.holder=n,this.observer=null,this.debounceTimer=200,this.mutationDebouncer=this.debounce((function(){e()}),this.debounceTimer)}var e,i;return e=t,(i=[{key:"setMutationObserver",value:function(){var t=this,e=this.holder;this.observer=new MutationObserver((function(e){t.mutationHandler(e)})),this.observer.observe(e,{childList:!0,attributes:!0,subtree:!0,characterData:!0,characterDataOldValue:!0})}},{key:"mutationHandler",value:function(t){var e=this,n=!1;t.forEach((function(t){switch(t.type){case"childList":t.target===e.holder?e.onDestroy():n=!0;break;case"characterData":n=!0;break;case"attributes":t.target.classList.contains("ce-block")||(n=!0)}})),n&&this.mutationDebouncer()}},{key:"debounce",value:function(t,e){var n,i=this;return function(){for(var o=arguments.length,s=new Array(o),r=0;r<o;r++)s[r]=arguments[r];var a=i;clearTimeout(n),n=setTimeout((function(){return t.apply(a,s)}),e)}}},{key:"onDestroy",value:function(){var t=new CustomEvent("destroy");document.dispatchEvent(t),this.observer.disconnect()}}])&&n(e.prototype,i),t}();function o(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)}}var s=function(){function t(e){var n=this,o=e.editor,s=e.config,r=void 0===s?{}:s,a=e.onUpdate,c=e.maxLength;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var h={maxLength:30,onUpdate:function(){},config:{shortcuts:{undo:"CMD+Z",redo:"CMD+Y"}}},u=o.configuration,l=u.holder,d=h.config.shortcuts,f=r.shortcuts,v=void 0===f?d:f;this.holder="string"==typeof l?document.getElementById(l):l,this.editor=o,this.shouldSaveHistory=!0,this.readOnly=u.readOnly,this.maxLength=c||h.maxLength,this.onUpdate=a||h.onUpdate,this.config={shortcuts:v},new i((function(){return n.registerChange()}),this.holder).setMutationObserver(),this.setEventListeners(),this.initialItem=null,this.clear()}var e,n,s;return e=t,s=[{key:"isReadOnlySupported",get:function(){return!0}}],(n=[{key:"truncate",value:function(t,e){for(;t.length>e;)t.shift()}},{key:"initialize",value:function(t){var e="blocks"in t?t.blocks:t,n={index:e.length-1,state:e};this.stack[0]=n,this.initialItem=n}},{key:"clear",value:function(){this.stack=this.initialItem?[this.initialItem]:[{index:0,state:[{type:"paragraph",data:{text:""}}]}],this.position=0,this.onUpdate()}},{key:"registerChange",value:function(){var t=this;this.readOnly||(this.editor&&this.editor.save&&this.shouldSaveHistory&&this.editor.save().then((function(e){t.editorDidUpdate(e.blocks)&&t.save(e.blocks)})),this.shouldSaveHistory=!0)}},{key:"editorDidUpdate",value:function(t){var e=this.stack[this.position].state;return!!t.length&&(t.length!==e.length||JSON.stringify(e)!==JSON.stringify(t))}},{key:"save",value:function(t){this.position>=this.maxLength&&this.truncate(this.stack,this.maxLength),this.position=Math.min(this.position,this.stack.length-1),this.stack=this.stack.slice(0,this.position+1);var e=this.editor.blocks.getCurrentBlockIndex();this.stack.push({index:e,state:t}),this.position+=1,this.onUpdate()}},{key:"undo",value:function(){var t=this;if(this.canUndo()){this.shouldSaveHistory=!1;var e=this.stack[this.position-=1],n=e.index,i=e.state;this.onUpdate(),this.editor.blocks.render({blocks:i}).then((function(){return t.editor.caret.setToBlock(n,"end")}))}}},{key:"redo",value:function(){var t=this;if(this.canRedo()){this.shouldSaveHistory=!1;var e=this.stack[this.position+=1],n=e.index,i=e.state;this.onUpdate(),this.editor.blocks.render({blocks:i}).then((function(){return t.editor.caret.setToBlock(n,"end")}))}}},{key:"canUndo",value:function(){return!this.readOnly&&this.position>0}},{key:"canRedo",value:function(){return!this.readOnly&&this.position<this.count()}},{key:"count",value:function(){return this.stack.length-1}},{key:"parseKeys",value:function(t){var e={CMD:/(Mac)/i.test(navigator.platform)?"metaKey":"ctrlKey",ALT:"altKey",SHIFT:"shiftKey"},n=t.slice(0,-1).map((function(t){return e[t]})),i=n.includes("shiftKey")?t[t.length-1].toUpperCase():t[t.length-1].toLowerCase();return n.push(i),n}},{key:"setEventListeners",value:function(){var t=this,e=this.holder,n=this.config.shortcuts,i=n.undo,o=n.redo,s=i.replace(/ /g,"").split("+"),r=o.replace(/ /g,"").split("+"),a=this.parseKeys(s),c=this.parseKeys(r),h=function(t,e){return!(2!==e.length||!t[e[0]]||t.key!==e[1])||!(3!==e.length||!t[e[0]]||!t[e[1]]||t.key!==e[2])},u=function(e){h(e,a)&&(e.preventDefault(),t.undo())},l=function(e){h(e,c)&&(e.preventDefault(),t.redo())};e.addEventListener("keydown",u),e.addEventListener("keydown",l),e.addEventListener("destroy",(function(){e.removeEventListener("keydown",u),e.removeEventListener("keydown",l)}))}}])&&o(e.prototype,n),s&&o(e,s),t}();return e.default})()}));
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Undo=e():t.Undo=e()}(self,(function(){return(()=>{"use strict";var t={d:(e,n)=>{for(var i in n)t.o(n,i)&&!t.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:n[i]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e)},e={};function n(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)}}t.d(e,{default:()=>s});var i=function(){function t(e,n){!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.holder=n,this.observer=null,this.debounceTimer=200,this.mutationDebouncer=this.debounce((function(){e()}),this.debounceTimer)}var e,i;return e=t,i=[{key:"setMutationObserver",value:function(){var t=this,e=this.holder;this.observer=new MutationObserver((function(e){t.mutationHandler(e)})),this.observer.observe(e,{childList:!0,attributes:!0,subtree:!0,characterData:!0,characterDataOldValue:!0})}},{key:"mutationHandler",value:function(t){var e=this,n=!1;t.forEach((function(t){switch(t.type){case"childList":t.target===e.holder?e.onDestroy():n=!0;break;case"characterData":n=!0;break;case"attributes":t.target.classList.contains("ce-block")||(n=!0)}})),n&&this.mutationDebouncer()}},{key:"debounce",value:function(t,e){var n,i=this;return function(){for(var o=arguments.length,s=new Array(o),r=0;r<o;r++)s[r]=arguments[r];var a=i;clearTimeout(n),n=setTimeout((function(){return t.apply(a,s)}),e)}}},{key:"onDestroy",value:function(){var t=new CustomEvent("destroy");document.dispatchEvent(t),this.observer.disconnect()}}],i&&n(e.prototype,i),t}();function o(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)}}var s=function(){function t(e){var n=this,o=e.editor,s=e.config,r=void 0===s?{}:s,a=e.onUpdate,c=e.maxLength;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t);var h={maxLength:30,onUpdate:function(){},config:{shortcuts:{undo:"CMD+Z",redo:"CMD+Y"}}},u=o.configuration,l=u.holder,d=h.config.shortcuts,f=r.shortcuts,v=void 0===f?d:f;this.holder="string"==typeof l?document.getElementById(l):l,this.editor=o,this.shouldSaveHistory=!0,this.readOnly=u.readOnly,this.maxLength=c||h.maxLength,this.onUpdate=a||h.onUpdate,this.config={shortcuts:v},new i((function(){return n.registerChange()}),this.holder).setMutationObserver(),this.setEventListeners(),this.initialItem=null,this.clear()}var e,n,s;return e=t,s=[{key:"isReadOnlySupported",get:function(){return!0}}],(n=[{key:"truncate",value:function(t,e){for(;t.length>e;)t.shift()}},{key:"initialize",value:function(t){var e="blocks"in t?t.blocks:t,n={index:e.length-1,state:e};this.stack[0]=n,this.initialItem=n}},{key:"clear",value:function(){this.stack=this.initialItem?[this.initialItem]:[{index:0,state:[{type:"paragraph",data:{text:""}}]}],this.position=0,this.onUpdate()}},{key:"registerChange",value:function(){var t=this;this.readOnly||(this.editor&&this.editor.save&&this.shouldSaveHistory&&this.editor.save().then((function(e){t.editorDidUpdate(e.blocks)&&t.save(e.blocks)})),this.shouldSaveHistory=!0)}},{key:"editorDidUpdate",value:function(t){var e=this.stack[this.position].state;return!!t.length&&(t.length!==e.length||JSON.stringify(e)!==JSON.stringify(t))}},{key:"save",value:function(t){this.position>=this.maxLength&&this.truncate(this.stack,this.maxLength),this.position=Math.min(this.position,this.stack.length-1),this.stack=this.stack.slice(0,this.position+1);var e=this.editor.blocks.getCurrentBlockIndex();this.stack.push({index:e,state:t}),this.position+=1,this.onUpdate()}},{key:"undo",value:function(){var t=this;if(this.canUndo()){this.shouldSaveHistory=!1;var e=this.stack[this.position-=1],n=e.index,i=e.state;this.onUpdate(),this.editor.blocks.render({blocks:i}).then((function(){return t.editor.caret.setToBlock(n,"end")}))}}},{key:"redo",value:function(){var t=this;if(this.canRedo()){this.shouldSaveHistory=!1;var e=this.stack[this.position+=1],n=e.index,i=e.state;this.onUpdate(),this.editor.blocks.render({blocks:i}).then((function(){return t.editor.caret.setToBlock(n,"end")}))}}},{key:"canUndo",value:function(){return!this.readOnly&&this.position>0}},{key:"canRedo",value:function(){return!this.readOnly&&this.position<this.count()}},{key:"count",value:function(){return this.stack.length-1}},{key:"parseKeys",value:function(t){var e={CMD:/(Mac)/i.test(navigator.platform)?"metaKey":"ctrlKey",ALT:"altKey",SHIFT:"shiftKey"},n=t.slice(0,-1).map((function(t){return e[t]})),i=n.includes("shiftKey")?t[t.length-1].toUpperCase():t[t.length-1].toLowerCase();return n.push(i),n}},{key:"setEventListeners",value:function(){var t=this,e=this.holder,n=this.config.shortcuts,i=n.undo,o=n.redo,s=i.replace(/ /g,"").split("+"),r=o.replace(/ /g,"").split("+"),a=this.parseKeys(s),c=this.parseKeys(r),h=function(t,e){return!(2!==e.length||!t[e[0]]||t.key!==e[1])||!(3!==e.length||!t[e[0]]||!t[e[1]]||t.key!==e[2])},u=function(e){h(e,a)&&(e.preventDefault(),t.undo())},l=function(e){h(e,c)&&(e.preventDefault(),t.redo())};e.addEventListener("keydown",u),e.addEventListener("keydown",l),e.addEventListener("destroy",(function(){e.removeEventListener("keydown",u),e.removeEventListener("keydown",l)}))}}])&&o(e.prototype,n),s&&o(e,s),t}();return e.default})()}));
{
"name": "editorjs-undo",
"version": "1.0.0",
"version": "1.0.1",
"keywords": [

@@ -35,3 +35,3 @@ "undo",

"babel-loader": "^8.1.0",
"eslint": "^7.1.0",
"eslint": "^8.3.0",
"eslint-config-airbnb-base": "^14.1.0",

@@ -38,0 +38,0 @@ "eslint-plugin-import": "^2.20.2",

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