codex-team/editor.js

How to catch Block's onFocus event simply

オープン

#1,004 opened on 2020/01/08

 (4 件のコメント) (2 件のリアクション) (0 人の担当者)TypeScript (1,985 件のフォーク)batch import
good first issue

Repository metrics

Stars
 (26,602 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

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

コントリビューターガイド