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

贡献者指南