Skip to content

Commit

Permalink
docs: improve DecoratorNode docs
Browse files Browse the repository at this point in the history
Add description for DecoratorNode.prototype.decorate method,
add description to the docs website "Extending DecoratorNode" section.
  • Loading branch information
petrovmiroslav committed Nov 26, 2023
1 parent 0f7c78b commit 6dd94ec
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/lexical-website/docs/concepts/nodes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


# Nodes

## Base Nodes
Expand Down Expand Up @@ -271,7 +269,13 @@ export function $createVideoNode(id: string): VideoNode {
return new VideoNode(id);
}

export function $isVideoNode(node: LexicalNode | null | undefined): node is VideoNode {
export function $isVideoNode(
node: LexicalNode | null | undefined,
): node is VideoNode {
return node instanceof VideoNode;
}
```

Using `useDecorators`, `PlainTextPlugin` and `RichTextPlugin` execute `React.createPortal(reactDecorator, element)` for each `DecoratorNode`,
where the `reactDecorator` is what is returned by `DecoratorNode.prototype.decorate`,
and the `element` is an `HTMLElement` returned by `DecoratorNode.prototype.createDOM`.
3 changes: 3 additions & 0 deletions packages/lexical/src/nodes/LexicalDecoratorNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export class DecoratorNode<T> extends LexicalNode {
super(key);
}

/**
* The returned value is added to the LexicalEditor.prototype._decorators
*/
decorate(editor: LexicalEditor, config: EditorConfig): T {
invariant(false, 'decorate: base method not extended');
}
Expand Down

0 comments on commit 6dd94ec

Please sign in to comment.