Socket
Socket
Sign inDemoInstall

@lexical/react

Package Overview
Dependencies
18
Maintainers
7
Versions
92
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @lexical/react

This package provides Lexical components and hooks for React applications.


Version published
Weekly downloads
341K
decreased by-3.55%
Maintainers
7
Install size
3.26 MB
Created
Weekly downloads
 

Changelog

Source

v0.9.1 (2023-03-24)

  • Explicit E2E_BROWSER on E2E runs (#4179) Gerard Rovira
  • Fix tables Webkit e2e (#4175) Gerard Rovira
  • Remove unused convertToMarkdown file (#4169) themagickoala
  • Improve markdown transformers (#3886) Godefroy
  • Iterate through the live NodeList instead of copying to an array in $generateNodesFromDOM (#4164) Acy Watson
  • Bump Excalidraw to v0.14.2 (#4153) Ivaylo Pavlov
  • Fix table stealing selectionchange (#4162) Gerard Rovira
  • Improve Documentation #2845 - lexical/selection (#4140) Harry Sanders
  • UX: Floating link editor: better positioning (#4158) Alessio Gravili
  • DecoratorNode not disabling placeholder at root (#4147) Harry Sanders
  • Color picker - fixes #4127 (#4146) Harry Sanders
  • Validate against infinite loop in ListItemNode.setIndent (#4120) Acy Watson
  • Paste merged celled table (#4116) Gerard Rovira
  • Add md import/export tests, fix numbered lists pasting (#4123) Maksim Horbachevsky
  • Bump webpack from 5.75.0 to 5.76.0 (#4128) dependabot[bot]
  • fix: drag-over event on windows (#4125) 子瞻 Luci
  • Remove link preview (#4122) John Flockton
  • Add a function to create a LinkMatcher based on a RegExp (#3972) Karibash
  • Revise padding for smaller res (#4112) Gerard Rovira
  • Catch failures in parseEditorState (#4109) Acy Watson
  • Improve Documentation #2845 - lexical/list (#4107) Harry Sanders
  • Fix tables Collab E2E (#4117) Gerard Rovira
  • Fix ShadowRoot + X insertNode (#4115) Gerard Rovira
  • Overflow of logos of action items in Lexical Playground (#4096) 7gaurab_khanal
  • Remove columns w/ span support (#4093) Gerard Rovira
  • Remove rows w/ span support (#4078) Gerard Rovira
  • Table insert column w/ span support (#4074) Gerard Rovira
  • Table insert row w/ span support (#4063) Gerard Rovira
  • Use broader return types in HorizontalRuleNode (#4097) Chris Montrois
  • Add focus tag to editor.focus (#4092) Dragoș Străinu
  • Improve Documentation #2845 - lexical/utils (#4047) Harry Sanders
  • Fix toolbars that shouldn't appear in certain cases (#4077) Warren19
  • Fixed reference to old addUpdateListener method in transforms doc (#4094) Kevin Ansfield
  • Pass tags to onChange for LexicalOnChangePlugin (#4091) Dragoș Străinu
  • Fix tables E2E (#4090) John Flockton
  • Change default indent to 40px (#4025) EgonBolton
  • Update CODEOWNERS (#4089) John Flockton
  • Updated InsertTableDialog UX (#4082) Brandon
  • Export getNearestEditorFromDOMNode (#4079) Gerard Rovira
  • Fix unresponsive resize handle in Safari (#4081) Brandon
  • Sticky toolbar to assist in editing large content (#4076) Brandon
  • Fix table RangeSelection test (#4061) Gerard Rovira
  • Trim table e2e assert (#4060) Gerard Rovira

Readme

Source

@lexical/react

This package provides a set of components and hooks for Lexical that allow for text editing in React applications.

Getting started

Install lexical and @lexical/react:

npm install --save lexical @lexical/react

Below is an example of a basic plain text editor using lexical and @lexical/react (try it yourself).

import {$getRoot, $getSelection} from 'lexical';
import {useEffect} from 'react';

import {LexicalComposer} from '@lexical/react/LexicalComposer';
import {PlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
import {ContentEditable} from '@lexical/react/LexicalContentEditable';
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
import {OnChangePlugin} from '@lexical/react/LexicalOnChangePlugin';
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';

const theme = {
  // Theme styling goes here
  ...
}

// When the editor changes, you can get notified via the
// LexicalOnChangePlugin!
function onChange(editorState) {
  editorState.read(() => {
    // Read the contents of the EditorState here.
    const root = $getRoot();
    const selection = $getSelection();

    console.log(root, selection);
  });
}

// Lexical React plugins are React components, which makes them
// highly composable. Furthermore, you can lazy load plugins if
// desired, so you don't pay the cost for plugins until you
// actually use them.
function MyCustomAutoFocusPlugin() {
  const [editor] = useLexicalComposerContext();

  

useEffect(() => {
    // Focus the editor when the effect fires!
    editor.focus();
  }, [editor]);

  return null;
}

// Catch any errors that occur during Lexical updates and log them
// or throw them as needed. If you don't throw them, Lexical will
// try to recover gracefully without losing user data.
function onError(error) {
  throw error;
}

function Editor() {
  const initialConfig = {
    namespace: 'MyEditor',
    theme,
    onError,
  };

return (
    <LexicalComposer initialConfig={initialConfig}>
      <PlainTextPlugin
        contentEditable={<ContentEditable />}
        placeholder={<div>Enter some text...</div>}
      />
      <OnChangePlugin onChange={onChange} />
      <HistoryPlugin />
      <MyCustomAutoFocusPlugin />
    </LexicalComposer>
  );
}

Keywords

FAQs

Last updated on 24 Mar 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc