-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix drag and drop indicator above first block and RTL drop indicators #33024
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,86 +79,101 @@ function InsertionPointPopover( { | |
}, [] ); | ||
const previousElement = useBlockElement( previousClientId ); | ||
const nextElement = useBlockElement( nextClientId ); | ||
|
||
const style = useMemo( () => { | ||
if ( ! previousElement ) { | ||
if ( ! previousElement && ! nextElement ) { | ||
return {}; | ||
} | ||
const previousRect = previousElement.getBoundingClientRect(); | ||
|
||
const previousRect = previousElement | ||
? previousElement.getBoundingClientRect() | ||
: null; | ||
const nextRect = nextElement | ||
? nextElement.getBoundingClientRect() | ||
: null; | ||
|
||
if ( orientation === 'vertical' ) { | ||
return { | ||
width: previousElement.offsetWidth, | ||
height: nextRect ? nextRect.top - previousRect.bottom : 0, | ||
width: previousElement | ||
? previousElement.offsetWidth | ||
: nextElement.offsetWidth, | ||
height: | ||
nextRect && previousRect | ||
? nextRect.top - previousRect.bottom | ||
: 0, | ||
}; | ||
} | ||
|
||
let width = 0; | ||
if ( nextElement ) { | ||
if ( previousRect && nextRect ) { | ||
width = isRTL() | ||
? previousRect.left - nextRect.right | ||
: nextRect.left - previousRect.right; | ||
} | ||
|
||
return { | ||
width, | ||
height: previousElement.offsetHeight, | ||
height: previousElement | ||
? previousElement.offsetHeight | ||
: nextElement.offsetHeight, | ||
}; | ||
}, [ previousElement, nextElement ] ); | ||
|
||
const getAnchorRect = useCallback( () => { | ||
const { ownerDocument } = previousElement; | ||
const previousRect = previousElement.getBoundingClientRect(); | ||
if ( ! previousElement && ! nextElement ) { | ||
return {}; | ||
} | ||
|
||
const { ownerDocument } = previousElement || nextElement; | ||
|
||
const previousRect = previousElement | ||
? previousElement.getBoundingClientRect() | ||
: null; | ||
const nextRect = nextElement | ||
? nextElement.getBoundingClientRect() | ||
: null; | ||
|
||
if ( orientation === 'vertical' ) { | ||
if ( isRTL() ) { | ||
return { | ||
top: previousRect.bottom, | ||
left: previousRect.right, | ||
right: previousRect.left, | ||
top: previousRect ? previousRect.bottom : nextRect.top, | ||
left: previousRect ? previousRect.right : nextRect.right, | ||
right: previousRect ? previousRect.left : nextRect.left, | ||
bottom: nextRect ? nextRect.top : previousRect.bottom, | ||
ownerDocument, | ||
}; | ||
} | ||
|
||
return { | ||
top: previousRect.bottom, | ||
left: previousRect.left, | ||
right: previousRect.right, | ||
top: previousRect ? previousRect.bottom : nextRect.top, | ||
left: previousRect ? previousRect.left : nextRect.left, | ||
right: previousRect ? previousRect.right : nextRect.right, | ||
bottom: nextRect ? nextRect.top : previousRect.bottom, | ||
ownerDocument, | ||
}; | ||
Comment on lines
138
to
153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This works pretty well but it got quite repetitive. How about something like:
Or perhaps even:
Or even:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Anyway that's just a note about code style, feel free to decide to keep the current one or use one of the ideas above. I'm approving this PR regardless. |
||
} | ||
|
||
if ( isRTL() ) { | ||
return { | ||
top: previousRect.top, | ||
left: nextRect ? nextRect.right : previousRect.left, | ||
right: previousRect.left, | ||
bottom: previousRect.bottom, | ||
top: previousRect ? previousRect.top : nextRect.top, | ||
left: previousRect ? previousRect.left : nextRect.right, | ||
right: nextRect ? nextRect.right : previousRect.left, | ||
bottom: previousRect ? previousRect.bottom : nextRect.bottom, | ||
ownerDocument, | ||
}; | ||
} | ||
|
||
return { | ||
top: previousRect.top, | ||
left: previousRect.right, | ||
top: previousRect ? previousRect.top : nextRect.top, | ||
left: previousRect ? previousRect.right : nextRect.left, | ||
right: nextRect ? nextRect.left : previousRect.right, | ||
bottom: previousRect.bottom, | ||
bottom: previousRect ? previousRect.bottom : nextRect.bottom, | ||
ownerDocument, | ||
}; | ||
}, [ previousElement, nextElement ] ); | ||
|
||
const popoverScrollRef = usePopoverScroll( __unstableContentRef ); | ||
|
||
if ( ! previousElement ) { | ||
return null; | ||
} | ||
|
||
const className = classnames( | ||
'block-editor-block-list__insertion-point', | ||
'is-' + orientation | ||
|
@@ -178,10 +193,10 @@ function InsertionPointPopover( { | |
} | ||
} | ||
|
||
// Only show the inserter when there's a `nextElement` (a block after the | ||
// insertion point). At the end of the block list the trailing appender | ||
// should serve the purpose of inserting blocks. | ||
const showInsertionPointInserter = nextElement && isInserterShown; | ||
// Only show the in-between inserter between blocks, so when there's a | ||
// previous and a next element. | ||
const showInsertionPointInserter = | ||
previousElement && nextElement && isInserterShown; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
/* eslint-disable jsx-a11y/no-static-element-interactions, jsx-a11y/click-events-have-key-events */ | ||
// While ideally it would be enough to capture the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wp-block
was added here in #25849, but I don't think it should be here. Everything still works without it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it should be a mistake 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shouldn't it be there? Won't it give correct margins to the appender?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't seem to make a difference from what I can tell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make a difference, we should restore it, without it, the block appender won't be considered a "block" meaning it won't be aligned properly in a block list.
For instance you can test this by adding an image block and notice that the appender that shows after the image is not centered properly.