@lexical/extension/getExtensionDependency
Functions
$getExtensionDependency()
$getExtensionDependency<
E>(extension):LexicalExtensionDependency<E>
Defined in: packages/lexical-extension/src/getExtensionDependency.ts:44
Get the finalized config and output for extension from the editor
currently in scope. A $-flavored shorthand for
getExtensionDependencyFromEditor($getEditor(), extension).
Throws if the editor was not built with extension as a dependency.
Type Parameters
E
E extends AnyLexicalExtension
Parameters
extension
E
Returns
Example
import {$getExtensionDependency} from '@lexical/extension';
import {KeywordsExtension} from './KeywordsExtension';
class KeywordNode extends TextNode {
createDOM(config: EditorConfig): HTMLElement {
const dom = super.createDOM(config);
dom.className =
$getExtensionDependency(KeywordsExtension).config.className;
return dom;
}
}
See
getExtensionDependencyFromEditor when you have an explicit editor reference (e.g. outside a read/update).
$getExtensionOutput()
$getExtensionOutput<
E>(extension):LexicalExtensionOutput<E>
Defined in: packages/lexical-extension/src/getExtensionDependency.ts:69
Shorthand for $getExtensionDependency(extension).output — the most
common reason to look up an extension dependency. Throws if the editor
was not built with extension as a dependency.
Type Parameters
E
E extends AnyLexicalExtension
Parameters
extension
E
Returns
Example
import {$getExtensionOutput} from '@lexical/extension';
import {DOMImportExtension} from '@lexical/html';
const nodes = $getExtensionOutput(DOMImportExtension).$generateNodesFromDOM(
dom,
);
See
$getExtensionDependency when you need both .config and
.output (or want to mirror the shape of
getExtensionDependencyFromEditor).
$getPeerDependency()
$getPeerDependency<
E>(extensionName):LexicalExtensionDependency<E> |undefined
Defined in: packages/lexical-extension/src/getExtensionDependency.ts:100
Get the finalized config and output for an optional peer extension by
name, from the editor currently in scope. A $-flavored shorthand for
getPeerDependencyFromEditor($getEditor(), extensionName).
Returns undefined if the editor was not built with the named
extension. Both the explicit Extension type and the name are
required so the returned config / output types are correct.
Type Parameters
E
E extends AnyLexicalExtension = never
Parameters
extensionName
E["name"]
Returns
LexicalExtensionDependency<E> | undefined
Example
import {$getPeerDependency} from '@lexical/extension';
import type {HistoryExtension} from '@lexical/history';
const dep = $getPeerDependency<typeof HistoryExtension>(
'@lexical/history/History',
);
if (dep) {
// …read dep.config / dep.output…
}
See
getPeerDependencyFromEditor when you have an explicit editor reference.