editor.js icon indicating copy to clipboard operation
editor.js copied to clipboard

Updating list of tools after editor is initialized

Open rgembalik opened this issue 2 years ago • 5 comments

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?

rgembalik avatar Jun 28 '23 10:06 rgembalik

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.

ConnectGrid avatar Sep 12 '23 05:09 ConnectGrid

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

neSpecc avatar Sep 14 '23 10:09 neSpecc

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.

rgembalik avatar Sep 17 '23 12:09 rgembalik

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

volodymyr-tomorrow avatar Nov 19 '23 20:11 volodymyr-tomorrow

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!

ShravanKarnati avatar Dec 23 '23 00:12 ShravanKarnati