RRZE-Webteam / rrze-elements-blocks

Sammlung von Gestaltungselementen für WordPress-Websites für den BlockEditor
GNU General Public License v3.0
2 stars 0 forks source link

Provide additional Undo's for complex blocks #54

Closed lukasniebler closed 8 months ago

lukasniebler commented 9 months ago

Mithilfe von useDispatch können zusätzliche Undo-Events hinzugefügt werden. Bevor der Block entfernt wird, könnte man versuchen ein Undo-State hinzuzufügen, um das Problem verlorener Inhalte zu minimieren.

Könnte klappen

  useEffect(() => {
    if (hasBlockBeenRemoved) {
      // Provide an option to undo the removal or automatically call undo
      undo();
    }
  }, [hasBlockBeenRemoved, undo]);

Weitere Lösungsansätze

s. "Undo trap": Avoid getting stuck in the editing state issue

lukasniebler commented 8 months ago

Die Lösung war die Nutzung von

import { useDispatch } from …
import { store as BlockEditorStore } from …

…
const { __unstableMarkNextChangeAsNotPersistent } = useDispatch(
    blockEditorStore
  );

  …
  __unstableMarkNextChangeAsNotPersistent();
  setAttributes(…)
  );