From 5f006f6f8039ba87727e993fe561c859410bc385 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Thu, 21 Mar 2019 21:25:36 +0100 Subject: [PATCH 01/17] RichText: improve format boundary style (#14519) * RichText: improve format boundary style * rgb => rgba --- .../src/components/rich-text/index.js | 34 +++++++++++++++++-- .../src/components/rich-text/style.scss | 21 ------------ packages/block-library/src/cover/editor.scss | 5 --- .../block-library/src/gallery/editor.scss | 4 --- 4 files changed, 32 insertions(+), 32 deletions(-) diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 006ec4a697760..b49b05f63ad7c 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -82,6 +82,13 @@ const INSERTION_INPUT_TYPES_TO_IGNORE = new Set( [ 'insertLink', ] ); +/** + * Global stylesheet. + */ +const globalStyle = document.createElement( 'style' ); + +document.head.appendChild( globalStyle ); + export class RichText extends Component { constructor( { value, onReplace, multiline } ) { super( ...arguments ); @@ -472,10 +479,11 @@ export class RichText extends Component { } let selectedFormat; + const formatsAfter = formats[ start ] || []; + const collapsed = isCollapsed( value ); - if ( isCollapsed( value ) ) { + if ( collapsed ) { const formatsBefore = formats[ start - 1 ] || []; - const formatsAfter = formats[ start ] || []; selectedFormat = Math.min( formatsBefore.length, formatsAfter.length ); } @@ -484,6 +492,25 @@ export class RichText extends Component { this.applyRecord( { ...value, selectedFormat }, { domOnly: true } ); delete this.formatPlaceholder; + + if ( collapsed ? selectedFormat > 0 : formatsAfter.length > 0 ) { + this.recalculateBoundaryStyle(); + } + } + } + + recalculateBoundaryStyle() { + const boundarySelector = '*[data-rich-text-format-boundary]'; + const element = this.editableRef.querySelector( boundarySelector ); + + if ( element ) { + const computedStyle = getComputedStyle( element ); + const newColor = computedStyle.color + .replace( ')', ', 0.2)' ) + .replace( 'rgb', 'rgba' ); + + globalStyle.innerHTML = + `${ boundarySelector }{background-color: ${ newColor }}`; } } @@ -793,6 +820,9 @@ export class RichText extends Component { } } + // Wait for boundary class to be added. + setTimeout( () => this.recalculateBoundaryStyle() ); + if ( newSelectedFormat !== selectedFormat ) { this.applyRecord( { ...value, selectedFormat: newSelectedFormat } ); this.setState( { selectedFormat: newSelectedFormat } ); diff --git a/packages/block-editor/src/components/rich-text/style.scss b/packages/block-editor/src/components/rich-text/style.scss index 16fdc282020e0..4a52ddb56fcd3 100644 --- a/packages/block-editor/src/components/rich-text/style.scss +++ b/packages/block-editor/src/components/rich-text/style.scss @@ -45,27 +45,6 @@ *[data-rich-text-format-boundary] { border-radius: 2px; - box-shadow: 0 0 0 1px $light-gray-400; - background: $light-gray-400; - - // Enforce a dark text color so active inline boundaries - // are always readable. - // See https://github.com/WordPress/gutenberg/issues/9508 - color: $dark-gray-900; - } - - // Link inline boundaries get special colors. - a[data-rich-text-format-boundary] { - box-shadow: 0 0 0 1px $blue-medium-100; - background: $blue-medium-100; - color: $blue-medium-900; - } - - // inline boundaries need special treatment because their - // un-selected style is already padded. - code[data-rich-text-format-boundary] { - background: $light-gray-400; - box-shadow: 0 0 0 1px $light-gray-400; } } diff --git a/packages/block-library/src/cover/editor.scss b/packages/block-library/src/cover/editor.scss index c74979dc0969d..b368b3ee24c05 100644 --- a/packages/block-library/src/cover/editor.scss +++ b/packages/block-library/src/cover/editor.scss @@ -1,10 +1,5 @@ .wp-block-cover-image, .wp-block-cover { - .block-editor-rich-text__editable:focus a[data-rich-text-format-boundary] { - box-shadow: none; - background: rgba(255, 255, 255, 0.3); - } - &.components-placeholder h2 { color: inherit; } diff --git a/packages/block-library/src/gallery/editor.scss b/packages/block-library/src/gallery/editor.scss index 0340f66a31e8e..34b08797e2e55 100644 --- a/packages/block-library/src/gallery/editor.scss +++ b/packages/block-library/src/gallery/editor.scss @@ -82,10 +82,6 @@ ul.wp-block-gallery li { a { color: $white; } - - &:focus a[data-rich-text-format-boundary] { - color: rgba(0, 0, 0, 0.2); - } } } From abc096d80b2f2e3a745b99b78fd334f36f1fd249 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Thu, 21 Mar 2019 21:41:10 +0100 Subject: [PATCH 02/17] Paste: check plain text for gutenberg content (#14536) --- packages/blocks/src/api/raw-handling/paste-handler.js | 11 ++++++++--- test/integration/blocks-raw-handling.spec.js | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/packages/blocks/src/api/raw-handling/paste-handler.js b/packages/blocks/src/api/raw-handling/paste-handler.js index b40164f549689..1d67540c0b922 100644 --- a/packages/blocks/src/api/raw-handling/paste-handler.js +++ b/packages/blocks/src/api/raw-handling/paste-handler.js @@ -127,9 +127,14 @@ export function pasteHandler( { HTML = '', plainText = '', mode = 'AUTO', tagNam // First of all, strip any meta tags. HTML = HTML.replace( /]+>/, '' ); - // If we detect block delimiters, parse entirely as blocks. - if ( mode !== 'INLINE' && HTML.indexOf( ''; + expect( serialize( pasteHandler( { + plainText: block, + mode: 'AUTO', + } ) ) ).toBe( block ); + } ); + describe( 'pasteHandler', () => { [ 'plain', From afc5b0f538e4400544402c4874147553745077ee Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Fri, 22 Mar 2019 06:01:08 +0900 Subject: [PATCH 03/17] Make ClipboardButton inside a block work correctly in Safari (#7106) * Make ClipboardButton inside a block work in Safari * Update changelogs * Block Editor: Update "Next" to "Unreleased" per guidelines https://github.com/WordPress/gutenberg/blob/master/packages/README.md#maintaining-changelogs --- packages/block-editor/CHANGELOG.md | 6 ++++ .../src/components/copy-handler/index.js | 28 ++++--------------- packages/edit-post/CHANGELOG.md | 4 ++- .../src/components/visual-editor/index.js | 7 +++-- 4 files changed, 19 insertions(+), 26 deletions(-) diff --git a/packages/block-editor/CHANGELOG.md b/packages/block-editor/CHANGELOG.md index 5c4cae61450ac..4306b855955f5 100644 --- a/packages/block-editor/CHANGELOG.md +++ b/packages/block-editor/CHANGELOG.md @@ -1,3 +1,9 @@ +## 2.0.0 (Unreleased) + +### Breaking Changes + +- `CopyHandler` will now only catch cut/copy events coming from its `props.children`, instead of from anywhere in the `document`. + ## 1.0.0 (2019-03-06) ### New Features diff --git a/packages/block-editor/src/components/copy-handler/index.js b/packages/block-editor/src/components/copy-handler/index.js index 3942eaae71b03..3f73d5f672c15 100644 --- a/packages/block-editor/src/components/copy-handler/index.js +++ b/packages/block-editor/src/components/copy-handler/index.js @@ -1,33 +1,17 @@ /** * WordPress dependencies */ -import { Component } from '@wordpress/element'; import { serialize } from '@wordpress/blocks'; import { documentHasSelection } from '@wordpress/dom'; import { withDispatch } from '@wordpress/data'; import { compose } from '@wordpress/compose'; -class CopyHandler extends Component { - constructor() { - super( ...arguments ); - - this.onCopy = ( event ) => this.props.onCopy( event ); - this.onCut = ( event ) => this.props.onCut( event ); - } - - componentDidMount() { - document.addEventListener( 'copy', this.onCopy ); - document.addEventListener( 'cut', this.onCut ); - } - - componentWillUnmount() { - document.removeEventListener( 'copy', this.onCopy ); - document.removeEventListener( 'cut', this.onCut ); - } - - render() { - return null; - } +function CopyHandler( { children, onCopy, onCut } ) { + return ( +
+ { children } +
+ ); } export default compose( [ diff --git a/packages/edit-post/CHANGELOG.md b/packages/edit-post/CHANGELOG.md index db8c68da54229..4e58838aade5e 100644 --- a/packages/edit-post/CHANGELOG.md +++ b/packages/edit-post/CHANGELOG.md @@ -5,7 +5,9 @@ * Expose the `className` property to style the `PluginSidebar` component. ### Bug Fixes - - Fix 'save' keyboard shortcut not functioning in the Code Editor. + +- Fix 'save' keyboard shortcut not functioning in the Code Editor. +- Prevent `ClipboardButton` from incorrectly copying a serialized block string instead of the intended text in Safari. ## 3.1.7 (2019-01-03) diff --git a/packages/edit-post/src/components/visual-editor/index.js b/packages/edit-post/src/components/visual-editor/index.js index eadf8a5fc461d..ca6a1c45212b6 100644 --- a/packages/edit-post/src/components/visual-editor/index.js +++ b/packages/edit-post/src/components/visual-editor/index.js @@ -26,12 +26,13 @@ function VisualEditor() { return ( - - - + + + + <_BlockSettingsMenuFirstItem> From 3a8af4ce78a5eb0d5827da913e63088683f8458d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ella=20van=C2=A0Durpe?= Date: Fri, 22 Mar 2019 14:19:18 +0100 Subject: [PATCH 04/17] Input Interaction: always expand single line selection vertically (#14487) * Input Interaction: always expand single line selection vertically * Add e2e test --- packages/dom/src/dom.js | 29 ++++++++++--------- .../multi-block-selection.test.js.snap | 2 ++ .../specs/multi-block-selection.test.js | 13 +++++++++ 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/packages/dom/src/dom.js b/packages/dom/src/dom.js index 4ea9ad8c0ef78..b3b0f7b6df89d 100644 --- a/packages/dom/src/dom.js +++ b/packages/dom/src/dom.js @@ -169,16 +169,6 @@ export function isVerticalEdge( container, isReverse ) { } const selection = window.getSelection(); - - // Only consider the selection at the edge if the direction is towards the - // edge. - if ( - ! selection.isCollapsed && - isSelectionForward( selection ) === isReverse - ) { - return false; - } - const range = selection.rangeCount ? selection.getRangeAt( 0 ) : null; if ( ! range ) { @@ -191,14 +181,25 @@ export function isVerticalEdge( container, isReverse ) { return false; } - const editableRect = container.getBoundingClientRect(); - // Calculate a buffer that is half the line height. In some browsers, the // selection rectangle may not fill the entire height of the line, so we add // half the line height to the selection rectangle to ensure that it is well // over its line boundary. - const { lineHeight } = window.getComputedStyle( container ); - const buffer = parseInt( lineHeight, 10 ) / 2; + const computedStyle = window.getComputedStyle( container ); + const lineHeight = parseInt( computedStyle.lineHeight, 10 ); + + // Only consider the multiline selection at the edge if the direction is + // towards the edge. + if ( + ! selection.isCollapsed && + rangeRect.height > lineHeight && + isSelectionForward( selection ) === isReverse + ) { + return false; + } + + const editableRect = container.getBoundingClientRect(); + const buffer = lineHeight / 2; // Too low. if ( isReverse && rangeRect.top - buffer > editableRect.top ) { diff --git a/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap b/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap index 6986ffc94968b..f68e40f606dc4 100644 --- a/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap +++ b/packages/e2e-tests/specs/__snapshots__/multi-block-selection.test.js.snap @@ -6,6 +6,8 @@ exports[`Multi-block selection should allow selecting outer edge if there is no " `; +exports[`Multi-block selection should always expand single line selection 1`] = `""`; + exports[`Multi-block selection should only trigger multi-selection when at the end 1`] = ` "

1.

diff --git a/packages/e2e-tests/specs/multi-block-selection.test.js b/packages/e2e-tests/specs/multi-block-selection.test.js index 76ea211367660..6bf7a62bf7789 100644 --- a/packages/e2e-tests/specs/multi-block-selection.test.js +++ b/packages/e2e-tests/specs/multi-block-selection.test.js @@ -181,6 +181,19 @@ describe( 'Multi-block selection', () => { expect( await getEditedPostContent() ).toMatchSnapshot(); } ); + it( 'should always expand single line selection', async () => { + await clickBlockAppender(); + await page.keyboard.press( 'Enter' ); + await page.keyboard.type( '12' ); + await page.keyboard.press( 'ArrowLeft' ); + await pressKeyWithModifier( 'shift', 'ArrowRight' ); + await pressKeyWithModifier( 'shift', 'ArrowUp' ); + // This delete all blocks. + await page.keyboard.press( 'Backspace' ); + + expect( await getEditedPostContent() ).toMatchSnapshot(); + } ); + it( 'should allow selecting outer edge if there is no sibling block', async () => { await clickBlockAppender(); await page.keyboard.type( '1' ); From 9b594f1ca1de7081b00b916bf1412e31830717f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s?= Date: Fri, 22 Mar 2019 18:31:26 +0100 Subject: [PATCH 05/17] Use MenuItem instead of IconButton (#14569) --- .../block-settings-menu/plugin-block-settings-menu-item.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js b/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js index 810d558346cc7..7a7451a983ce3 100644 --- a/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js +++ b/packages/edit-post/src/components/block-settings-menu/plugin-block-settings-menu-item.js @@ -6,7 +6,7 @@ import { difference } from 'lodash'; /** * WordPress dependencies */ -import { IconButton } from '@wordpress/components'; +import { MenuItem } from '@wordpress/components'; import { compose } from '@wordpress/compose'; /** @@ -89,7 +89,7 @@ const PluginBlockSettingsMenuItem = ( { allowedBlocks, icon, label, onClick, sma if ( ! shouldRenderItem( selectedBlocks, allowedBlocks ) ) { return null; } - return ( { ! small && label } - ); + ); } } ); From cbaf41f529e369174d572196083007cc50b745b7 Mon Sep 17 00:00:00 2001 From: Jackie6 <541172791@qq.com> Date: Fri, 22 Mar 2019 14:26:30 -0400 Subject: [PATCH 06/17] Remove id, infoid, label and aria-describedby from MenuItem (#14423) --- .../block-settings-menu/block-convert-button.js | 1 - .../components/block-settings-menu/block-mode-toggle.js | 1 - packages/components/src/menu-item/README.md | 9 --------- packages/components/src/menu-item/index.js | 7 ------- .../src/menu-item/test/__snapshots__/index.js.snap | 2 -- packages/components/src/menu-item/test/index.js | 2 +- .../src/components/header/feature-toggle/index.js | 1 - .../test/__snapshots__/index.js.snap | 1 + .../components/visual-editor/block-inspector-button.js | 1 - 9 files changed, 2 insertions(+), 23 deletions(-) diff --git a/packages/block-editor/src/components/block-settings-menu/block-convert-button.js b/packages/block-editor/src/components/block-settings-menu/block-convert-button.js index 2ae65fed66cfd..f27cac38b1df9 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-convert-button.js +++ b/packages/block-editor/src/components/block-settings-menu/block-convert-button.js @@ -15,7 +15,6 @@ export default function BlockConvertButton( { shouldRender, onClick, small } ) { className="editor-block-settings-menu__control block-editor-block-settings-menu__control" onClick={ onClick } icon="screenoptions" - label={ small ? label : undefined } > { ! small && label } diff --git a/packages/block-editor/src/components/block-settings-menu/block-mode-toggle.js b/packages/block-editor/src/components/block-settings-menu/block-mode-toggle.js index 8ba029fd1794c..3f8260d135e44 100644 --- a/packages/block-editor/src/components/block-settings-menu/block-mode-toggle.js +++ b/packages/block-editor/src/components/block-settings-menu/block-mode-toggle.js @@ -26,7 +26,6 @@ export function BlockModeToggle( { blockType, mode, onToggleMode, small = false className="editor-block-settings-menu__control block-editor-block-settings-menu__control" onClick={ onToggleMode } icon="html" - label={ small ? label : undefined } > { ! small && label } diff --git a/packages/components/src/menu-item/README.md b/packages/components/src/menu-item/README.md index eacd6770f7aaf..38251ccedf261 100644 --- a/packages/components/src/menu-item/README.md +++ b/packages/components/src/menu-item/README.md @@ -34,15 +34,6 @@ Element to render as child of button. Element -### `label` - -- Type: `string` -- Required: No - -String to use as primary button label text, applied as `aria-label`. Useful in cases where an `info` prop is passed, where `label` should be the minimal text of the button, described in further detail by `info`. - -Defaults to the value of `children`, if `children` is passed as a string. - ### `info` - Type: `string` diff --git a/packages/components/src/menu-item/index.js b/packages/components/src/menu-item/index.js index 860430b4ecb67..1b793a2c5cf26 100644 --- a/packages/components/src/menu-item/index.js +++ b/packages/components/src/menu-item/index.js @@ -30,7 +30,6 @@ export function MenuItem( { shortcut, isSelected, role = 'menuitem', - instanceId, ...props } ) { className = classnames( 'components-menu-item__button', className, { @@ -38,16 +37,10 @@ export function MenuItem( { } ); if ( info ) { - const infoId = 'edit-post-feature-toggle__info-' + instanceId; - - // Deconstructed props is scoped to the function; mutation is fine. - props[ 'aria-describedby' ] = infoId; - children = ( { children } { info } diff --git a/packages/components/src/menu-item/test/__snapshots__/index.js.snap b/packages/components/src/menu-item/test/__snapshots__/index.js.snap index a0f00b2889f00..d029c29c0cb3a 100644 --- a/packages/components/src/menu-item/test/__snapshots__/index.js.snap +++ b/packages/components/src/menu-item/test/__snapshots__/index.js.snap @@ -18,7 +18,6 @@ exports[`MenuItem should match snapshot when all props provided 1`] = ` exports[`MenuItem should match snapshot when info is provided 1`] = ` @@ -28,7 +27,6 @@ exports[`MenuItem should match snapshot when info is provided 1`] = ` My item Extended description of My Item diff --git a/packages/components/src/menu-item/test/index.js b/packages/components/src/menu-item/test/index.js index f521add7452c8..63ac41b337dff 100644 --- a/packages/components/src/menu-item/test/index.js +++ b/packages/components/src/menu-item/test/index.js @@ -54,7 +54,7 @@ describe( 'MenuItem', () => { it( 'should match snapshot when info is provided', () => { const wrapper = shallow( - + My item ); diff --git a/packages/edit-post/src/components/header/feature-toggle/index.js b/packages/edit-post/src/components/header/feature-toggle/index.js index 4e0df7f3749b0..b855ca046c386 100644 --- a/packages/edit-post/src/components/header/feature-toggle/index.js +++ b/packages/edit-post/src/components/header/feature-toggle/index.js @@ -26,7 +26,6 @@ function FeatureToggle( { onToggle, isActive, label, info, messageActivated, mes isSelected={ isActive } onClick={ flow( onToggle, speakMessage ) } role="menuitemcheckbox" - label={ label } info={ info } > { label } diff --git a/packages/edit-post/src/components/header/plugin-more-menu-item/test/__snapshots__/index.js.snap b/packages/edit-post/src/components/header/plugin-more-menu-item/test/__snapshots__/index.js.snap index 6e395b2e7ebae..7fa0869a60f22 100644 --- a/packages/edit-post/src/components/header/plugin-more-menu-item/test/__snapshots__/index.js.snap +++ b/packages/edit-post/src/components/header/plugin-more-menu-item/test/__snapshots__/index.js.snap @@ -18,6 +18,7 @@ exports[`PluginMoreMenuItem renders menu item as button properly 1`] = ` >