Skip to content

[examples] Feature: Added examples (for the website) #8258

Merged
etrepum merged 5 commits into
facebook:mainfrom
m-santanna:examples
Mar 28, 2026
Merged

[examples] Feature: Added examples (for the website) #8258
etrepum merged 5 commits into
facebook:mainfrom
m-santanna:examples

Conversation

@m-santanna

Copy link
Copy Markdown
Contributor

Description

Added 4 examples to the /examples directory:

  • Notion like editor
  • Chatapp like textbox
  • Toolbar Editor
  • Rich input

These examples will be useful for the website, since we will be importing the editors. Also, we will link the editors to stackblitz from the site.

Test plan

I tested them on my personal branch in stackblitz. Here are the links:

Notion

https://stackblitz.com/github/m-santanna/lexical/tree/examples/examples/website-notion

Toolbar

https://stackblitz.com/github/m-santanna/lexical/tree/examples/examples/website-toolbar

Chatapp

https://stackblitz.com/github/m-santanna/lexical/tree/examples/examples/website-chat

Rich Input

https://stackblitz.com/github/m-santanna/lexical/tree/examples/examples/website-rich-input

@vercel

vercel Bot commented Mar 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
lexical Ready Ready Preview, Comment Mar 28, 2026 6:41pm
lexical-playground Ready Ready Preview, Comment Mar 28, 2026 6:41pm

Request Review

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Mar 26, 2026
@etrepum etrepum added the extended-tests Run extended e2e tests on a PR label Mar 26, 2026
@etrepum

etrepum commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

The chat input example would be a great place to demonstrate using multiple editors on the page (a readonly editor per chat message, and a writable editor for the chat input). This way it would be trivial to add support for rich text. The chat messages should also scroll to the bottom after submit.

(this is just based on using the examples, not a close reading of the code)

Comment on lines +177 to +191
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.insertNodes([$createTextNode(emoji)]);
} else {
// fallback: append to end
const root = $getRoot();
const lastChild = root.getLastChild();
if (lastChild) {
lastChild.selectEnd();
const sel = $getSelection();
if (sel !== null) {
sel.insertNodes([$createTextNode(emoji)]);
}
}
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.insertNodes([$createTextNode(emoji)]);
} else {
// fallback: append to end
const root = $getRoot();
const lastChild = root.getLastChild();
if (lastChild) {
lastChild.selectEnd();
const sel = $getSelection();
if (sel !== null) {
sel.insertNodes([$createTextNode(emoji)]);
}
}
}
$insertNodes([$createTextNode(emoji)]);
.read(() => $getRoot().getTextContent().trim() !== '');
if (hasContent) {
onSubmit(editor.getEditorState());
clearEditor(editor);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With ClearEditorExtension as a dependency:

Suggested change
clearEditor(editor);
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);
namespace: '@lexical/website/chat-message',
theme: chatMessageTheme,
}),
// eslint-disable-next-line react-hooks/exhaustive-deps

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exception isn't needed, initialState is a dependency. Both the EditorState and the function references are stable.

useEffect(() => {
return editor.registerUpdateListener(({editorState}) => {
editorState.read(() => {
setCount($getRoot().getTextContent().length);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
setCount($getRoot().getTextContent().length);
setCount($getRoot().getTextContentSize());
Comment on lines +135 to +142
editor.registerCommand(
SELECTION_CHANGE_COMMAND,
(_payload, _newEditor) => {
$updateToolbar();
return false;
},
COMMAND_PRIORITY_LOW,
),

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is redundant, the update listener is called when the selection changes

Suggested change
editor.registerCommand(
SELECTION_CHANGE_COMMAND,
(_payload, _newEditor) => {
$updateToolbar();
return false;
},
COMMAND_PRIORITY_LOW,
),

@etrepum etrepum left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The clearEditor function is still there

Comment on lines +23 to +35
export function clearEditor(editor: LexicalEditor) {
editor.update(() => {
const root = $getRoot();
root.clear();
const paragraph = $createParagraphNode();
paragraph.append($createTextNode(''));
root.append(paragraph);
if ($isParagraphNode(paragraph)) {
paragraph.selectEnd();
}
});
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be unused now

Suggested change
export function clearEditor(editor: LexicalEditor) {
editor.update(() => {
const root = $getRoot();
root.clear();
const paragraph = $createParagraphNode();
paragraph.append($createTextNode(''));
root.append(paragraph);
if ($isParagraphNode(paragraph)) {
paragraph.selectEnd();
}
});
}
.read(() => $getRoot().getTextContent().trim() !== '');
if (hasContent) {
onSubmit(editor.getEditorState());
clearEditor(editor);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
clearEditor(editor);
editor.dispatchCommand(CLEAR_EDITOR_COMMAND, undefined);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(this change will also need changes to the imports)

@etrepum

etrepum commented Mar 28, 2026

Copy link
Copy Markdown
Collaborator

These nits are the last things I noticed here, so once these are cleaned up it looks good to go!

@etrepum etrepum added this pull request to the merge queue Mar 28, 2026
Merged via the queue into facebook:main with commit cdfd31a Mar 28, 2026
37 checks passed
@etrepum etrepum mentioned this pull request Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. extended-tests Run extended e2e tests on a PR

2 participants