JSPM

@lexical/react

0.3.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1269011
  • Score
    100M100P100Q182335F
  • License MIT

This package provides Lexical components and hooks for React applications.

Package Exports

  • @lexical/react/LexicalAutoFocusPlugin
  • @lexical/react/LexicalAutoFocusPlugin.js
  • @lexical/react/LexicalAutoLinkPlugin
  • @lexical/react/LexicalAutoLinkPlugin.js
  • @lexical/react/LexicalAutoScrollPlugin
  • @lexical/react/LexicalAutoScrollPlugin.js
  • @lexical/react/LexicalBlockWithAlignableContents
  • @lexical/react/LexicalBlockWithAlignableContents.js
  • @lexical/react/LexicalCheckListPlugin
  • @lexical/react/LexicalCheckListPlugin.js
  • @lexical/react/LexicalClearEditorPlugin
  • @lexical/react/LexicalClearEditorPlugin.js
  • @lexical/react/LexicalCollaborationPlugin
  • @lexical/react/LexicalCollaborationPlugin.js
  • @lexical/react/LexicalComposer
  • @lexical/react/LexicalComposer.js
  • @lexical/react/LexicalComposerContext
  • @lexical/react/LexicalComposerContext.js
  • @lexical/react/LexicalContentEditable
  • @lexical/react/LexicalContentEditable.js
  • @lexical/react/LexicalDecoratorBlockNode
  • @lexical/react/LexicalDecoratorBlockNode.js
  • @lexical/react/LexicalHashtagPlugin
  • @lexical/react/LexicalHashtagPlugin.js
  • @lexical/react/LexicalHistoryPlugin
  • @lexical/react/LexicalHistoryPlugin.js
  • @lexical/react/LexicalHorizontalRuleNode
  • @lexical/react/LexicalHorizontalRuleNode.js
  • @lexical/react/LexicalLinkPlugin
  • @lexical/react/LexicalLinkPlugin.js
  • @lexical/react/LexicalListPlugin
  • @lexical/react/LexicalListPlugin.js
  • @lexical/react/LexicalMarkdownShortcutPlugin
  • @lexical/react/LexicalMarkdownShortcutPlugin.js
  • @lexical/react/LexicalNestedComposer
  • @lexical/react/LexicalNestedComposer.js
  • @lexical/react/LexicalOnChangePlugin
  • @lexical/react/LexicalOnChangePlugin.js
  • @lexical/react/LexicalPlainTextPlugin
  • @lexical/react/LexicalPlainTextPlugin.js
  • @lexical/react/LexicalRichTextPlugin
  • @lexical/react/LexicalRichTextPlugin.js
  • @lexical/react/LexicalTablePlugin
  • @lexical/react/LexicalTablePlugin.js
  • @lexical/react/LexicalTreeView
  • @lexical/react/LexicalTreeView.js
  • @lexical/react/useLexicalNodeSelection
  • @lexical/react/useLexicalNodeSelection.js
  • @lexical/react/useLexicalTextEntity
  • @lexical/react/useLexicalTextEntity.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@lexical/react) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

@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 {LexicalPlainTextPlugin} from '@lexical/react/LexicalPlainTextPlugin';
import {LexicalContentEditable} from '@lexical/react/LexicalContentEditable';
import {HistoryPlugin} from '@lexical/react/LexicalHistoryPlugin';
import {LexicalOnChangePlugin} 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 = {
    theme,
    onError,
  };

  

return (
    <LexicalComposer initialConfig={initialConfig}>
      <LexicalPlainTextPlugin
        contentEditable={<LexicalContentEditable />}
        placeholder={<div>Enter some text...</div>}
      />
      <LexicalOnChangePlugin onChange={onChange} />
      <HistoryPlugin />
      <MyCustomAutoFocusPlugin />
    </LexicalComposer>
  );
}