Giter Site home page Giter Site logo

kommitters / editorjs-undo Goto Github PK

View Code? Open in Web Editor NEW
163.0 11.0 50.0 6.95 MB

Undo/Redo feature for Editor.js

Home Page: https://www.npmjs.com/package/editorjs-undo

License: MIT License

JavaScript 100.00%
editorjs editorjs-plugin javascript hacktoberfest

editorjs-undo's People

Contributors

applegrew avatar boterop avatar cristhianrodriguezmolina avatar dependabot[bot] avatar egg- avatar evangillogley avatar felipeguzmansierra avatar howarto avatar imadha avatar jhonatan-kmt avatar jmzp avatar juanhurtado10 avatar juanmagiraldor avatar juliandsg0222 avatar karolrojas07 avatar khanakia avatar mariorodriguezs avatar marthox avatar mauriciosabogal avatar miguelnietoa avatar neokms avatar nicolasgaviria avatar odraxs avatar psalchow avatar renovate[bot] avatar sangeeky avatar step-security-bot avatar trevrdspcdev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

editorjs-undo's Issues

editorjs-undo not working with default editorjs configuration since 0.1.7

Hi ๐Ÿ‘‹

I update this morning to 0.1.7 and editorjs-undo stopped working. This is because my editorjs was configured with the default value for the holder param, which is 'editorjs' (https://editorjs.io/getting-started#configuration). It results in the following errors when instantiating Undo

bundle.js:280 Uncaught (in promise) TypeError: e.addEventListener is not a function
    at t.value (bundle.js:280)
    at new t (bundle.js:160)
    at onReady (fs_builder_controller.js:116)
    at editor.js:13098
 bundle.js:205 Uncaught (in promise) TypeError: Cannot read property 'undefined' of undefined
    at t.value (bundle.js:205)
    at bundle.js:199

Changing the configuration value of holder to document.querySelector('#editorjs') fixes the issue. I think editorjs-undo should support both a String or a HTMLElement value for the holder param, as this is what is supported by editorjs (see https://github.com/codex-team/editor.js/blob/master/types/configs/editor-config.d.ts#L16).

Let me know what you think. If you agree with my suggestion, I can go ahead and write a PR for this.

Cheers!

Ctrl+Z will make editor scroll to top [Firefox]

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

If an article is very long, and scrollbar is in the middle of the article, press Ctrl+Z will make editor scroll to top.

this experience is not good

Environment

  • Editor.js version: 2.22.2
  • Plugins you use with their versions: No plugin enabled
  • Device, Browser, OS: Firefox Windown10, PC

Current behavior

Press Ctrl+Z will scroll to top

Expected behavior

Press Ctrl+Z would not scroll to any where

Additional context

Firefox will cause this problem, Chrome is ok

Moving blocks (or Drag and Drop) + Undo seems squishy

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

It seems that moving blocks (via Drag-and-Drop OR via BlockTune) doesn't behave consistently.

Environment

  • Editor.js version: 2.24.2
  • Plugins you use with their versions:
    • "@editorjs/header": "^2.6.2"
    • "@editorjs/paragraph": "^2.8.0"
  • Device, Browser, OS:
    • Mac
    • Safari Version 15.4 (17613.1.17.1.6)
    • OSX Moneterey 12.3

Current behavior

  1. Move via Drag and Drop to last position.
  2. Press Undo-Combination
  3. First Paragraph is missing. Last two Paragraphs are duplicate

Expected behavior

  1. Move via Drag and Drop to last position
  2. Press Undo-Combination
  3. First and Last Paragraph should be switched correctly

Additional context

Attached 2 Videos with two different behaviors

Bug with Drag and Drop

Screen.Recording.2022-05-11.at.21.51.08.mov

Bug with BlockTune

Screen.Recording.2022-05-11.at.21.53.05.mov

Add shortcut for Cmd + Shift + Z to redo

Is your feature request related to a problem? Please describe.

Ctrl/Cmd + Z is the universally accepted keyboard shortcut to undo something.

However the shortcut for redo varies between different operating systems:

  • Ctrl + Y (Windows)

    On Windows, it's common for redo be mapped to Ctrl + Y.

    But on Mac, Cmd + Y has no effect in most applications. And sometimes it does something else entirely โ€“ for example, in Chrome it opens History.

  • Ctrl/Cmd + Shift + Z (Mac, Linux)

    This is the redo keyboard shortcut on Mac and Linux.

    As a Mac user, I can confirm that Cmd + Shift + Z performs the redo action consistently in all applications throughout the operating system. I believe this is also true for Linux.

    The picture seems less clear on Windows. Some applications seem to support Ctrl + Y whereas other support Ctrl + Shift + Z (or both).

    This is corroborated by: https://keyboardshortcuts.org/redo

Describe the solution you'd like

It'd be great if the redo feature supported both Ctrl + Y and Ctrl/Cmd + Shift + Z keyboard shortcuts. That way it'd be more discoverable and feel native to users of non-Windows operating systems.

Personally, I have a strong muscle memory for Cmd + Shift + Z which is why I've noticed this. It breaks my internal expectations of how an editor behaves on Mac. I expect the same is true for people using iOS devices with an attached keyboard.

Additional context

I haven't actually tried mapping redo to both shortcuts, so am unsure whether this is a trivial change or if it's limited to one single shortcut only.

But I thought I'd report this here as it doesn't seem to have been raised yet โ€“ although I do see that it was touched upon in #106.

Add read-only mode support

Context

The recent EditorJS version has included a readOnly property. Ref.

Objective

To add support to this new property

undo redo not working for underline and change case and redo not working for hyperlink

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

A clear and concise description of what the bug is.

Environment

  • Editor.js version:
  • Plugins you use with their versions:
  • Device, Browser, OS:

Current behavior

Include code samples, errors and stack traces if appropriate.
If reporting a bug, please include the reproducing steps.

Expected behavior

A clear and concise description of what you expected to happen.

Additional context

Add any other context about the problem here.

Doesn't work for Specified holder elements

Uncaught (in promise) DOMException: Failed to execute 'querySelector' on 'Document': '#[object HTMLDivElement]' is not a valid selector.

EditorJS supports queryselectors and actual element refs. This plugin breaks when using elements directly as a holder.
For example, when you specify { holder: ref.current }, the observer code #${this.holder} breaks.
Breaks on this line of code
https://github.com/kommitters/editorjs-undo/blob/master/src/observer.js#L36

Not working with editorjs-table, empty rows are deleted

Description

Undo deletes empty rows on a Table

Environment

Current behavior

Adding table, enter some content
Bildschirmfoto 2022-01-20 um 08 48 00

Then Ctrl + Z
Bildschirmfoto 2022-01-20 um 08 48 59

Expected behavior

Only remove the text that was entered

Additional context

My Application is currently available here:

Number of characters deleted with CMD+Z depends on initial typing speed

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

For typed text, the number of characters deleted each time the CMD+Z key combination is pressed depends upon the speed/cadence with which the original text was typed. This is due to the currently unchangeable 200ms debounce used in the observer.

Environment

  • Editor.js version: 2.23.2
  • Plugins you use with their versions: editorjs-undo
  • Device, Browser, OS: MacOS, Chrome

Current behaviour

The number of characters deleted each time CMD+Z is pressed depends upon the rate of speed with which the original text was typed. To reproduce this behaviour:

  1. Type some text into the editor, varying your typing speed.
  2. Press CMD+Z a few times.
  3. Observe that sometimes a single character is deleted, and other times multiple characters are deleted.
multiple-characters-deleted.mov

Expected behaviour

It should be possible to have pressing CMD+Z delete one character at a time, regardless of how quickly the original text was entered.

single-characters-deleted.mov

Additional context

N/A

Undo issue related to editorjs

As Undo plugin need an inital state
`
function initUndo() {

    undo = new Undo({editor});
      
    editor.save().then((outputData) => {
        //console.log('Article data: ', outputData) //strong tags are washed where are they are allowed in config
        var initialData=outputData
        undo.initialize(initialData.blocks);
    }).catch((error) => {
        console.log('Saving failed: ', error)
    });
}

`

and in my paragaph plugin config, I have

paragraph: {
text: {
type: "string",
allowedTags: "i,b,u,a[href],strong,em,br,br,dt,dl,embed,ol,li,ul"
}
}
but edtor sanitize at least strong tag (and I guess others too) on editor.save()
/**
* Saving example
*/

    saveButton.addEventListener('click',(e) => {
            editor.save().then((savedData) => {
                alert(savedData.toSource()) //<strong> dissaper
            });
    }); 

`

so when I undo, I got only text with br tag preserved in paragraph

2.0.0-rc3 - TypeError: Cannot read properties of undefined (reading 'type')

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

If you add an empty paragraph, followed by an empty paragraph and enter one character: You're receiving the following message:

bundle.js?:formatted:347 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'type')
    at t.value (bundle.js?:formatted:347:54)
    at eval (bundle.js?:formatted:329:62)

Environment

  • Editor.js version: 2.23.2
  • Plugins you use with their versions: 2.0.0-rc3
  • Device, Browser, OS: Monterey 12.3, Safari Version 15.4 (17613.1.17.1.6)

Current behavior

  1. Load the editor with an initial header
  2. Click Enter (creates a new block)
  3. Click again Enter (creates another new block)
  4. Enter any character (i.e. "a") inside the second block and you should see the error message

Expected behavior

The error message should not appear.

Additional context

Using react-editor-js as described in the README.md with onInitialize.

  const handleInitialize = React.useCallback((instance) => {
    editorCore.current = instance
  }, [])

  const handleReady = () => {
    const editorJsInstance = editorCore.current._editorJS;
    const undo = new Undo({
      editor: editorJsInstance,
      config: {
        debounceTimer: 100
      }
    });
    undo.initialize(editor.blocks);
    new DragDrop(editorJsInstance);
  };

Undo is ignored, when Copy-paste 2-3 paragraph from Wikipedia

Hi, thanks for this package. I'm getting a bug. Can you help me.
When a user pastes text into the editor and uses the 'undo' function, then it should undo the paste.
Instead, the undo is ignored.

Steps to reproduce:

  1. Go to Wikipedia
  2. Select and copy 2-3 paragraph
  3. Paste in the editor.
  4. Then the editor ignores the undo & redo.

Expected behavior:
The editor should undo the paste.

Library listening to all click events on the DOM

Description

After instantiating the Undo class in onReady(), every click on the DOM (anywhere other than the EditorJS editor itself) triggers a save event on the editor, this doesn't happen when I remove the editorjs-undo library.

editorjs

Environment

  • Editor.js version: 2.23.2

  • Plugins you use with their versions:

Embed, Table, List, Warning, Code, LinkTool, Raw, Header, Quote, Marker, CheckList, Delimiter, InlineCode, SimpleImage

  • Device, Browser, OS: HP Elitebook 8470p, Chrome, Ubuntu

Is there a way to scope the click events to the editor container only, so clicks outside the editor container doesn't trigger the save event?

I'm worried that this behaviour might affect performance.

Shortcuts are not supported on other keyboard layouts

Precheck

  • [+] Do a quick search and make sure the bug has not been reported yet.
  • [+] Please disclose security vulnerabilities privately at [email protected].
  • [+] Finally, be nice and have fun!.

Description

The plugin does not work correctly when the text was written in Russian. In particular, return does not work after converting text into a header and other types of blocks.

Environment

  • Editor.js version: 2.25.0
  • Plugins you use with their versions: 1.0.1 and 2.0.12
  • Device, Browser, OS: chrome, win10

Current behavior

We write 1 paragraph of text
Convert 1 paragraph to heading
Change the keyboard layout to Russian (or another)
Press cmd + z
Nothing happens

Expected behavior

We write 1 paragraph of text
Convert 1 paragraph to heading
Change the keyboard layout to Russian (or another)
Press cmd + z
Paragraph 1 became text again

Undo tries to save when readOnly is toggled to true

Description

A clear and concise description of what the bug is.

When you initialize the editorjs instance with readOnly: false and then later toggle it to true using editor.readOnly.toggle() then this library still tries to call editor.save() causing an error.

This error does not happen when editorjs-undo is not installed.

image

Environment

  • Editor.js version: 2.23.2
  • Plugins you use with their versions:
    "@editorjs/embed": "2.5.0",
    "@editorjs/header": "2.6.2",
    "@editorjs/image": "2.6.2",
    "@editorjs/list": "1.6.2",
    "@editorjs/paragraph": "2.8.0",
    "@editorjs/table": "2.0.1",
    "editorjs-undo": "1.0.1",
  • Device, Browser, OS:
    Device: Macbook M1 Pro
    Browser: Chrome Version 98.0.4758.102 (Official Build) (arm64)
    OS: macOS Monterey version 12.1

Current behavior

Reproduction steps:

  1. Create EditorJS instance with readOnly: false
  2. Inject instance into Undo
  3. Toggle editor to readOnly mode using editor.readOnly.toggle()
  4. Observe the error

Expected behavior

The library should know how to handle readOnly mode and respond accordingly when readOnly mode is toggled between true/false

Configurable Undo/Redo keyboard shortcodes

Context

The keyboard shortcodes vary depending on the operating system or the language. It is hard to keep a standard here.

Default Undo/Redo shortcodes

MacOS metaKey + z metaKey + y
Other OS ctrlKey + z ctrlKey + y

Objective

Allow users to configure their custom keyboard shortcodes to dispatch the Undo/Redo actions.

Checklist

  • Allow adding keyboard shortcodes via plugin configuration
  • Keep the default shortcodes when no config is added

Add pretier config file

Is your feature request related to a problem? Please describe.

Because of the variety of default prettier configurations among developers to reduce problems from auto stylizing code its necesary to add a code style file ".prettierrc"

Describe the solution you'd like

A .prettierrc file with the parameters to stylize the code

Describe alternatives you've considered

A .prettierrc file with the parameters to stylize the code

Additional context

Hover over @editorjs/table trigger mutationDebouncer

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

On hover action, the column and row creator toolbars show and hide causing the attribute mutation. I have added an exclusion for this toolbar's class.

Environment

  • Editor.js version: 2.25.0
  • Plugins you use with their versions:
    @editorjs/table: 2.0.2
    editorjs-undo: 2.0.3

Current behaviour

On hover action, the column and row creator toolbars show and hide causing the attribute mutation

Screen.Recording.2022-06-29.at.9.05.01.PM.mov

Expected behaviour

When on hover actions in the table toolbars, does not save it as a mutation in the observer

  • Exclude from the mutationHandler the class tc-toolbox which is the class of the table toolbar
2022-06-29.11-18-00.mp4

Add Typescript support

Is your feature request related to a problem? Please describe.

I'm working on a Typescript project and ideally, this library should have Typescript type declarations

Describe the solution you'd like

Add Typescript type declaration files

Describe alternatives you've considered

Creating my own type declaration files inline in my project for this library, but that is not a very maintainable solution.

Undo does not work in document with initial data

Description

Undo does not work in document with initial data

Environment

  • Editor.js version: 2.0.8
  • Plugins you use with their versions:
  • Device, Browser, OS: MacBook Pro (14-inch, 2021) Apple M1 Pro, MacOS Monterey 12.5, Chrome 104.0.5112.79 (Official Build) (arm64), Node v16.15.0,

Steps to reproduce:

  1. Open document with initial data
  2. Type something anywere
  3. Press 'CMD+Z'

Current behavior

  • changes are not rolled back
  • page is scrolled down to the bottom.

Expected behavior

Changes should be rolled back in appropriate order or appearance

Implementation code

...
editorRef.current = new EditorJS({
        placeholder: 'Enter some reach text...',
        inlineToolbar: true,
        readOnly,
        data,
        holder: 'editorjs',
        onReady: () => {
          const undo = new Undo({
            editor: editorRef.current,
            config: {
              shortcuts: {
                undo: 'CMD+Z',
                redo: 'CMD+SHIFT+Z'
              }
            }
          });
          if (data) undo.initialize(data);
          return undo;
        },
        tools: EDITOR_JS_TOOLS({
          readOnly,
          policyId: orgPolicyId,
          orgId,
          companyName: orgName,
          blocks: data?.blocks,
          orgEntities,
          ...orgParams
        }),
        tunes: ['blockTune', 'anchorBlockTune']
});
...

Note:

Work well in empty document.

Uncaught TypeError: Cannot read properties of undefined (reading 'holder') #66

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

A clear and concise description of what the bug is.

Environment

  • Editor.js version:
  • Plugins you use with their versions:
  • Device, Browser, OS:

Current behavior

Include code samples, errors and stack traces if appropriate.
If reporting a bug, please include the reproducing steps.

Expected behavior

A clear and concise description of what you expected to happen.

Additional context

Add any other context about the problem here.

EditorJs-undo compatibility with ReactJs component?

I am using react-editor-js npm package and I would like to extend it with undo.

const handleReady = (editor) => {
        new Undo({ editor });
};

<EditorJs
        instanceRef={instance => (editorJsRef.current = instance)}
        placeholder="Start typing what's in your head..."
        tools={EDITOR_JS_TOOLS}
        data={data}
        onReady={handleReady}
/>

According to your documentation, this should work. But error breaks the page:
image

In this case e = this.editor.configuration.holder.

holder property in editor instance I am passing in handleReady function is a string with editor container ID. But library code references it as DOM element.

This workaround works (converting element ID to DOM element):

const handleReady = (editor) => {
        let temp = document.getElementById(editor.configuration.holder);
        editor.configuration.holder = temp;

        new Undo({ editor });
};

But I don't think that I should override this.
Also can you update README.md to show an example how to integrate this with https://www.npmjs.com/package/react-editor-js?

Save function contains a bug where index is used instead of indexInState

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

There is a bug in the save function where index is incorrectly being used in place of indexInState.

Environment

  • Editor.js version: 2.22.2
  • Plugins you use with their versions: editorjs-undo v2.0.0
  • Device, Browser, OS: Macbook Pro, Chrome, Mac OS

Current behavior

When determining the caretIndex, index is incorrectly used in the state[index].type === 'header' comparison

/**
 * Adds the saved data in the history stack and updates current position.
 */
save(state) {
  if (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);

  const index = this.blocks.getCurrentBlockIndex();
  const blockCount = this.blocks.getBlocksCount();
  let indexInState = index;

  if (!state[index]) indexInState -= (blockCount - state.length);
  const caretIndex = state[indexInState].type === 'paragraph' || state[index].type === 'header'
    ? this.getCaretIndex(index) : null;
  this.stack.push({ index: indexInState, state, caretIndex });
  this.position += 1;
  this.onUpdate();
}

Expected behavior

When determining the caretIndex, indexInState should be used in both comparisons

/**
 * Adds the saved data in the history stack and updates current position.
 */
save(state) {
  if (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);

  const index = this.blocks.getCurrentBlockIndex();
  const blockCount = this.blocks.getBlocksCount();
  let indexInState = index;

  if (!state[index]) indexInState -= (blockCount - state.length);
  const caretIndex = state[indexInState].type === 'paragraph' || state[indexInState].type === 'header'
    ? this.getCaretIndex(index) : null;
  this.stack.push({ index: indexInState, state, caretIndex });
  this.position += 1;
  this.onUpdate();
}

Caret should maintain its current position during CMD+Z and CMD+Y operations within a text block

CMD+Z and CMD+Y operations on text selections within a text block cause the caret to unexpectedly jump to the end of the current text block rather than remaining in its current location.

CMD+Z and CMD+Y operations on text selections within a text block should not cause the caret to unexpectedly jump to the end of the current text block. The caret should remain in the position it was in when the CMD+Z or CMD+Y operation was initiated.

If text deleted from within a text block is restored using CMD+Z, the restored text should be highlighted, indicating that it is currently selected.

  • If the user then presses the left or right arrow on their keyboard, the caret should be appear at the beginning or end of the restored text, respectively.
  • If the user begins entering new characters while a restored selection is highlighted, the restored selection should be replaced and the caret should appear to the right of the first character entered.
  • If the user presses CMD+Y to re-delete a restored (and highlighted) selection, the caret should appear immediately to the left of where the first character in the deleted selection was located.

The caret currently jumps to the end of the current text block when CMD+Z and CMD+Y are used, as shown below:

Screen.Recording.2022-02-07.at.9.20.57.AM.mov

The caret should maintain its position during CMD+Z and CMD+Y operations, as shown below:

Screen.Recording.2022-02-07.at.10.11.09.AM.mov

Unable to set CMD+SHIFT+Z as redo shortcut

Description

I always use cmd+z for undo and cmd+shift+z for redo in every application I use so I wanted to set the same shortcuts for this library. However if I set it up like that then both cmd+z and cmd+shift+z will perform an undo action.

My configuration:

const undo = new Undo({
  editor,
  config: {
    shortcuts: {
      undo: "CMD+Z",
      redo: "CMD+SHIFT+Z",
    },
  },
});

Environment

  • Editor.js version: 2.23.2
  • Plugins you use with their versions: editorjs-undo: 2.0.0-rc.3
  • Device, Browser, OS: Apple M1 Pro, Chrome Version 100.0.4896.60 (Official Build) (arm64), MacOS Monterey Version 12.2.1

Current behavior

Having both cmd+z as undo and cmd+shift+z as redo in the shortcuts config will result in both performing an undo action.

Expected behavior

The shortcuts should respect the config sent into Undo.

Uncaught TypeError: Cannot read properties of undefined (reading 'holder')

const Demo2 = () => {
  const edjsParser = edjsHTML();

  const handleReady = (editor) => {
    new Undo({ editor });
    new DragDrop(editor);
  };

  const handleChange = (api, newData) => console.log(newData, edjsParser.parse(newData), 'Something is changing!!');

  return (
    <EditorJs
      tools={EDITOR_JS_TOOLS}
      onReady={handleReady}
      onChange={handleChange}
    />
  );
};

Steps to reproduce

  1. Type something

  2. Ctrl + Z

  3. click the editor

    "editorjs-undo": "^0.3.0",
    "react-editor-js": "^1.10.0",

TypeError: can't access property "type", t[i] is undefined in Next.js

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

I'm getting a weird error when using this component with NextJS. The page crashes, but is fixed after reloading, and doesn't appear for a while? It seems to be random. Possibly a SSR issue?

Environment

  • Editor.js version: v2.25.0
  • Plugins you use with their versions: DragDrop
  • Device, Browser, OS: MacOS in Firefox

Current behavior

Unhandled Runtime Error

TypeError: can't access property "type", t[i] is undefined
Call Stack
value
node_modules/editorjs-undo/dist/bundle.js (1:6033)
value/<
node_modules/editorjs-undo/dist/bundle.js (1:5490)```

### Expected behavior

The page doesn't crash.

Undo with CMD+Z does not work across multiple blocks

Precheck

  • Do a quick search and make sure the bug has not been reported yet.
  • Please disclose security vulnerabilities privately at [email protected].
  • Finally, be nice and have fun!.

Description

If a user makes changes in more than one block and tries to undo those changes with CMD+Z, the plugin breaks and unexpectedly deletes a block when it should not.

Environment

  • Editor.js version: 2.23.2
  • Plugins you use with their versions: editorjs-undo (2.0.0-rc.3)
  • Device, Browser, OS: Macbook Pro, Chrome, MacOS

Current behavior

The plugin unexpectedly deletes content during CMD+Z operations across multiple blocks, as shown below:

undo-deletes-second-block.mov

To recreate this bug, take the following steps:

  1. Enter some text in a paragraph block
  2. Press enter and enter some text in a new paragraph block
  3. Select and delete some of the text in the first paragraph block
  4. Select and delete some of the text in the second paragraph block
  5. Press CMD+Z
  6. Notice that the second paragraph block is deleted
  7. Press CMD+Z
  8. Notice that the following error is thrown:

no-block-at-index-1

Expected behavior

Undo operations with CMD+Z should work properly across multiple blocks instead of having content deleted unexpectedly, as shown below:

undo-does-not-delete-second-block.mov

Additional context

The plugin is currently incorrectly deleting a block when it should not because no entry is inserted into the stack when a user moves between blocks. This causes the blockWasSkipped function to return true when it should not. It compares the index and compIndex obtained from the stack, and since there was no stack entry for when the user switched from one block to another, this condition evaluates to true and the second block in the example I provided gets deleted.

block-was-skipped-function

if-block-was-skipped

For what it's worth, I did attempt to implement a fix for this issue by modifying the blockWasSkipped function to no longer do an index comparison and also adding a new click listener/handler to save and insert new stack entries when the user switched between blocks, but my solution did not seem stable across environments. These changes are shown below:

block-was-skipped-function-modified

handle-click-function

Unfortunately I do not have the bandwidth to continue looking into a solution for this issue, so I'm hoping someone in the community can solve it and that the information I've provided here helps with that effort.

Security Policy violation SECURITY.md

This issue was automatically created by Allstar.

Security Policy Violation
Security policy not enabled.
A SECURITY.md file can give users information about what constitutes a vulnerability and how to report one securely so that information about a bug is not publicly visible. Examples of secure reporting methods include using an issue tracker with private issue support, or encrypted email with a published key.

To fix this, add a SECURITY.md file that explains how to handle vulnerabilities found in your repository. Go to https://github.com/kommitters/editorjs-undo/security/policy to enable.

For more information, see https://docs.github.com/en/code-security/getting-started/adding-a-security-policy-to-your-repository.


This issue will auto resolve when the policy is in compliance.

Issue created by Allstar. See https://github.com/ossf/allstar/ for more information. For questions specific to the repository, please contact the owner or maintainer.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.