codex-team/editor.js

How to catch Block's onFocus event simply

Open

#1.004 geöffnet am 8. Jan. 2020

Auf GitHub ansehen
 (4 Kommentare) (2 Reaktionen) (0 zugewiesene Personen)TypeScript (1.985 Forks)batch import
good first issue

Repository-Metriken

Stars
 (26.602 Stars)
PR-Merge-Metriken
 (Keine gemergten PRs in 30 T)

Beschreibung

I think it is more useful to implement focus event in Editor.js ! To catch Block's onFocus event, it needs to use MutationObserver currently.

  render() {
    const container = document.createElement('div');

    setTimeout(() => {
      const block = container.parentElement && container.parentElement.parentElement;

      if (block) {
        // TODO: disconnect
        const observer = new MutationObserver(() => {
          console.log(block.classList);
        });

        observer.observe(block, {
          attributeFilter: ['class'],
          attributes: true,
        });
      }  
    }, 100);

    return container;
  }

console output

DOMTokenList ["ce-block", value: "ce-block"]
DOMTokenList(2) ["ce-block", "ce-block--focused", value: "ce-block ce-block--focused"]

Contributor Guide