1 import {$createParagraphNode, $getSelection, BaseSelection, LexicalEditor} from "lexical";
2 import {LexicalElementNodeCreator, LexicalNodeMatcher} from "./nodes";
3 import {$getNearestBlockElementAncestorOrThrow} from "@lexical/utils";
4 import {$setBlocksType} from "@lexical/selection";
6 export function selectionContainsNodeType(selection: BaseSelection|null, matcher: LexicalNodeMatcher): boolean {
11 for (const node of selection.getNodes()) {
16 for (const parent of node.getParents()) {
17 if (matcher(parent)) {
26 export function toggleSelectionBlockNodeType(editor: LexicalEditor, matcher: LexicalNodeMatcher, creator: LexicalElementNodeCreator) {
28 const selection = $getSelection();
29 const blockElement = selection ? $getNearestBlockElementAncestorOrThrow(selection.getNodes()[0]) : null;
30 if (selection && matcher(blockElement)) {
31 $setBlocksType(selection, $createParagraphNode);
33 $setBlocksType(selection, creator);