1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-07-30 04:23:11 +03:00

Lexical: Updated URL handling, added mouse handling

- Removed URL protocol allow-list to allow any as per old editor.
- Added mouse handling, so that clicks below many last hard-to-escape
  block types will add an empty new paragraph for easy escaping &
  editing.
This commit is contained in:
Dan Brown
2025-07-25 13:58:48 +01:00
parent 865e5aecc9
commit c54101c603
5 changed files with 133 additions and 22 deletions

View File

@ -0,0 +1,51 @@
import {
createTestContext, destroyFromContext, dispatchEditorMouseClick,
} from "lexical/__tests__/utils";
import {
$getRoot, LexicalEditor, LexicalNode,
ParagraphNode,
} from "lexical";
import {registerRichText} from "@lexical/rich-text";
import {EditorUiContext} from "../../ui/framework/core";
import {registerMouseHandling} from "../mouse-handling";
import {$createTableNode, TableNode} from "@lexical/table";
describe('Mouse-handling service tests', () => {
let context!: EditorUiContext;
let editor!: LexicalEditor;
beforeEach(() => {
context = createTestContext();
editor = context.editor;
registerRichText(editor);
registerMouseHandling(context);
});
afterEach(() => {
destroyFromContext(context);
});
test('Click below last table inserts new empty paragraph', () => {
let tableNode!: TableNode;
let lastRootChild!: LexicalNode|null;
editor.updateAndCommit(() => {
tableNode = $createTableNode();
$getRoot().append(tableNode);
lastRootChild = $getRoot().getLastChild();
});
expect(lastRootChild).toBeInstanceOf(TableNode);
const tableDOM = editor.getElementByKey(tableNode.getKey());
const rect = tableDOM?.getBoundingClientRect();
dispatchEditorMouseClick(editor, 0, (rect?.bottom || 0) + 1)
editor.getEditorState().read(() => {
lastRootChild = $getRoot().getLastChild();
});
expect(lastRootChild).toBeInstanceOf(ParagraphNode);
});
});