Skip to content
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

Components: remove __unstablePositionedAtSelection #15035

Merged
merged 3 commits into from
May 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/writing-flow/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ class WritingFlow extends Component {
if ( ! isVertical ) {
this.verticalRect = null;
} else if ( ! this.verticalRect ) {
this.verticalRect = computeCaretRect( target );
ellatrix marked this conversation as resolved.
Show resolved Hide resolved
this.verticalRect = computeCaretRect();
}

if ( isShift ) {
Expand Down
1 change: 0 additions & 1 deletion packages/components/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 1 addition & 0 deletions packages/components/src/popover/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ class Popover extends Component {
getAnchorRect,
expandOnMobile,
animate = true,
anchorRect,
/* eslint-enable no-unused-vars */
...contentProps
} = this.props;
Expand Down
65 changes: 0 additions & 65 deletions packages/components/src/positioned-at-selection/index.js

This file was deleted.

4 changes: 0 additions & 4 deletions packages/dom/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ npm install @wordpress/dom --save

Get the rectangle for the selection in a container.

_Parameters_

- _container_ `Element`: Editable container.

_Returns_

- `?DOMRect`: The rectangle.
Expand Down
8 changes: 1 addition & 7 deletions packages/dom/src/dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,9 @@ export function getRectangleFromRange( range ) {
/**
* Get the rectangle for the selection in a container.
*
* @param {Element} container Editable container.
*
* @return {?DOMRect} The rectangle.
*/
export function computeCaretRect( container ) {
ellatrix marked this conversation as resolved.
Show resolved Hide resolved
if ( ! container.isContentEditable ) {
return;
}

export function computeCaretRect() {
const selection = window.getSelection();
const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null;

Expand Down
32 changes: 21 additions & 11 deletions packages/format-library/src/image/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
/**
* WordPress dependencies
*/
import { Path, SVG, TextControl, Popover, IconButton, __unstablePositionedAtSelection } from '@wordpress/components';
import { Path, SVG, TextControl, Popover, IconButton } from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { Component } from '@wordpress/element';
import { Component, useMemo } from '@wordpress/element';
import { insertObject } from '@wordpress/rich-text';
import { MediaUpload, RichTextToolbarButton, MediaUploadCheck } from '@wordpress/block-editor';
import { LEFT, RIGHT, UP, DOWN, BACKSPACE, ENTER } from '@wordpress/keycodes';
import { computeCaretRect } from '@wordpress/dom';

const ALLOWED_MEDIA_TYPES = [ 'image' ];

const name = 'core/image';

const stopKeyPropagation = ( event ) => event.stopPropagation();

const PopoverAtImage = ( { dependencies, ...props } ) => {
return (
<Popover
position="bottom center"
focusOnMount={ false }
anchorRect={ useMemo( () => computeCaretRect(), dependencies ) }
{ ...props }
/>
);
};

export const image = {
name,
title: __( 'Image' ),
Expand Down Expand Up @@ -81,9 +93,6 @@ export const image = {
render() {
const { value, onChange, isObjectActive, activeObjectAttributes } = this.props;
const { style } = activeObjectAttributes;
// Rerender PositionedAtSelection when the selection changes or when
// the width changes.
const key = value.start + style;

return (
<MediaUploadCheck>
Expand Down Expand Up @@ -113,10 +122,11 @@ export const image = {
return null;
} }
/> }
{ isObjectActive && <__unstablePositionedAtSelection key={ key }>
<Popover
position="bottom center"
focusOnMount={ false }
{ isObjectActive &&
<PopoverAtImage
// Reposition Popover when the selection changes or
// when the width changes.
dependencies={ [ style, value.start ] }
>
{ // Disable reason: KeyPress must be suppressed so the block doesn't hide the toolbar
/* eslint-disable jsx-a11y/no-noninteractive-element-interactions */ }
Expand Down Expand Up @@ -154,8 +164,8 @@ export const image = {
<IconButton icon="editor-break" label={ __( 'Apply' ) } type="submit" />
</form>
{ /* eslint-enable jsx-a11y/no-noninteractive-element-interactions */ }
</Popover>
</__unstablePositionedAtSelection> }
</PopoverAtImage>
}
</MediaUploadCheck>
);
}
Expand Down