@lexical/react
Version:
This package provides Lexical components and hooks for React applications.
58 lines (50 loc) • 1.6 kB
JavaScript
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
;
var list = require('@lexical/list');
var LexicalComposerContext = require('@lexical/react/LexicalComposerContext');
var lexical = require('lexical');
var react = require('react');
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
function useList(editor) {
react.useEffect(() => {
return list.registerList(editor);
}, [editor]);
}
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
function ListPlugin({
hasStrictIndent = false,
shouldPreserveNumbering = false
}) {
const [editor] = LexicalComposerContext.useLexicalComposerContext();
react.useEffect(() => {
if (!editor.hasNodes([list.ListNode, list.ListItemNode])) {
throw new Error('ListPlugin: ListNode and/or ListItemNode not registered on editor');
}
}, [editor]);
react.useEffect(() => {
return lexical.mergeRegister(list.registerList(editor, {
restoreNumbering: shouldPreserveNumbering
}), hasStrictIndent ? list.registerListStrictIndentTransform(editor) : () => {});
}, [editor, hasStrictIndent, shouldPreserveNumbering]);
useList(editor);
return null;
}
exports.ListPlugin = ListPlugin;