Lexical: Do not display two toolbars at once

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2023-08-01 00:42:06 +02:00
parent f259f52b40
commit 43216e7d2a
5 changed files with 21 additions and 33 deletions

View file

@ -0,0 +1,11 @@
import { $createImageNode } from '../nodes/image-node';
import type { LexicalNode } from 'lexical';
import type { ImportHandler } from 'lexical-remark';
const importImage: ImportHandler<any> /* TODO */ = (node: LexicalNode, parser) => {
const lexicalNode = $createImageNode({ altText: node.alt ?? '', src: node.url });
parser.append(lexicalNode);
};
export { importImage };

View file

@ -148,15 +148,8 @@ const ImageComponent = ({
(event: KeyboardEvent) => {
const latestSelection = $getSelection();
const buttonElem = buttonRef.current;
if (
isSelected &&
$isNodeSelection(latestSelection) &&
latestSelection.getNodes().length === 1
) {
if (
buttonElem !== null &&
buttonElem !== document.activeElement
) {
if (isSelected && $isNodeSelection(latestSelection) && latestSelection.getNodes().length === 1) {
if (buttonElem !== null && buttonElem !== document.activeElement) {
event.preventDefault();
buttonElem.focus();
return true;

View file

@ -120,18 +120,12 @@ const getScrollParent = (
if (style.position === 'fixed') {
return document.body;
}
for (
let parent: HTMLElement | null = element;
(parent = parent.parentElement);
) {
for (let parent: HTMLElement | null = element; (parent = parent.parentElement);) {
style = getComputedStyle(parent);
if (excludeStaticParent && style.position === 'static') {
continue;
}
if (
overflowRegex.test(style.overflow + style.overflowY + style.overflowX)
) {
if (overflowRegex.test(style.overflow + style.overflowY + style.overflowX)) {
return parent;
}
}
@ -418,17 +412,16 @@ const AutosuggestPlugin = ({
editor.getEditorState().read(() => {
const range = document.createRange();
const match = getQueryTextForSearch(editor);
const nativeSelection = window.getSelection();
if (!match) {
if (!match || nativeSelection?.anchorOffset !== nativeSelection?.focusOffset) {
closeTypeahead();
return;
}
dispatch(fetchComposeSuggestions(composeId, match.matchingString.trim()));
if (
!isSelectionOnEntityBoundary(editor, match.leadOffset)
) {
if (!isSelectionOnEntityBoundary(editor, match.leadOffset)) {
const isRangePositioned = tryToPositionRange(match.leadOffset, range);
if (isRangePositioned !== null) {
startTransition(() =>

View file

@ -119,10 +119,7 @@ const BlockTypeDropdown = ({ editor, anchorElem, blockType, icon }: {
const formatParagraph = () => {
editor.update(() => {
const selection = $getSelection();
if (
$isRangeSelection(selection) ||
DEPRECATED_$isGridSelection(selection)
) {
if ($isRangeSelection(selection) || DEPRECATED_$isGridSelection(selection)) {
$setBlocksType(selection, () => $createParagraphNode());
}
});
@ -509,10 +506,7 @@ const useFloatingTextFormatToolbar = (
setIsLink(false);
}
if (
!$isCodeHighlightNode(selection.anchor.getNode()) &&
selection.getTextContent() !== ''
) {
if (!$isCodeHighlightNode(selection.anchor.getNode()) && selection.getTextContent() !== '') {
setIsText($isTextNode(node));
} else {
setIsText(false);

View file

@ -20,10 +20,7 @@ const FocusPlugin: React.FC<IFocusPlugin> = ({ autoFocus }) => {
() => {
const activeElement = document.activeElement;
const rootElement = editor.getRootElement();
if (
rootElement !== null &&
(activeElement === null || !rootElement.contains(activeElement))
) {
if (rootElement !== null && (activeElement === null || !rootElement.contains(activeElement))) {
rootElement.focus({ preventScroll: true });
}
}, { defaultSelection: 'rootEnd' },