Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating list of tools after editor is initialized #2397

Open
rgembalik opened this issue Jun 28, 2023 · 5 comments · May be fixed by #2579
Open

Updating list of tools after editor is initialized #2397

rgembalik opened this issue Jun 28, 2023 · 5 comments · May be fixed by #2579

Comments

@rgembalik
Copy link

Hi there,

I was wondering, what would be the preferred method of updating a list of tools once the editor is already active and visible for users? I saw that there is a setter for configuration that handles new config, but I am not sure how to make EditorJS object utilize that new info. Right now setting new value won't update the editor.

My use case revolves around adding or removing toolbar items based on some external user config. I know that some blocks may not render after such a thing happens, but that is something I don't have a problem with as I know users won't mind losing a block when they disable some tool in their config.

Is destruction and reinitialization the only way to achieve this?

@ConnectGrid
Copy link

I'm faced with a similar dilemma. The tools object passed into the constructor requires that the class property be a class/variable reference, not just the name of a class in string form.

tools: {
    header: {
      class: Header,    // <--- must be a defined class at this point
      inlineToolbar : true
    },
    // ...
  }

This makes JSON.stringifying the tools object impossible. I haven't found an elegant way to pass a JSON string from the server to the JavaScript to construct this tools object without manually looping and replacing the class value in each tool definition.

Am I completely missing something? If there was a way to configure tools post-construction, this might be easier, and would solve the issue raised in this thread, too.

@neSpecc
Copy link
Member

neSpecc commented Sep 14, 2023

It could be implemented, but we need to understand why you prefer changing the tools list rather than just destroy/reinitialize the editor.

@rgembalik
Copy link
Author

I don't know about the others, but from my perspective, reinitialization does not work well UX-wise. Autofocus often reapplies, scroll resets, the editor's content flashes, and in some situations, the layout around the editor will "jump" due to editor size changes. All those things can be prevented somehow, but it's not a pleasant process to debug all those problems and apply fixes.

@volodymyr-tomorrow
Copy link

same issue here. We are updating config of the custom tool depending on the outer state. Unfortunately it does not take any effect...

@Shravankumarkarnati
Copy link

Hi @neSpecc, any update on this?

I tried a monkey patch in my personal project to add this functionality. Not sure if its right, but works fine.

happy to create a PR with necessary tweaks if you like!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants