mirror of
https://github.com/outline/outline.git
synced 2026-11-27 16:08:58 +03:00
In Firefox, a mousedown in the editor can have a Text node as its target. The Mermaid plugin cast the target to HTMLElement and called closest(), which threw and stopped ProseMirror from handling the event. Resolve the target to its element (or parent element) before calling element methods. Sentry: OUTLINE-CLOUD-DFP Claude-Session: https://claude.ai/code/session_016MJXFcsyhupagpKC181rqW Co-authored-by: Claude <noreply@anthropic.com>
36 lines
1.3 KiB
TypeScript
36 lines
1.3 KiB
TypeScript
import { getEventTargetElement } from "./eventTarget";
|
|
|
|
describe.runIf(typeof document !== "undefined")("getEventTargetElement", () => {
|
|
it("returns the element when the target is an element", () => {
|
|
const element = document.createElement("div");
|
|
const event = new MouseEvent("mousedown");
|
|
Object.defineProperty(event, "target", { value: element });
|
|
|
|
expect(getEventTargetElement(event)).toBe(element);
|
|
});
|
|
|
|
it("returns the parent element when the target is a text node", () => {
|
|
const element = document.createElement("span");
|
|
const text = document.createTextNode("diagram label");
|
|
element.appendChild(text);
|
|
const event = new MouseEvent("mousedown");
|
|
Object.defineProperty(event, "target", { value: text });
|
|
|
|
const result = getEventTargetElement(event);
|
|
expect(result).toBe(element);
|
|
expect(result?.closest("span")).toBe(element);
|
|
});
|
|
|
|
it("returns null when the text node has no parent", () => {
|
|
const text = document.createTextNode("detached");
|
|
const event = new MouseEvent("mousedown");
|
|
Object.defineProperty(event, "target", { value: text });
|
|
|
|
expect(getEventTargetElement(event)).toBeNull();
|
|
});
|
|
|
|
it("returns null when the event has no target", () => {
|
|
expect(getEventTargetElement(new MouseEvent("mousedown"))).toBeNull();
|
|
});
|
|
});
|