slab / quill

Quill is a modern WYSIWYG editor built for compatibility and extensibility
https://quilljs.com
BSD 3-Clause "New" or "Revised" License
43.77k stars 3.41k forks source link

Update modules without re-instantiating the editor? #4234

Open ViktorZhurbin opened 5 months ago

ViktorZhurbin commented 5 months ago

Question: Do I have to create a new Quill instance to update modules? Or is there a way to update them directly, something like:

const quill = new Quill(editorContainer, {
  modules, // <- this can change
  theme: "snow",
 });

// later on
quill.options.modules = updatedModules. // doesn't work, obviously

Context: I need to override some default keyboard bindings, and I do it through the config as suggested. When a binding needs to be updated (eg, user can change it in settings), it looks like I need to create a new Quill instance with updated config. This creates an extra hustle of saving/re-applying existing user input and selection.

luin commented 5 months ago

One approach would be updating quill.keyboard.options directly so in binding handlers, you could read the options dynamically

ViktorZhurbin commented 5 months ago

One approach would be updating quill.keyboard.options directly so in binding handlers, you could read the options dynamically

Typescript would not be happy about it. There's probably a reason for this property to be protected:

Property 'options' is protected and only accessible within class 'Module<T>' and its subclasses
Screenshot 2024-06-04 at 08 46 47
ViktorZhurbin commented 5 months ago

I opened #4237 which seems like a separate bug to me. I wouldn't hit it, if I didn't have to re-create the editor. But it's still a bug on its own.

singintime commented 2 months ago

I'm facing the same problem, and I think I have a solution for that: https://github.com/slab/quill/discussions/4397

Happy to create a PR and make the Quill editor reconfigurable

showonne commented 1 month ago

hide/show different modules according to different condition is very common.