LexicalExtension
interfaceAn Extension is a composable unit of LexicalEditor configuration (nodes, theme, etc) used to create an editor, plus runtime behavior that is registered after the editor is created. An Extension may depend on other Extensions, and provide functionality to other extensions through its config.
Import
import { LexicalExtension } from '@modular/sdk/editor';Members19
- $initialEditorStateoptional
InitialEditorStateTypeThe initial EditorState as a JSON string, an EditorState, or a function to update the editor (once).
- afterRegistrationoptional
(editor: LexicalEditor, config: Config, state: ExtensionRegisterState<Init, Output>) => () => voidRun any code that must happen after initialization of the editor state (which happens after all register calls).
- buildoptional
(editor: LexicalEditor, config: Config, state: ExtensionBuildState<Init>) => OutputPerform any tasks that require a LexicalEditor instance, but before registration has taken place. May provide output to be used by dependencies or the application (commands, components, etc.). This will only be run once, and any work performed by the output function must not require cleanup.
- configoptional
ConfigThe default configuration specific to this Extension. This Config may be seen by this Extension, or any Extension that uses it as a dependency. The config may be mutated on register, this is particularly useful for vending functionality to other Extensions that depend on this Extension.
- conflictsWithoptional
string[]Extension names that must not be loaded with this Extension. If this extension and any of the conflicting extensions are configured in the same editor then a runtime error will be thrown instead of creating the editor. This is used to prevent extensions with incompatible and overlapping functionality from being registered concurrently, such as PlainTextExtension and RichTextExtension.
- dependenciesoptional
AnyLexicalExtensionArgument[]Other Extensions that this Extension depends on, can also be used to configure them
- editableoptional
CreateEditorArgs['editable']Whether the initial state of the editor is editable or not
- htmloptional
CreateEditorArgs['html']Overrides for HTML serialization (exportDOM) and deserialization (importDOM) that does not require subclassing and node replacement
- initoptional
(editorConfig: InitialEditorConfig, config: Config, state: ExtensionInitState) => InitPerform any necessary initialization before the editor is created, this runs after all configuration overrides for both the editor this this extension have been merged. May be used validate the editor configuration.
- mergeConfigoptional
(config: Config, overrides: Partial<Config>) => ConfigBy default, Config is shallow merged `{...a, ...b}` with shallowMergeConfig, if your Extension requires other strategies (such as concatenating an Array) you can implement it here.
- name
NameThe name of the Extension, must be unique
- namespaceoptional
CreateEditorArgs['namespace']The namespace of this Editor. If two editors share the same namespace, JSON will be the clipboard interchange format. Otherwise HTML will be used.
- nodesoptional
CreateEditorArgs['nodes'] | (() => CreateEditorArgs['nodes'])The nodes that this Extension adds to the Editor configuration, will be merged with other Extensions. Can be a function to defer the access of the nodes to editor construction which may be useful in cases when the node and extension are defined in different modules and have depenendencies on each other, depending on the bundler configuration.
- onErroroptional
(error: Error, editor: LexicalEditor) => voidThe editor will catch errors that happen during updates and reconciliation and call this. It defaults to `(error) => { throw error }`.
- onWarnoptional
(error: Error, editor: LexicalEditor) => voidOptional handler for recoverable, warn-level conditions (e.g. the update-recursion guard tripping) that the editor has already recovered from. Mirrors onError but at warn severity, so embedders can route the condition to telemetry without raising an error alarm. Defaults to a handler that throws in development and only `console.warn`s in production.
- parentEditoroptional
CreateEditorArgs['parentEditor']Used when this editor is nested inside of another editor
- peerDependenciesoptional
NormalizedPeerDependency<AnyLexicalExtension>[]Other Extensions, by name, that this Extension can optionally depend on or configure, if they are directly depended on by another Extension
- registeroptional
(editor: LexicalEditor, config: Config, state: ExtensionRegisterState<Init, Output>) => () => voidAdd behavior to the editor (register transforms, listeners, etc.) after the Editor is created, but before its initial state is set. The register function may also mutate the config in-place to expose data to other extensions that use it as a dependency.
- themeoptional
CreateEditorArgs['theme']EditorThemeClasses that will be deep merged with other Extensions