1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-01-03 23:42:28 +03:00

Lexical: Added basic URL field header option list

May show bad option label names on chrome/safari.
This was an easy first pass without loads of extra custom UI since we're
using native datalists.
This commit is contained in:
Dan Brown
2024-08-16 12:29:40 +01:00
parent 1ef4044419
commit ad6b26ba97
7 changed files with 135 additions and 10 deletions

View File

@@ -1,4 +1,4 @@
import {$getRoot, $isTextNode, LexicalEditor, LexicalNode} from "lexical";
import {$getRoot, $isElementNode, $isTextNode, ElementNode, LexicalEditor, LexicalNode} from "lexical";
import {LexicalNodeMatcher} from "../nodes";
import {$createCustomParagraphNode} from "../nodes/custom-paragraph";
import {$generateNodesFromDOM} from "@lexical/html";
@@ -31,6 +31,26 @@ export function $getParentOfType(node: LexicalNode, matcher: LexicalNodeMatcher)
return null;
}
export function $getAllNodesOfType(matcher: LexicalNodeMatcher, root?: ElementNode): LexicalNode[] {
if (!root) {
root = $getRoot();
}
const matches = [];
for (const child of root.getChildren()) {
if (matcher(child)) {
matches.push(child);
}
if ($isElementNode(child)) {
matches.push(...$getAllNodesOfType(matcher, child));
}
}
return matches;
}
/**
* Get the nearest root/block level node for the given position.
*/