Skip to content

Commit

Permalink
fixed hovered component and drag leave
Browse files Browse the repository at this point in the history
  • Loading branch information
LiveDuo committed Mar 27, 2024
1 parent 303e23a commit ee00019
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/client/vanilla/editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -304,14 +304,15 @@ function Editor({ standaloneServer = false }) {
const onCanvasDragOver = (e: React.MouseEvent<HTMLElement>) => {
e.preventDefault()

// get hovered component
const components = getComponents()
const component = components.find((c) => isEventOnElement(c, e))!

// update empty flag
const components = getComponents()
const isEmpty = components.length === 0
if (isEmpty !== isEmptyCanvas) setIsEmptyCanvas(isEmpty)
if (!component) return

// get hovered component
if (components.length === 0) return
const componentWithEvent = components.find((c) => isEventOnElement(c, e))!
const component = componentWithEvent ?? components[components.length - 1]

// update border
const isTopHalf = isElementTopHalf(component, e)
Expand All @@ -334,7 +335,7 @@ function Editor({ standaloneServer = false }) {
}

const onCanvasDragLeave = (e: React.DragEvent<HTMLElement>) => {
if (!canvasRef.current?.contains(e.target as HTMLElement)) {
if (!canvasRef.current?.contains(e.relatedTarget as HTMLElement)) {
setHoveredComponent(null)
removeBorders()
}
Expand Down

0 comments on commit ee00019

Please sign in to comment.