Lexical: Added table creator UI

This commit is contained in:
Dan Brown
2024-06-21 16:18:44 +01:00
parent f47f7dd9d2
commit ac01c62e6e
5 changed files with 119 additions and 5 deletions

View File

@ -1,13 +1,14 @@
import {
$createParagraphNode,
$createParagraphNode, $getRoot,
$getSelection,
$isTextNode,
BaseSelection,
BaseSelection, ElementNode,
LexicalEditor, LexicalNode, TextFormatType
} from "lexical";
import {LexicalElementNodeCreator, LexicalNodeMatcher} from "./nodes";
import {$getNearestBlockElementAncestorOrThrow} from "@lexical/utils";
import {$setBlocksType} from "@lexical/selection";
import {$createDetailsNode} from "./nodes/details";
export function el(tag: string, attrs: Record<string, string|null> = {}, children: (string|HTMLElement)[] = []): HTMLElement {
const el = document.createElement(tag);
@ -77,4 +78,15 @@ export function toggleSelectionBlockNodeType(editor: LexicalEditor, matcher: Lex
$setBlocksType(selection, creator);
}
});
}
export function insertNewBlockNodeAtSelection(node: LexicalNode) {
const selection = $getSelection();
const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null;
if (blockElement) {
blockElement.insertAfter(node);
} else {
$getRoot().append(node);
}
}