What is @lexical/link?
@lexical/link is a plugin for the Lexical framework that provides functionality for handling links within a Lexical editor. It allows users to insert, edit, and manage hyperlinks in their text content.
What are @lexical/link's main functionalities?
Insert Link
This feature allows you to insert a hyperlink into the editor. The code sample demonstrates how to create a link node and insert it into the current selection.
import { $createLinkNode } from '@lexical/link';
const linkNode = $createLinkNode('https://example.com');
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
selection.insertNodes([linkNode]);
}
});
Edit Link
This feature allows you to edit an existing hyperlink in the editor. The code sample shows how to update the URL of a link node within the current selection.
import { $getSelection, $isRangeSelection } from 'lexical';
import { $isLinkNode } from '@lexical/link';
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
const nodes = selection.getNodes();
nodes.forEach(node => {
if ($isLinkNode(node)) {
node.setURL('https://new-url.com');
}
});
}
});
Remove Link
This feature allows you to remove a hyperlink from the editor. The code sample demonstrates how to replace a link node with its text content, effectively removing the link.
import { $getSelection, $isRangeSelection } from 'lexical';
import { $isLinkNode } from '@lexical/link';
editor.update(() => {
const selection = $getSelection();
if ($isRangeSelection(selection)) {
const nodes = selection.getNodes();
nodes.forEach(node => {
if ($isLinkNode(node)) {
node.replace(node.getTextContent());
}
});
}
});
Other packages similar to @lexical/link
draft-js
Draft.js is a rich text editor framework for React. It provides extensive support for handling links, including inserting, editing, and removing links. Compared to @lexical/link, Draft.js offers a more comprehensive set of features for building rich text editors but may have a steeper learning curve.
slate
Slate is another popular framework for building rich text editors in React. It offers similar functionalities for managing links, such as inserting, editing, and removing links. Slate is highly customizable and flexible, making it a strong alternative to @lexical/link.
quill
Quill is a powerful, open-source WYSIWYG editor that provides built-in support for links. It allows users to easily insert and manage hyperlinks within the editor. Quill is known for its ease of use and extensive documentation, making it a good option for developers looking for a straightforward solution.
0.3.8 (July 20, 2022)
Lots of bug fixes.
Introduces TypeaheadPlugin and associated primitives, which consolidate the implementation of all such functionality (mentions and component picker) and create a base to build similar typeahead functionality from.
Introduces TableOfContents plugin for easier navigation of long-form documents. Available in the playground in the settings menu (bottom-left corner).
Introduces a "clipboard viewer" functionality in the local dev environment. When active, it shows the clipboard content the last time the paste event was fired with the editor focused.
- Remove default styling imports on HTML paste (#2663) Acy Watson
- fix(lexical-playground): code lang display (#2658) 子瞻 Luci
- chore(lexical-playground): remove files that should not be submitted (#2662) 子瞻 Luci
- Selection.extract fix (#2620) Acy Watson
- Specify the return type of getNearestNodeOfType. (#2651) hiraoka
- Autolink default protocol (#2654) Gerard Rovira
- fix(doc): RichTextPlugin placeholder (#2655) unvalley
- fix(lexical): calculate range selection formatting (#2643) 子瞻 Luci
- Add TableOfContentsPlugin (#2634) Karam Qaoud
- Port ASCII State Tree to Browser Extension (#2625) Will
- Fix markdown text matchers during md import (#2644) Maksim Horbachevsky
- fix(lexical): Japanese IME issue (#2623) 子瞻 Luci
- Remove comment box from footer (#2639) John Flockton
- Delete doc from ydocMap on unmount. Fixes init on re-mount (#2637) Maksim Horbachevsky
- feat: new way to delete comments and threads (#2570) Adithya Vardhan
- Lexical Typeaheads (#2534) Tyler Bainbridge
- Add $insertBlockNode (#2633) Gerard Rovira
- Add seperate flag for if script had loaded (#2628) John Flockton
- Fix Chrome types in Lexical DevTools (#2627) John Flockton
- Capture the expected payload type in commands (#2537) Patrik Åkerstrand
- fix unit test warning (#2618) Acy Watson
- fix(lexical-playground): fix toolbar-item button style bug in safari (#2621) 子瞻 Luci
- add docs (#2611) Acy Watson
- Add default value for undefined case in markdown transformers (#2453) Noah Cook
- Add PasteLog Plugin (#2609) Acy Watson
- Fix pasting inline code blocks (#2607) Maksim Horbachevsky