Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lexical/link

Package Overview
Dependencies
Maintainers
5
Versions
228
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lexical/link

This package contains the functionality for Lexical links.

  • 0.21.1-nightly.20241218.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
555K
decreased by-3%
Maintainers
5
Weekly downloads
 
Created

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

Keywords

FAQs

Package last updated on 18 Dec 2024

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc