What is @lexical/utils?
@lexical/utils is a utility package for the Lexical framework, which is a modern, extensible text editor framework. This package provides various utility functions to facilitate the manipulation and management of Lexical nodes, editors, and other related components.
What are @lexical/utils's main functionalities?
Node Manipulation
This feature allows you to create and manipulate nodes within the Lexical editor. In this example, a text node is created and appended to the root node.
const { $createTextNode, $getRoot } = require('@lexical/utils');
const root = $getRoot();
const textNode = $createTextNode('Hello, world!');
root.append(textNode);
Editor State Management
This feature provides functions to get and set the editor state, allowing for more controlled and dynamic updates to the editor's content.
const { $getEditorState, $setEditorState } = require('@lexical/utils');
const editorState = $getEditorState();
// Modify the editor state as needed
$setEditorState(editorState);
Event Handling
This feature allows you to add and remove event listeners to the Lexical editor, enabling custom event handling and interaction.
const { $addEventListener, $removeEventListener } = require('@lexical/utils');
const handleClick = (event) => {
console.log('Editor clicked!', event);
};
$addEventListener('click', handleClick);
// Later, if needed
$removeEventListener('click', handleClick);
Other packages similar to @lexical/utils
draft-js
Draft.js is a rich text editor framework for React. It provides a set of tools for building complex text editors with features like text formatting, media embedding, and more. Compared to @lexical/utils, Draft.js offers a more comprehensive set of features for building rich text editors but may be more complex to use.
slate
Slate is another framework for building rich text editors in React. It is highly customizable and provides a lot of flexibility in terms of editor behavior and appearance. Slate is similar to @lexical/utils in that it offers utilities for managing editor state and nodes, but it is generally more flexible and powerful.
prosemirror
ProseMirror is a toolkit for building rich text editors with a focus on extensibility and performance. It provides a robust set of tools for manipulating document structures and handling complex editor interactions. ProseMirror is more feature-rich and versatile compared to @lexical/utils, but it also comes with a steeper learning curve.
v0.8.0 (2023-02-09)
This release includes some breaking changes, including:
- Remove of indentList
and outdentList
from @lexical/list
.
- Refactor of the LexicalContentEditable
types from @lexical/react
to make them more accurate with HTMLDivElement
attributes.
This release adds functionality to apply node transforms to node replacements, it allows users to specify tab indentation sizes, and improved support for tracking the origin of YJS updates for collaborative editing.
- Ensure deletions capture existing formatting (#3867) Dominic Gannaway
- Add style properties to RangeSelection (#3863) Dominic Gannaway
- List indentation simplified (#3809) EgonBolton
- Update ContentEditable types (#3580) John Flockton
- Allow the format property to be omitted (#3812) Karibash
- Allow users to customise the indentation of tabs (#3802) John Flockton
- Apply node transform not only to the original node but also to the overriding node (#3639) mizuno
- feat: set the update tag from yjs based on the origin (#3608) El-Hussein Abdelraouf