Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
@lexical/link
Advanced tools
This package contains the functionality for Lexical links.
@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.
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());
}
});
}
});
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 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 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.
FAQs
This package contains the functionality for Lexical links.
We found that @lexical/link demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.