codex-team/editor.js

How to catch Block's onFocus event simply

Aperta

#1004 aperta il 8 gen 2020

 (4 commenti) (2 reazioni) (0 assegnatari)TypeScript (1985 fork)batch import
good first issue

Metriche repository

Star
 (26.602 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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"]

Guida contributor