Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[lexical-react][lexical-playground] Feature: Makes an inline node more easily linkable #7359

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

sescandell
Copy link
Contributor

Description

Currently if you want to put a link around an image, you need to be clever and "select" around the image. It works in a way, but is not easy to use neither well presented.
Thanks to these changes, we globally allow to put a link on an inline node such as the ImageNode from the playground

Before

Nothing to show

After

image

Copy link

vercel bot commented Mar 21, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
lexical ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 23, 2025 11:04pm
lexical-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 23, 2025 11:04pm

@facebook-github-bot facebook-github-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 21, 2025
Copy link
Collaborator

@etrepum etrepum left a comment

Choose a reason for hiding this comment

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

Seems like a great start, it would be nice to clean up the functionality so that it's more correct in the general case. I would recommend adding some function(s) to @lexical/selection to facilitate the shared logic between these different modules so that this code is simpler, and that it's easier to do these things elsewhere too

Comment on lines 47 to 49
.filter(
(n) => $isTextNode(n) || $isElementNode(n) || $isDecoratorNode<T>(n),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

What's the purpose of this? To avoid LineBreakNode? This filter is why the code fails typecheck because the guard isn't implied with this version of TypeScript.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, this update wasn’t intended to be reviewed yet — I’m still working on it. Sorry, I shouldn’t have pushed it.

To answer your question: no, I can’t limit it to $isTextNode and $isElementNode because, for the primary objective of this PR, this wouldn’t work for ImageComponent (which is a DecoratorNode).

The goal is not to restrict it to specific blocks. In the initial implementation, getSelectedNode was designed to return either a TextNode or an ElementNode, and I wanted to stay as close as possible to that. However, in a NodeSelection, it can actually return more. For formatting purposes (e.g., links, formatting, toolbar), DecoratorNode should be allowed to support components like ImageComponent.

That said, after looking at your comment (and the code), I realize that, aside from LineBreakNode, there aren’t any other relevant types of elements.

I’m still working on this. I’ll mention you once I think it’s ready for review.

Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @etrepum,

I’ve removed the filter and updated the return type of getSelectedNode.
In previous usages, all cases either already checked the type of the node before using it or didn’t require the check at all.

Let me know your thoughts.

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants