@lexical/extension/getPeerDependencyFromEditor
Functions
getPeerDependencyFromEditor()
getPeerDependencyFromEditor<
Extension>(editor,extensionName):LexicalExtensionDependency<Extension> |undefined
Defined in: packages/lexical-extension/src/getPeerDependencyFromEditor.ts:44
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.
Inside an editor read/update, prefer $getPeerDependency — it
resolves the editor via $getEditor() so you don't have to thread it
through.
Type Parameters
Extension
Extension extends AnyLexicalExtension = never
Parameters
editor
The editor that may have been built using extension
extensionName
Extension["name"]
The name of the Extension
Returns
LexicalExtensionDependency<Extension> | undefined
The config and output of the Extension or undefined
Example
import type { HistoryExtension } from "@lexical/history";
getPeerDependencyFromEditor<typeof HistoryExtension>(editor, "@lexical/history/History");
getPeerDependencyFromEditorOrThrow()
getPeerDependencyFromEditorOrThrow<
Extension>(editor,extensionName):LexicalExtensionDependency<Extension>
Defined in: packages/lexical-extension/src/getPeerDependencyFromEditor.ts:100
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.
Inside an editor read/update, prefer $getPeerDependency (which
resolves the editor via $getEditor()) and add your own invariant if
the peer is required.
Type Parameters
Extension
Extension extends AnyLexicalExtension = never
Parameters
editor
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(),
"@lexical/playground/emoji",
).config.emojiClass,
);
return dom;
}
}