Function: getPeerDependencyFromEditorOrThrow()
getPeerDependencyFromEditorOrThrow<
Extension
>(editor
,extensionName
):LexicalExtensionDependency
<Extension
>
Get the finalized config and output of an Extension that was used to build the editor by name.
This can be used from the implementation of a LexicalNode or in other situation where you have an editor reference but it's not easy to pass the config around. Use this version if you do not have a concrete reference to the Extension for some reason (e.g. it is an optional peer dependency, or you are avoiding a circular import).
Both the explicit Extension type and the name are required.
Type Parameters
• Extension extends AnyLexicalExtension
= never
Parameters
• editor: LexicalEditor
The editor that may have been built using extension
• extensionName: Extension
["name"
]
The name of the Extension
Returns
LexicalExtensionDependency
<Extension
>
The config and output of the Extension
Example
import type { EmojiExtension } from "./EmojiExtension";
export class EmojiNode extends TextNode {
// other implementation details not included
createDOM(
config: EditorConfig,
editor?: LexicalEditor | undefined
): HTMLElement {
const dom = super.createDOM(config, editor);
addClassNamesToElement(
dom,
getPeerDependencyFromEditorOrThrow<typeof EmojiExtension>(
editor || $getEditor(),
"@etrepum/lexical-emoji-extension/Emoji",
).config.emojiClass,
);
return dom;
}
}