chore: fix super block dragging indicator line not disappearing correctly (#2866) [skip e2e]

This commit is contained in:
Aman Harwara
2024-04-04 16:53:02 +05:30
committed by GitHub
parent c6a31f209d
commit ef81e9d97e

View File

@@ -16,6 +16,7 @@ import {
COMMAND_PRIORITY_HIGH, COMMAND_PRIORITY_HIGH,
COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_LOW,
DRAGOVER_COMMAND, DRAGOVER_COMMAND,
DRAGEND_COMMAND,
DROP_COMMAND, DROP_COMMAND,
LexicalEditor, LexicalEditor,
LexicalNode, LexicalNode,
@@ -32,6 +33,7 @@ const DRAGGABLE_BLOCK_MENU_LEFT_SPACE = -2
const TARGET_LINE_HALF_HEIGHT = 2 const TARGET_LINE_HALF_HEIGHT = 2
const DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu' const DRAGGABLE_BLOCK_MENU_CLASSNAME = 'draggable-block-menu'
const DRAG_DATA_FORMAT = 'application/x-lexical-drag-block' const DRAG_DATA_FORMAT = 'application/x-lexical-drag-block'
let draggedNodeKey = ''
const TEXT_BOX_HORIZONTAL_PADDING = 24 const TEXT_BOX_HORIZONTAL_PADDING = 24
const Downward = 1 const Downward = 1
@@ -283,6 +285,9 @@ function useDraggableBlockMenu(editor: LexicalEditor, anchorElem: HTMLElement, i
if (!isHTMLElement(target)) { if (!isHTMLElement(target)) {
return false return false
} }
if (!draggedNodeKey) {
return false
}
const targetBlockElem = getBlockElement(anchorElem, editor, new Point(event.pageX, pageY)) const targetBlockElem = getBlockElement(anchorElem, editor, new Point(event.pageX, pageY))
const targetLineElem = targetLineRef.current const targetLineElem = targetLineRef.current
if (targetBlockElem === null || targetLineElem === null) { if (targetBlockElem === null || targetLineElem === null) {
@@ -331,6 +336,12 @@ function useDraggableBlockMenu(editor: LexicalEditor, anchorElem: HTMLElement, i
return true return true
} }
function onDragEnd(): boolean {
hideTargetLine(targetLineRef.current)
draggedNodeKey = ''
return true
}
return mergeRegister( return mergeRegister(
editor.registerCommand( editor.registerCommand(
DRAGOVER_COMMAND, DRAGOVER_COMMAND,
@@ -339,6 +350,13 @@ function useDraggableBlockMenu(editor: LexicalEditor, anchorElem: HTMLElement, i
}, },
COMMAND_PRIORITY_LOW, COMMAND_PRIORITY_LOW,
), ),
editor.registerCommand(
DRAGEND_COMMAND,
() => {
return onDragEnd()
},
COMMAND_PRIORITY_LOW,
),
editor.registerCommand( editor.registerCommand(
DROP_COMMAND, DROP_COMMAND,
(event) => { (event) => {
@@ -363,10 +381,12 @@ function useDraggableBlockMenu(editor: LexicalEditor, anchorElem: HTMLElement, i
} }
}) })
dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey) dataTransfer.setData(DRAG_DATA_FORMAT, nodeKey)
draggedNodeKey = nodeKey
} }
function onDragEnd(): void { function onDragEnd(): void {
hideTargetLine(targetLineRef.current) hideTargetLine(targetLineRef.current)
draggedNodeKey = ''
} }
function onTouchStart(): void { function onTouchStart(): void {