VolgaIgor / editorjs-gallery

Gallery block for Editor.js with multi-loading and sorting
MIT License
13 stars 8 forks source link

Deleting images or changing style not triggering onChange #5

Open pabloprieto opened 4 months ago

pabloprieto commented 4 months ago

can be reproduced with the following code:

import EditorJS from "@editorjs/editorjs";
import Gallery from "@kiberpro/editorjs-gallery";
import Sortable from "sortablejs";

const editorContainer = document.getElementById("editor");
const uploadUrl = "/upload";

const editor = new EditorJS({
  holder: editorContainer,
  tools: {
    gallery: {
      class: Gallery,
      config: {
        sortableJs: Sortable,
        endpoints: {
          byFile: uploadUrl,
          byUrl: uploadUrl,
        },
        field: "file",
      },
    },
  },
  onChange: () => {
    editor.save().then((data) => {
      console.debug(data);
    });
  },
});

Adding or moving images correctly trigger EditorJs onChange event, but removing images or changing style does not. Any workaround or suggestion to make it work?

lukaszb commented 3 weeks ago

I can confirm it does not trigger EditorJS.onChange when changing style (fit vs slider). It does trigger for me when deleting items, though.

@VolgaIgor bump as without this trigger it's hard to use core functionality.

Walkaround I'm currently using:

  class MyImageGallery extends ImageGallery {
    styleToggled(tuneName: string) {
      super.styleToggled(tuneName)

      // hack: this triggers EditorJS's onChange method
      this.ui.nodes.caption.innerHTML = this.ui.nodes.caption.innerHTML
    }
  }