import { ElementNode, type LexicalNode } from "lexical"; export class FocusableNode extends ElementNode { __hasFocus: boolean = false; setFocus(hasFocus: boolean) { const self = this.getWritable(); self.__hasFocus = hasFocus; } constructor(key?: string, hasFocus?: boolean) { super(key); hasFocus && (this.__hasFocus = hasFocus); } createDOM(): HTMLElement { const element = document.createElement("div"); element.classList.toggle("focus", this.__hasFocus); return element; } updateDOM(old: FocusableNode, dom: HTMLElement): boolean { if (this.__hasFocus != old.__hasFocus) { dom.classList.toggle("focus", this.__hasFocus); } return false; } } export function $isFocusableNode(node: LexicalNode): node is FocusableNode { return node instanceof FocusableNode; }