/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * */ import type { ElementFormatType, LexicalNode, LexicalUpdateJSON, NodeKey, SerializedLexicalNode, Spread, } from 'lexical'; import type {JSX} from 'react'; import {DecoratorNode} from 'lexical'; export type SerializedDecoratorBlockNode = Spread< { format: ElementFormatType; }, SerializedLexicalNode >; export class DecoratorBlockNode extends DecoratorNode { __format: ElementFormatType; constructor(format?: ElementFormatType, key?: NodeKey) { super(key); this.__format = format || ''; } afterCloneFrom(prevNode: this): void { super.afterCloneFrom(prevNode); this.__format = prevNode.__format; } exportJSON(): SerializedDecoratorBlockNode { return { ...super.exportJSON(), format: this.__format || '', }; } updateFromJSON( serializedNode: LexicalUpdateJSON, ): this { return super .updateFromJSON(serializedNode) .setFormat(serializedNode.format || ''); } canIndent(): false { return false; } createDOM(): HTMLElement { return document.createElement('div'); } updateDOM(): false { return false; } setFormat(format: ElementFormatType): this { const self = this.getWritable(); self.__format = format; return self; } getFormat(): ElementFormatType { return this.getLatest().__format; } isInline(): false { return false; } } export function $isDecoratorBlockNode( node: LexicalNode | null | undefined, ): node is DecoratorBlockNode { return node instanceof DecoratorBlockNode; }