2 * Copyright (c) Meta Platforms, Inc. and affiliates.
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
9 import type {KlassConstructor, LexicalEditor} from '../LexicalEditor';
10 import type {NodeKey} from '../LexicalNode';
11 import type {ElementNode} from './LexicalElementNode';
13 import {EditorConfig} from 'lexical';
14 import invariant from 'lexical/shared/invariant';
16 import {LexicalNode} from '../LexicalNode';
18 // eslint-disable-next-line @typescript-eslint/no-unused-vars
19 export interface DecoratorNode<T> {
20 getTopLevelElement(): ElementNode | this | null;
21 getTopLevelElementOrThrow(): ElementNode | this;
25 // eslint-disable-next-line @typescript-eslint/no-unsafe-declaration-merging
26 export class DecoratorNode<T> extends LexicalNode {
27 ['constructor']!: KlassConstructor<typeof DecoratorNode<T>>;
28 constructor(key?: NodeKey) {
33 * The returned value is added to the LexicalEditor._decorators
35 decorate(editor: LexicalEditor, config: EditorConfig): T {
36 invariant(false, 'decorate: base method not extended');
39 isIsolated(): boolean {
47 isKeyboardSelectable(): boolean {
52 export function $isDecoratorNode<T>(
53 node: LexicalNode | null | undefined,
54 ): node is DecoratorNode<T> {
55 return node instanceof DecoratorNode;