Skip to main content

Function: getPeerDependencyFromEditorOrThrow()

getPeerDependencyFromEditorOrThrow<Plan>(editor, planName): LexicalPlanDependency<Plan>

Get the finalized config and output of a Plan 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 Plan for some reason (e.g. it is an optional peer dependency, or you are avoiding a circular import).

Both the explicit Plan type and the name are required.

Type Parameters

Plan extends AnyLexicalPlan = never

Parameters

editor: LexicalEditor

The editor that may have been built using plan

planName: Plan["name"]

The name of the Plan

Returns

LexicalPlanDependency<Plan>

The config and output of the Plan

Example

import type { EmojiPlan } from "./EmojiPlan";
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 EmojiPlan>(
editor || $getEditor(),
"@etrepum/lexical-emoji-plan/Emoji",
).config.emojiClass,
);
return dom;
}
}

Defined in

lexical-builder/src/getPeerDependencyFromEditor.ts:82