mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-06-24 22:51:23 +08:00
Lexical: Added a range of format buttons
This commit is contained in:
@ -1,7 +1,15 @@
|
||||
import {$createParagraphNode, $getSelection, BaseSelection, LexicalEditor} from "lexical";
|
||||
import {
|
||||
$createParagraphNode,
|
||||
$getSelection,
|
||||
$isTextNode,
|
||||
BaseSelection,
|
||||
ElementFormatType,
|
||||
LexicalEditor, TextFormatType
|
||||
} from "lexical";
|
||||
import {LexicalElementNodeCreator, LexicalNodeMatcher} from "./nodes";
|
||||
import {$getNearestBlockElementAncestorOrThrow} from "@lexical/utils";
|
||||
import {$setBlocksType} from "@lexical/selection";
|
||||
import {TextNodeThemeClasses} from "lexical/LexicalEditor";
|
||||
|
||||
export function selectionContainsNodeType(selection: BaseSelection|null, matcher: LexicalNodeMatcher): boolean {
|
||||
if (!selection) {
|
||||
@ -23,6 +31,20 @@ export function selectionContainsNodeType(selection: BaseSelection|null, matcher
|
||||
return false;
|
||||
}
|
||||
|
||||
export function selectionContainsTextFormat(selection: BaseSelection|null, format: TextFormatType): boolean {
|
||||
if (!selection) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const node of selection.getNodes()) {
|
||||
if ($isTextNode(node) && node.hasFormat(format)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
export function toggleSelectionBlockNodeType(editor: LexicalEditor, matcher: LexicalNodeMatcher, creator: LexicalElementNodeCreator) {
|
||||
editor.update(() => {
|
||||
const selection = $getSelection();
|
||||
|
Reference in New Issue
Block a user