Skip to content

Commit

Permalink
Add contextElement fields to virtual elements
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Aug 22, 2023
1 parent 1057add commit 7e43290
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ function BlockPopoverInbetween( {
return undefined;
}

const { ownerDocument } = previousElement || nextElement;
const contextElement = previousElement || nextElement;

return {
ownerDocument,
contextElement,
getBoundingClientRect() {
const previousRect = previousElement
? previousElement.getBoundingClientRect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function BlockPopover(

return new window.DOMRect( left, top, width, height );
},
ownerDocument: selectedElement.ownerDocument,
contextElement: selectedElement,
};
}, [
bottomClientId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,8 @@ export default function ListViewDropIndicator( {
return undefined;
}

const ownerDocument = targetElement.ownerDocument;

return {
ownerDocument,
contextElement: targetElement,
getBoundingClientRect() {
const rect = targetElement.getBoundingClientRect();
const indent = getDropIndicatorIndent( rect );
Expand All @@ -189,9 +187,10 @@ export default function ListViewDropIndicator( {
'horizontal'
);

const doc = targetElement.ownerDocument;
const windowScroll =
scrollContainer === ownerDocument.body ||
scrollContainer === ownerDocument.documentElement;
scrollContainer === doc.body ||
scrollContainer === doc.documentElement;

// If the scroll container is not the window, offset the left position, if need be.
if ( scrollContainer && ! windowScroll ) {
Expand Down
2 changes: 1 addition & 1 deletion packages/components/src/popover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ const UnforwardedPopover = (
}, [ referenceOwnerDocument, update ] );

const mergedFloatingRef = useMergeRefs( [
refs.floating,
refs.setFloating,
dialogRef,
forwardedRef,
] );
Expand Down
4 changes: 2 additions & 2 deletions packages/rich-text/src/component/use-anchor.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function getFormatElement( range, editableContentElement, tagName, className ) {
/**
* @typedef {Object} VirtualAnchorElement
* @property {() => DOMRect} getBoundingClientRect A function returning a DOMRect
* @property {Document} ownerDocument The element's ownerDocument
* @property {HTMLElement} contextElement The actual DOM element
*/

/**
Expand All @@ -64,7 +64,7 @@ function getFormatElement( range, editableContentElement, tagName, className ) {
*/
function createVirtualAnchorElement( range, editableContentElement ) {
return {
ownerDocument: range.startContainer.ownerDocument,
contextElement: editableContentElement,
getBoundingClientRect() {
return editableContentElement.contains( range.startContainer )
? range.getBoundingClientRect()
Expand Down

0 comments on commit 7e43290

Please sign in to comment.