From 1fe6b02b2b20007be3fea24d7ddc469624958b90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20Rold=C3=A1n?= <62166813+Odraxs@users.noreply.github.com> Date: Mon, 2 Oct 2023 11:12:54 -0500 Subject: [PATCH 1/4] Update allowed -endpoints and harden runner (#225) Co-authored-by: Juan Manuel Giraldo --- .github/workflows/ci.yml | 4 ++-- .github/workflows/codeql.yml | 8 ++++---- .github/workflows/publish.yml | 2 +- .github/workflows/scorecards.yml | 5 +++-- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47cf80e..22d19a9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -6,7 +6,7 @@ on: - 'v*.[0-9]' pull_request: -permissions: # added using https://github.com/step-security/secure-workflows +permissions: # added using https://github.com/step-security/secure-workflows contents: read jobs: @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0 + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 with: disable-sudo: true egress-policy: block diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 5ee4105..accc179 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -41,14 +41,14 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0 + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 with: disable-sudo: true egress-policy: block allowed-endpoints: > - api.github.com:443 - github.com:443 - objects.githubusercontent.com:443 + *.github.com:443 + *.githubapp.com:443 + *.githubusercontent.com:443 - name: Checkout repository uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index 719e492..5bdc14b 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -10,7 +10,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Harden Runner - uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0 + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 with: disable-sudo: true egress-policy: block diff --git a/.github/workflows/scorecards.yml b/.github/workflows/scorecards.yml index d569a0f..16f41e9 100644 --- a/.github/workflows/scorecards.yml +++ b/.github/workflows/scorecards.yml @@ -22,7 +22,7 @@ jobs: steps: - name: Harden Runner - uses: step-security/harden-runner@03bee3930647ebbf994244c21ddbc0d4933aab4f # v2.3.0 + uses: step-security/harden-runner@8ca2b8b2ece13480cda6dacd3511b49857a23c09 # v2.5.1 with: disable-sudo: true egress-policy: block @@ -34,7 +34,8 @@ jobs: fulcio.sigstore.dev:443 github.com:443 rekor.sigstore.dev:443 - sigstore-tuf-root.storage.googleapis.com:443 + bestpractices.dev:443 + *.storage.googleapis.com:443 - name: "Checkout code" uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2 From 509bfbe7497a17d7a1519fce483e6d5ae39ae2f4 Mon Sep 17 00:00:00 2001 From: Juan Manuel Giraldo <84339390+juanmagiraldor@users.noreply.github.com> Date: Tue, 17 Oct 2023 12:06:10 -0500 Subject: [PATCH 2/4] Solve undo with custom blocks (#230) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Solve undo with custom blocks Co-authored-by: David Roldán * Solve github endpoint Co-authored-by: David Roldán * Implement defaultBlock in initialData Co-authored-by: Edwin Steven Guayacan --------- Co-authored-by: David Roldán Co-authored-by: Mario Rodriguez <64106728+MarioRodriguezS@users.noreply.github.com> Co-authored-by: Edwin Steven Guayacan --- .github/workflows/codeql.yml | 1 + dist/bundle.js | 2 +- src/index.js | 9 +++++---- test/fixtures/editor.js | 4 +++- test/undo.test.js | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index accc179..5b0db6b 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -47,6 +47,7 @@ jobs: egress-policy: block allowed-endpoints: > *.github.com:443 + github.com:443 *.githubapp.com:443 *.githubusercontent.com:443 diff --git a/dist/bundle.js b/dist/bundle.js index 10c81ce..42eb213 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Undo=t():e.Undo=t()}(self,(()=>(()=>{var e={571:function(e,t){var n,i;n=function(e){"use strict";var t=function(){function e(e,t){for(var n=0;n=0){var t=window.getSelection(),n=this.createRange(this.target,{count:e});n&&(n.collapse(!1),t.removeAllRanges(),t.addRange(n))}}else this.target.setSelectionRange(e,e)}},{key:"createRange",value:function(e,t,n){if(n||((n=document.createRange()).selectNode(e),n.setStart(e,0)),0===t.count)n.setEnd(e,t.count);else if(e&&t.count>0)if(e.nodeType===Node.TEXT_NODE)e.textContent.length{e.exports=n(571)}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";n.d(i,{default:()=>u});var e=n(334),t=n.n(e);function o(e,t){for(var n=0;nt;)e.shift()}},{key:"initialize",value:function(e){var t="blocks"in e?e.blocks:e,n={index:t.length-1,state:t};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:"setReadOnly",value:function(){var e=this.holder.querySelector(".ce-toolbox");this.readOnly=!e}},{key:"registerChange",value:function(){var e=this;this.setReadOnly(),this.readOnly||(this.editor&&this.editor.save&&this.shouldSaveHistory&&this.editor.save().then((function(t){e.editorDidUpdate(t.blocks)&&e.save(t.blocks)})),this.shouldSaveHistory=!0)}},{key:"editorDidUpdate",value:function(e){var t=this.stack[this.position].state;return!!e.length&&(e.length!==t.length||JSON.stringify(t)!==JSON.stringify(e))}},{key:"save",value:function(e){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 t=this.blocks.getCurrentBlockIndex(),n=this.blocks.getBlocksCount(),i=t;e[t]||(i-=n-e.length);var o=!e[i]||"paragraph"!==e[i].type&&"header"!==e[i].type?null:this.getCaretIndex(t);this.stack.push({index:i,state:e,caretIndex:o}),this.position+=1,this.onUpdate()}},{key:"getCaretIndex",value:function(e){var n=this.holder.getElementsByClassName("ce-block__content");return new(t())(n[e].firstChild).getPos()}},{key:"insertDeletedBlock",value:function(e,t,n){for(var i=0;it.length}},{key:"undo",value:function(){var e=this;if(this.canUndo()){var t=this.stack[this.position],n=t.index,i=t.state;this.position-=1,this.shouldSaveHistory=!1;var o=this.stack[this.position].index,r=this.stack[this.position],s=r.state,a=r.caretIndex;this.onUpdate();var c=this.blocks.getBlocksCount();if(s[o]||(o-=1,this.stack[this.position].index=o),this.blockWasDeleted(s,i))this.insertDeletedBlock(s,i,o);else if(this.blockWasSkipped(o,n,s,i))this.blocks.delete(),this.caret.setToBlock(o,"end");else if(c>s.length)this.blocks.render({blocks:s}).then((function(){e.editor.blocks.insert("paragraph",{text:""}),e.caret.setToLastBlock("end")}));else if(this.blockWasDropped(s,i))this.blocks.render({blocks:s}).then((function(){return e.caret.setToBlock(o,"end")}));else if(this.contentChangedInNoFocusBlock(o,n)){var l=this.blocks.getBlockByIndex(n).id;this.blocks.update(l,s[n].data),this.setCaretIndex(o,a)}var u=this.blocks.getBlockByIndex(o);u&&(this.blocks.update(u.id,s[o].data),this.setCaretIndex(o,a))}}},{key:"setCaretIndex",value:function(e,n){if(n&&-1!==n){var i=this.holder.getElementsByClassName("ce-block__content");new(t())(i[e].firstChild).setPos(n)}else this.caret.setToBlock(e,"end")}},{key:"insertBlock",value:function(e,t){this.blocks.insert(e[t].type,e[t].data,{},t,!0)}},{key:"insertSkippedBlocks",value:function(e,t){for(var n=e;n0}},{key:"canRedo",value:function(){return!this.readOnly&&this.position(()=>{var e={571:function(e,t){var n,i;n=function(e){"use strict";var t=function(){function e(e,t){for(var n=0;n=0){var t=window.getSelection(),n=this.createRange(this.target,{count:e});n&&(n.collapse(!1),t.removeAllRanges(),t.addRange(n))}}else this.target.setSelectionRange(e,e)}},{key:"createRange",value:function(e,t,n){if(n||((n=document.createRange()).selectNode(e),n.setStart(e,0)),0===t.count)n.setEnd(e,t.count);else if(e&&t.count>0)if(e.nodeType===Node.TEXT_NODE)e.textContent.length{e.exports=n(571)}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";n.d(i,{default:()=>u});var e=n(334),t=n.n(e);function o(e,t){for(var n=0;nt;)e.shift()}},{key:"initialize",value:function(e){var t="blocks"in e?e.blocks:e,n={index:t.length-1,state:t};this.stack[0]=n,this.initialItem=n}},{key:"clear",value:function(){this.stack=this.initialItem?[this.initialItem]:[{index:0,state:[{type:this.defaultBlock,data:{}}]}],this.position=0,this.onUpdate()}},{key:"setReadOnly",value:function(){var e=this.holder.querySelector(".ce-toolbox");this.readOnly=!e}},{key:"registerChange",value:function(){var e=this;this.setReadOnly(),this.readOnly||(this.editor&&this.editor.save&&this.shouldSaveHistory&&this.editor.save().then((function(t){e.editorDidUpdate(t.blocks)&&e.save(t.blocks)})),this.shouldSaveHistory=!0)}},{key:"editorDidUpdate",value:function(e){var t=this.stack[this.position].state;return!!e.length&&(e.length!==t.length||JSON.stringify(t)!==JSON.stringify(e))}},{key:"save",value:function(e){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 t=this.blocks.getCurrentBlockIndex(),n=this.blocks.getBlocksCount(),i=t;e[t]||(i-=n-e.length);var o=!e[i]||"paragraph"!==e[i].type&&"header"!==e[i].type?null:this.getCaretIndex(t);this.stack.push({index:i,state:e,caretIndex:o}),this.position+=1,this.onUpdate()}},{key:"getCaretIndex",value:function(e){var n=this.holder.getElementsByClassName("ce-block__content");return new(t())(n[e].firstChild).getPos()}},{key:"insertDeletedBlock",value:function(e,t,n){for(var i=0;it.length}},{key:"undo",value:function(){var e=this;if(this.canUndo()){var t=this.stack[this.position],n=t.index,i=t.state;this.position-=1,this.shouldSaveHistory=!1;var o=this.stack[this.position].index,r=this.stack[this.position],s=r.state,a=r.caretIndex;this.onUpdate();var c=this.blocks.getBlocksCount();if(s[o]||(o-=1,this.stack[this.position].index=o),this.blockWasDeleted(s,i))this.insertDeletedBlock(s,i,o);else if(this.blockWasSkipped(o,n,s,i))this.blocks.delete(),this.caret.setToBlock(o,"end");else if(c>s.length)this.blocks.render({blocks:s}).then((function(){e.editor.blocks.insert(e.defaultBlock,{}),e.caret.setToLastBlock("end")}));else if(this.blockWasDropped(s,i))this.blocks.render({blocks:s}).then((function(){return e.caret.setToBlock(o,"end")}));else if(this.contentChangedInNoFocusBlock(o,n)){var l=this.blocks.getBlockByIndex(n).id;this.blocks.update(l,s[n].data),this.setCaretIndex(o,a)}var u=this.blocks.getBlockByIndex(o);u&&(this.blocks.update(u.id,s[o].data),this.setCaretIndex(o,a))}}},{key:"setCaretIndex",value:function(e,n){if(n&&-1!==n){var i=this.holder.getElementsByClassName("ce-block__content");new(t())(i[e].firstChild).setPos(n)}else this.caret.setToBlock(e,"end")}},{key:"insertBlock",value:function(e,t){this.blocks.insert(e[t].type,e[t].data,{},t,!0)}},{key:"insertSkippedBlocks",value:function(e,t){for(var n=e;n0}},{key:"canRedo",value:function(){return!this.readOnly&&this.position { - this.editor.blocks.insert("paragraph", {text: ""}) - this.caret.setToLastBlock("end") ; + this.editor.blocks.insert(this.defaultBlock, {}); + this.caret.setToLastBlock("end"); }); } else if (this.blockWasDropped(state, nextState)) { this.blocks diff --git a/test/fixtures/editor.js b/test/fixtures/editor.js index 647b3b0..ab809f7 100644 --- a/test/fixtures/editor.js +++ b/test/fixtures/editor.js @@ -17,7 +17,9 @@ const editor = { caret: { setToBlock() {}, }, - configuration: {}, + configuration: { + defaultBlock: 'paragraph', + }, }; const readOnlyEditor = { diff --git a/test/undo.test.js b/test/undo.test.js index 6881770..e760ea4 100644 --- a/test/undo.test.js +++ b/test/undo.test.js @@ -64,7 +64,7 @@ describe('Undo', () => { undo = new Undo({ editor }); }); - const intialStackData = { index: 0, state: [{ type: 'paragraph', data: { text: '' } }] }; + const intialStackData = { index: 0, state: [{ type: 'paragraph', data: {} }] }; it('is unable to perform an undo operation in an empty stack', () => { expect(undo.canUndo()).toBe(false); From fff305467764d24612eacbaa1f41db0eb6eeebc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alejandro=20Rodr=C3=ADguez?= <64106728+MarioRodriguezS@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:34:07 -0500 Subject: [PATCH 3/4] fix deleted blocks and caret (#231) Co-authored-by: Edwin Steven Guayacan --- dist/bundle.js | 2 +- src/index.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 42eb213..8f9f5ff 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -1 +1 @@ -!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Undo=t():e.Undo=t()}(self,(()=>(()=>{var e={571:function(e,t){var n,i;n=function(e){"use strict";var t=function(){function e(e,t){for(var n=0;n=0){var t=window.getSelection(),n=this.createRange(this.target,{count:e});n&&(n.collapse(!1),t.removeAllRanges(),t.addRange(n))}}else this.target.setSelectionRange(e,e)}},{key:"createRange",value:function(e,t,n){if(n||((n=document.createRange()).selectNode(e),n.setStart(e,0)),0===t.count)n.setEnd(e,t.count);else if(e&&t.count>0)if(e.nodeType===Node.TEXT_NODE)e.textContent.length{e.exports=n(571)}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";n.d(i,{default:()=>u});var e=n(334),t=n.n(e);function o(e,t){for(var n=0;nt;)e.shift()}},{key:"initialize",value:function(e){var t="blocks"in e?e.blocks:e,n={index:t.length-1,state:t};this.stack[0]=n,this.initialItem=n}},{key:"clear",value:function(){this.stack=this.initialItem?[this.initialItem]:[{index:0,state:[{type:this.defaultBlock,data:{}}]}],this.position=0,this.onUpdate()}},{key:"setReadOnly",value:function(){var e=this.holder.querySelector(".ce-toolbox");this.readOnly=!e}},{key:"registerChange",value:function(){var e=this;this.setReadOnly(),this.readOnly||(this.editor&&this.editor.save&&this.shouldSaveHistory&&this.editor.save().then((function(t){e.editorDidUpdate(t.blocks)&&e.save(t.blocks)})),this.shouldSaveHistory=!0)}},{key:"editorDidUpdate",value:function(e){var t=this.stack[this.position].state;return!!e.length&&(e.length!==t.length||JSON.stringify(t)!==JSON.stringify(e))}},{key:"save",value:function(e){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 t=this.blocks.getCurrentBlockIndex(),n=this.blocks.getBlocksCount(),i=t;e[t]||(i-=n-e.length);var o=!e[i]||"paragraph"!==e[i].type&&"header"!==e[i].type?null:this.getCaretIndex(t);this.stack.push({index:i,state:e,caretIndex:o}),this.position+=1,this.onUpdate()}},{key:"getCaretIndex",value:function(e){var n=this.holder.getElementsByClassName("ce-block__content");return new(t())(n[e].firstChild).getPos()}},{key:"insertDeletedBlock",value:function(e,t,n){for(var i=0;it.length}},{key:"undo",value:function(){var e=this;if(this.canUndo()){var t=this.stack[this.position],n=t.index,i=t.state;this.position-=1,this.shouldSaveHistory=!1;var o=this.stack[this.position].index,r=this.stack[this.position],s=r.state,a=r.caretIndex;this.onUpdate();var c=this.blocks.getBlocksCount();if(s[o]||(o-=1,this.stack[this.position].index=o),this.blockWasDeleted(s,i))this.insertDeletedBlock(s,i,o);else if(this.blockWasSkipped(o,n,s,i))this.blocks.delete(),this.caret.setToBlock(o,"end");else if(c>s.length)this.blocks.render({blocks:s}).then((function(){e.editor.blocks.insert(e.defaultBlock,{}),e.caret.setToLastBlock("end")}));else if(this.blockWasDropped(s,i))this.blocks.render({blocks:s}).then((function(){return e.caret.setToBlock(o,"end")}));else if(this.contentChangedInNoFocusBlock(o,n)){var l=this.blocks.getBlockByIndex(n).id;this.blocks.update(l,s[n].data),this.setCaretIndex(o,a)}var u=this.blocks.getBlockByIndex(o);u&&(this.blocks.update(u.id,s[o].data),this.setCaretIndex(o,a))}}},{key:"setCaretIndex",value:function(e,n){if(n&&-1!==n){var i=this.holder.getElementsByClassName("ce-block__content");new(t())(i[e].firstChild).setPos(n)}else this.caret.setToBlock(e,"end")}},{key:"insertBlock",value:function(e,t){this.blocks.insert(e[t].type,e[t].data,{},t,!0)}},{key:"insertSkippedBlocks",value:function(e,t){for(var n=e;n0}},{key:"canRedo",value:function(){return!this.readOnly&&this.position(()=>{var e={571:function(e,t){var n,i;n=function(e){"use strict";var t=function(){function e(e,t){for(var n=0;n=0){var t=window.getSelection(),n=this.createRange(this.target,{count:e});n&&(n.collapse(!1),t.removeAllRanges(),t.addRange(n))}}else this.target.setSelectionRange(e,e)}},{key:"createRange",value:function(e,t,n){if(n||((n=document.createRange()).selectNode(e),n.setStart(e,0)),0===t.count)n.setEnd(e,t.count);else if(e&&t.count>0)if(e.nodeType===Node.TEXT_NODE)e.textContent.length{e.exports=n(571)}},t={};function n(i){var o=t[i];if(void 0!==o)return o.exports;var r=t[i]={exports:{}};return e[i].call(r.exports,r,r.exports,n),r.exports}n.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return n.d(t,{a:t}),t},n.d=(e,t)=>{for(var i in t)n.o(t,i)&&!n.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},n.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i={};return(()=>{"use strict";n.d(i,{default:()=>u});var e=n(334),t=n.n(e);function o(e,t){for(var n=0;nt;)e.shift()}},{key:"initialize",value:function(e){var t="blocks"in e?e.blocks:e,n={index:t.length-1,state:t};this.stack[0]=n,this.initialItem=n}},{key:"clear",value:function(){this.stack=this.initialItem?[this.initialItem]:[{index:0,state:[{type:this.defaultBlock,data:{}}]}],this.position=0,this.onUpdate()}},{key:"setReadOnly",value:function(){var e=this.holder.querySelector(".ce-toolbox");this.readOnly=!e}},{key:"registerChange",value:function(){var e=this;this.setReadOnly(),this.readOnly||(this.editor&&this.editor.save&&this.shouldSaveHistory&&this.editor.save().then((function(t){e.editorDidUpdate(t.blocks)&&e.save(t.blocks)})),this.shouldSaveHistory=!0)}},{key:"editorDidUpdate",value:function(e){var t=this.stack[this.position].state;return!!e.length&&(e.length!==t.length||JSON.stringify(t)!==JSON.stringify(e))}},{key:"save",value:function(e){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 t=this.blocks.getCurrentBlockIndex(),n=this.blocks.getBlocksCount(),i=t;e[t]||(i-=n-e.length);var o=!e[i]||"paragraph"!==e[i].type&&"header"!==e[i].type?null:this.getCaretIndex(t);this.stack.push({index:i,state:e,caretIndex:o}),this.position+=1,this.onUpdate()}},{key:"getCaretIndex",value:function(e){var n=this.holder.getElementsByClassName("ce-block__content");return new(t())(n[e].firstChild).getPos()}},{key:"insertDeletedBlock",value:function(e,t,n){for(var i=0;it.length}},{key:"undo",value:function(){var e=this;if(this.canUndo()){var t=this.stack[this.position],n=t.index,i=t.state;this.position-=1,this.shouldSaveHistory=!1;var o=this.stack[this.position].index,r=this.stack[this.position],s=r.state,a=r.caretIndex;this.onUpdate();var c=this.blocks.getBlocksCount();if(s[o]||(o-=1,this.stack[this.position].index=o),this.blockWasDeleted(s,i))this.insertDeletedBlock(s,i,o);else if(this.blockWasSkipped(o,n,s,i))this.blocks.delete(n),this.caret.setToBlock(o,"end");else if(c>s.length)this.blocks.render({blocks:s}).then((function(){e.editor.blocks.insert(e.defaultBlock,{}),e.setCaretIndex(o,a)}));else if(this.blockWasDropped(s,i))this.blocks.render({blocks:s}).then((function(){return e.caret.setToBlock(o,"end")}));else if(this.contentChangedInNoFocusBlock(o,n)){var l=this.blocks.getBlockByIndex(n).id;this.blocks.update(l,s[n].data),this.setCaretIndex(o,a)}var u=this.blocks.getBlockByIndex(o);u&&(this.blocks.update(u.id,s[o].data),this.setCaretIndex(o,a))}}},{key:"setCaretIndex",value:function(e,n){if(n&&-1!==n){var i=this.holder.getElementsByClassName("ce-block__content");new(t())(i[e].firstChild).setPos(n)}else this.caret.setToBlock(e,"end")}},{key:"insertBlock",value:function(e,t){this.blocks.insert(e[t].type,e[t].data,{},t,!0)}},{key:"insertSkippedBlocks",value:function(e,t){for(var n=e;n0}},{key:"canRedo",value:function(){return!this.readOnly&&this.position state.length) { this.blocks .render({ blocks: state }) .then(() => { this.editor.blocks.insert(this.defaultBlock, {}); - this.caret.setToLastBlock("end"); + this.setCaretIndex(index, caretIndex); }); } else if (this.blockWasDropped(state, nextState)) { this.blocks From ae70e2d05817c1015338835f2e8e7e80944be41f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20Alejandro=20Rodr=C3=ADguez?= <64106728+MarioRodriguezS@users.noreply.github.com> Date: Tue, 17 Oct 2023 14:58:11 -0500 Subject: [PATCH 4/4] Prepare release v2.0.24 (#233) --- CHANGELOG.md | 6 ++++++ package.json | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d6c9bca..bf4d172 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 2.0.24 (17.10.2023) + +- Fix bug [#227](https://github.com/kommitters/editorjs-undo/issues/227) - Fix unexpected behavior when there are line breaks. +- Fix bug [#202](https://github.com/kommitters/editorjs-undo/issues/202) - Solve undo with custom blocks. +- Update [#225](https://github.com/kommitters/editorjs-undo/pull/225) - Update codeql.yml and scorecards.yml allowed-endpoints. + ## 2.0.23 (15.09.2023) - Fix bug [#213](https://github.com/kommitters/editorjs-undo/issues/213) - Add support to different keyboard distributions. diff --git a/package.json b/package.json index 5b0df1d..82ff7df 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "editorjs-undo", - "version": "2.0.23", + "version": "2.0.24", "keywords": [ "undo", "redo",