codex-team/editor.js

How to catch Block's onFocus event simply

Open

#1,004 建立於 2020年1月8日

在 GitHub 查看
 (4 留言) (2 反應) (0 負責人)TypeScript (1,985 fork)batch import
good first issue

倉庫指標

Star
 (26,602 star)
PR 合併指標
 (30 天內沒有已合併 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"]

貢獻者指南