0.13.4-next.12 • Published 1 month ago

@emailsenderlab/headless v0.13.4-next.12

Weekly downloads
-
License
MIT
Repository
github
Last release
1 month ago

@lexical/headless

This package allows you to interact with Lexical in a headless environment (one that does not rely on DOM, e.g. for Node.js environment), and use its main features like editor.update(), editor.registerNodeTransform(), editor.registerUpdateListener() to create, update or traverse state.

Install @lexical/headless:

npm install --save @lexical/headless
const { createHeadlessEditor } = require('@lexical/headless');

const editor = createHeadlessEditor({
  nodes: [],
  onError: () => {},
});

editor.update(() => {
  $getRoot().append(
    $createParagraphNode().append(
      $createTextNode('Hello world')
    )
  )
});

Any plugins that do not rely on DOM could also be used. Here's an example of how you can convert lexical editor state to markdown on server:

const { createHeadlessEditor } = require('@lexical/headless');
const { $convertToMarkdownString, TRANSFORMERS } = require('@lexical/markdown');

app.get('article/:id/markdown', await (req, res) => {
  const editor = createHeadlessEditor({
    nodes: [],
    onError: () => {},
  });

  const articleEditorStateJSON = await loadArticleBody(req.query.id);
  editor.setEditorState(editor.parseEditorState(articleEditorStateJSON));  

  editor.update(() => {
    const markdown = $convertToMarkdownString(TRANSFORMERS);
    res.send(markdown);
  });
});
0.13.4-next.12

1 month ago

0.13.4-next.11

1 month ago

0.13.4-next.10

2 months ago

0.13.4-next.9

2 months ago

0.13.4-next.8

2 months ago

0.13.4-next.5

3 months ago

0.13.4-next.7

2 months ago

0.13.4-next.6

3 months ago

0.13.4-next.4

3 months ago

0.13.4-next.1

3 months ago

0.13.4-next.0

3 months ago

0.13.4-next.3

3 months ago

0.13.4-next.2

3 months ago

0.13.3

3 months ago

0.13.2-next.1

3 months ago

0.13.2-next.0

3 months ago

0.0.4-next.0

6 months ago

0.12.3-next.0

6 months ago