diff --git a/packages/block-editor/src/components/writing-flow/index.js b/packages/block-editor/src/components/writing-flow/index.js index d03b11d0a84f7a..951df53592ae33 100644 --- a/packages/block-editor/src/components/writing-flow/index.js +++ b/packages/block-editor/src/components/writing-flow/index.js @@ -284,7 +284,7 @@ class WritingFlow extends Component { if ( ! isVertical ) { this.verticalRect = null; } else if ( ! this.verticalRect ) { - this.verticalRect = computeCaretRect( target ); + this.verticalRect = computeCaretRect(); } if ( isShift ) { diff --git a/packages/components/src/index.js b/packages/components/src/index.js index 65c44bb660ef38..ce378c0b09e3a8 100644 --- a/packages/components/src/index.js +++ b/packages/components/src/index.js @@ -43,7 +43,6 @@ export { default as PanelHeader } from './panel/header'; export { default as PanelRow } from './panel/row'; export { default as Placeholder } from './placeholder'; export { default as Popover } from './popover'; -export { default as __unstablePositionedAtSelection } from './positioned-at-selection'; export { default as QueryControls } from './query-controls'; export { default as RadioControl } from './radio-control'; export { default as RangeControl } from './range-control'; diff --git a/packages/components/src/popover/index.js b/packages/components/src/popover/index.js index bdf1b5c0c7c624..4515cd2facfe78 100644 --- a/packages/components/src/popover/index.js +++ b/packages/components/src/popover/index.js @@ -282,6 +282,7 @@ class Popover extends Component { getAnchorRect, expandOnMobile, animate = true, + anchorRect, /* eslint-enable no-unused-vars */ ...contentProps } = this.props; diff --git a/packages/components/src/positioned-at-selection/index.js b/packages/components/src/positioned-at-selection/index.js deleted file mode 100644 index 37c039d77777df..00000000000000 --- a/packages/components/src/positioned-at-selection/index.js +++ /dev/null @@ -1,65 +0,0 @@ -/** - * WordPress dependencies - */ -import { Component } from '@wordpress/element'; -import { getOffsetParent, getRectangleFromRange } from '@wordpress/dom'; - -/** - * Returns a style object for applying as `position: absolute` for an element - * relative to the bottom-center of the current selection. Includes `top` and - * `left` style properties. - * - * @return {Object} Style object. - */ -function getCurrentCaretPositionStyle() { - const selection = window.getSelection(); - - // Unlikely, but in the case there is no selection, return empty styles so - // as to avoid a thrown error by `Selection#getRangeAt` on invalid index. - if ( selection.rangeCount === 0 ) { - return {}; - } - - // Get position relative viewport. - const rect = getRectangleFromRange( selection.getRangeAt( 0 ) ); - let top = rect.top + rect.height; - let left = rect.left + ( rect.width / 2 ); - - // Offset by positioned parent, if one exists. - const offsetParent = getOffsetParent( selection.anchorNode ); - if ( offsetParent ) { - const parentRect = offsetParent.getBoundingClientRect(); - top -= parentRect.top; - left -= parentRect.left; - } - - return { top, left }; -} - -/** - * Component which renders itself positioned under the current caret selection. - * The position is calculated at the time of the component being mounted, so it - * should only be mounted after the desired selection has been made. - * - * @type {WPComponent} - */ -export default class PositionedAtSelection extends Component { - constructor() { - super( ...arguments ); - - this.state = { - style: getCurrentCaretPositionStyle(), - }; - } - - render() { - const { children } = this.props; - const { style } = this.state; - - return ( -