chore: Update Lexical to 0.7.5 (#2117)

This commit is contained in:
Aman Harwara
2022-12-23 22:22:19 +05:30
committed by GitHub
parent 1ec173dcd6
commit 2f3bc9b85b
43 changed files with 217 additions and 164 deletions

View File

@@ -21,6 +21,7 @@ import DraggableBlockPlugin from '../Lexical/Plugins/DraggableBlockPlugin';
import CodeHighlightPlugin from '../Lexical/Plugins/CodeHighlightPlugin';
import FloatingTextFormatToolbarPlugin from '../Lexical/Plugins/FloatingTextFormatToolbarPlugin';
import FloatingLinkEditorPlugin from '../Lexical/Plugins/FloatingLinkEditorPlugin';
import {TabIndentationPlugin} from '../Lexical/Plugins/TabIndentationPlugin';
import {truncateString} from './Utils';
import {SuperEditorContentId} from './Constants';
import {classNames} from '@standardnotes/utils';
@@ -107,7 +108,7 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
</div>
</div>
}
placeholder=""
placeholder={null}
ErrorBoundary={LexicalErrorBoundary}
/>
<ListPlugin />
@@ -125,6 +126,7 @@ export const BlocksEditor: FunctionComponent<BlocksEditorProps> = ({
<TwitterPlugin />
<YouTubePlugin />
<CollapsiblePlugin />
<TabIndentationPlugin />
{!readonly && floatingAnchorElem && (
<>
<FloatingTextFormatToolbarPlugin anchorElem={floatingAnchorElem} />

View File

@@ -192,9 +192,10 @@ export function AutoEmbedDialog({
const embedResult =
text != null && urlMatch != null ? embedConfig.parseUrl(text) : null;
const onClick = () => {
if (embedResult != null) {
embedConfig.insertNode(editor, embedResult);
const onClick = async () => {
const result = await embedResult;
if (result != null) {
embedConfig.insertNode(editor, result);
onClose();
}
};

View File

@@ -12,6 +12,7 @@ import {mergeRegister} from '@lexical/utils';
import {
$getNearestNodeFromDOMNode,
$getNodeByKey,
$getRoot,
COMMAND_PRIORITY_HIGH,
COMMAND_PRIORITY_LOW,
DRAGOVER_COMMAND,
@@ -58,8 +59,7 @@ function getCurrentIndex(keysLength: number): number {
}
function getTopLevelNodeKeys(editor: LexicalEditor): string[] {
const root = editor.getEditorState()._nodeMap.get('root');
return root ? root.__children : [];
return editor.getEditorState().read(() => $getRoot().getChildrenKeys());
}
function elementContainingEventLocation(

View File

@@ -0,0 +1,50 @@
/**
* 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.
*
*/
import {useLexicalComposerContext} from '@lexical/react/LexicalComposerContext';
import {
$getSelection,
$isRangeSelection,
COMMAND_PRIORITY_EDITOR,
INDENT_CONTENT_COMMAND,
KEY_TAB_COMMAND,
OUTDENT_CONTENT_COMMAND,
} from 'lexical';
import {useEffect} from 'react';
/**
* This plugin adds the ability to indent content using the tab key. Generally, we don't
* recommend using this plugin as it could negatively affect acessibility for keyboard
* users, causing focus to become trapped within the editor.
*/
export function TabIndentationPlugin(): null {
const [editor] = useLexicalComposerContext();
useEffect(() => {
return editor.registerCommand<KeyboardEvent>(
KEY_TAB_COMMAND,
(event) => {
const selection = $getSelection();
if (!$isRangeSelection(selection)) {
return false;
}
event.preventDefault();
return editor.dispatchCommand(
event.shiftKey ? OUTDENT_CONTENT_COMMAND : INDENT_CONTENT_COMMAND,
undefined,
);
},
COMMAND_PRIORITY_EDITOR,
);
});
return null;
}