From c7d28be05c8f74c00717bd671caeba1c0303a6ff Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Fri, 26 Oct 2018 10:32:45 -0400 Subject: [PATCH 1/4] Editor: Deprecate `layout` attribute --- docs/data/data-core-editor.md | 2 +- docs/reference/deprecated.md | 1 + .../src/components/block-drop-zone/index.js | 6 ++- .../src/components/inner-blocks/README.md | 28 +--------- .../src/components/inner-blocks/index.js | 9 ++++ packages/editor/src/store/actions.js | 53 ++++++++++++++++--- packages/editor/src/store/test/actions.js | 4 ++ 7 files changed, 68 insertions(+), 35 deletions(-) diff --git a/docs/data/data-core-editor.md b/docs/data/data-core-editor.md index 6554b8d7535bd..b514a9bcd828a 100644 --- a/docs/data/data-core-editor.md +++ b/docs/data/data-core-editor.md @@ -1512,7 +1512,7 @@ to a new index. * clientId: The client ID of the block. * fromRootClientId: Root client ID source. * toRootClientId: Root client ID destination. - * layout: Layout to move the block into. + * indexOrDeprecatedLayout: The index to move the block into. * index: The index to move the block into. ### insertBlock diff --git a/docs/reference/deprecated.md b/docs/reference/deprecated.md index 65d80a8d59388..706787562b0e1 100644 --- a/docs/reference/deprecated.md +++ b/docs/reference/deprecated.md @@ -6,6 +6,7 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo - `wp.compose.remountOnPropChange` has been removed. - The following editor store actions have been removed: `createNotice`, `removeNotice`, `createSuccessNotice`, `createInfoNotice`, `createErrorNotice`, `createWarningNotice`. Use the equivalent actions by the same name from the `@wordpress/notices` module. - The id prop of wp.nux.DotTip has been removed. Please use the tipId prop instead. +- Block `layout` support has been removed, including the `InnerBlocks` `layouts` prop. See: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/inner-blocks/README.md#usage ## 4.3.0 diff --git a/packages/editor/src/components/block-drop-zone/index.js b/packages/editor/src/components/block-drop-zone/index.js index ded228febbe32..5324b88e1d361 100644 --- a/packages/editor/src/components/block-drop-zone/index.js +++ b/packages/editor/src/components/block-drop-zone/index.js @@ -151,7 +151,11 @@ export default compose( }, moveBlockToPosition( srcClientId, srcRootClientId, dstIndex ) { const { rootClientId: dstRootClientId, layout } = ownProps; - moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, layout, dstIndex ); + if ( layout === undefined ) { + moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, dstIndex ); + } else { + moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, layout, dstIndex ); + } }, }; } ), diff --git a/packages/editor/src/components/inner-blocks/README.md b/packages/editor/src/components/inner-blocks/README.md index 5659a9cead961..494fb750fb74c 100644 --- a/packages/editor/src/components/inner-blocks/README.md +++ b/packages/editor/src/components/inner-blocks/README.md @@ -7,9 +7,7 @@ Refer to the [implementation of the Columns block](https://github.com/WordPress/ ## Usage -In a block's `edit` implementation, render `InnerBlocks`, optionally with `layouts` of available nest areas: - -Then, in the `save` implementation, render `InnerBlocks.Content`. This will be replaced automatically with the content of the nested blocks. +In a block's `edit` implementation, render `InnerBlocks`. Then, in the `save` implementation, render `InnerBlocks.Content`. This will be replaced automatically with the content of the nested blocks. ```jsx import { registerBlockType } from '@wordpress/blocks'; @@ -36,7 +34,7 @@ registerBlockType( 'my-plugin/my-block', { } ); ``` -_Note:_ A block can render at most a single `InnerBlocks` and `InnerBlocks.Content` element in `edit` and `save` respectively. To create distinct arrangements of nested blocks, refer to the `layouts` prop documented below. +_Note:_ A block can render at most a single `InnerBlocks` and `InnerBlocks.Content` element in `edit` and `save` respectively. To create distinct arrangements of nested blocks, create a separate block type which renders its own `InnerBlocks` and assign as the sole `allowedBlocks` type. _Note:_ Because the save step will automatically apply props to the element returned by `save`, it is important to include the wrapping `div` in the above simple example even though we are applying no props of our own. In a real-world example, you may have your own attributes to apply to the saved markup, or sibling content adjacent to the rendered nested blocks. @@ -107,25 +105,3 @@ Template locking allows locking the `InnerBlocks` area for the current template. If locking is not set in an `InnerBlocks` area: the locking of the parent `InnerBlocks` area is used. If the block is a top level block: the locking of the Custom Post Type is used. - -### `layouts` -* **Type:** `Array|Object` - -To achieve distinct arrangements of nested blocks, you may assign layout as an object. When assigned, the rendered output will assign a layout-specific class which can be used in your block stylesheet to effect the visual arrangement of nested blocks. - -A layout is an object where each key is the `slug` of the layout and its value an object consisting of: - -- Icon (`icon: string`): The slug of the Dashicon to use in controls presented to the user in moving between layouts - - Reference: https://developer.wordpress.org/resource/dashicons/ -- Label (`label: string`): The text to display in the controls presented to the user in moving between layouts - -The `slug` is also used to create the class name for the block. A slug of `normal` would output the class `"layout-normal"`. - -**Example:** - -```jsx - -``` diff --git a/packages/editor/src/components/inner-blocks/index.js b/packages/editor/src/components/inner-blocks/index.js index 9108743838c10..c26d2e36e4151 100644 --- a/packages/editor/src/components/inner-blocks/index.js +++ b/packages/editor/src/components/inner-blocks/index.js @@ -13,6 +13,7 @@ import { withSelect, withDispatch } from '@wordpress/data'; import { synchronizeBlocksWithTemplate, withBlockContentContext } from '@wordpress/blocks'; import isShallowEqual from '@wordpress/is-shallow-equal'; import { compose } from '@wordpress/compose'; +import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -105,6 +106,14 @@ class InnerBlocks extends Component { 'has-overlay': isSmallScreen && ! isSelectedBlockInRoot, } ); + if ( layouts !== undefined ) { + deprecated( 'InnerBlocks `layouts` prop', { + plugin: 'Gutenberg', + version: '2.4.0', + hint: 'Layout has been deprecated. The prop should be removed.', + } ); + } + return (
block.attributes.layout !== undefined ) ) { + deprecated( 'replaceBlocks with block including `layout` attribute', { + plugin: 'Gutenberg', + version: '2.4.0', + hint: 'Layout has been deprecated. The attribute should be removed.', + } ); + } + return { type: 'REPLACE_BLOCKS', clientIds: castArray( clientIds ), - blocks: castArray( blocks ), + blocks, time: Date.now(), }; } @@ -274,15 +292,28 @@ export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' ); * Returns an action object signalling that an indexed block should be moved * to a new index. * - * @param {?string} clientId The client ID of the block. - * @param {?string} fromRootClientId Root client ID source. - * @param {?string} toRootClientId Root client ID destination. - * @param {?string} layout Layout to move the block into. - * @param {number} index The index to move the block into. + * @param {?string} clientId The client ID of the block. + * @param {?string} fromRootClientId Root client ID source. + * @param {?string} toRootClientId Root client ID destination. + * @param {?string} indexOrDeprecatedLayout The index to move the block into. + * @param {?number} index The index to move the block into. * * @return {Object} Action object. */ -export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, layout, index ) { +export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, indexOrDeprecatedLayout, index ) { + let layout; + if ( index === undefined ) { + index = indexOrDeprecatedLayout; + } else { + deprecated( 'moveBlockToPosition `layout` argument', { + plugin: 'Gutenberg', + version: '2.4.0', + hint: 'Layout has been deprecated. The argument should be removed.', + } ); + + layout = indexOrDeprecatedLayout; + } + return { type: 'MOVE_BLOCK_TO_POSITION', fromRootClientId, @@ -320,6 +351,14 @@ export function insertBlock( block, index, rootClientId ) { * @return {Object} Action object. */ export function insertBlocks( blocks, index, rootClientId ) { + if ( blocks.some( ( block ) => block.attributes.layout !== undefined ) ) { + deprecated( 'insertBlocks with block including `layout` attribute', { + plugin: 'Gutenberg', + version: '2.4.0', + hint: 'Layout has been deprecated. The attribute should be removed.', + } ); + } + return { type: 'INSERT_BLOCKS', blocks: castArray( blocks ), diff --git a/packages/editor/src/store/test/actions.js b/packages/editor/src/store/test/actions.js index 9c776f0cc47e8..ab6ad500e266d 100644 --- a/packages/editor/src/store/test/actions.js +++ b/packages/editor/src/store/test/actions.js @@ -150,6 +150,7 @@ describe( 'actions', () => { it( 'should return the REPLACE_BLOCKS action', () => { const block = { clientId: 'ribs', + attributes: {}, }; expect( replaceBlock( [ 'chicken' ], block ) ).toEqual( { @@ -165,6 +166,7 @@ describe( 'actions', () => { it( 'should return the REPLACE_BLOCKS action', () => { const blocks = [ { clientId: 'ribs', + attributes: {}, } ]; expect( replaceBlocks( [ 'chicken' ], blocks ) ).toEqual( { @@ -180,6 +182,7 @@ describe( 'actions', () => { it( 'should return the INSERT_BLOCKS action', () => { const block = { clientId: 'ribs', + attributes: {}, }; const index = 5; expect( insertBlock( block, index, 'testclientid' ) ).toEqual( { @@ -196,6 +199,7 @@ describe( 'actions', () => { it( 'should return the INSERT_BLOCKS action', () => { const blocks = [ { clientId: 'ribs', + attributes: {}, } ]; const index = 3; expect( insertBlocks( blocks, index, 'testclientid' ) ).toEqual( { From 007540f45034fe89fd4e73a259f229a6b6adaa40 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 29 Oct 2018 09:38:42 -0400 Subject: [PATCH 2/4] Revert "Editor: Deprecate `layout` attribute" This reverts commit c7d28be05c8f74c00717bd671caeba1c0303a6ff. --- docs/data/data-core-editor.md | 2 +- docs/reference/deprecated.md | 1 - .../src/components/block-drop-zone/index.js | 6 +-- .../src/components/inner-blocks/README.md | 28 +++++++++- .../src/components/inner-blocks/index.js | 9 ---- packages/editor/src/store/actions.js | 53 +++---------------- packages/editor/src/store/test/actions.js | 4 -- 7 files changed, 35 insertions(+), 68 deletions(-) diff --git a/docs/data/data-core-editor.md b/docs/data/data-core-editor.md index b514a9bcd828a..6554b8d7535bd 100644 --- a/docs/data/data-core-editor.md +++ b/docs/data/data-core-editor.md @@ -1512,7 +1512,7 @@ to a new index. * clientId: The client ID of the block. * fromRootClientId: Root client ID source. * toRootClientId: Root client ID destination. - * indexOrDeprecatedLayout: The index to move the block into. + * layout: Layout to move the block into. * index: The index to move the block into. ### insertBlock diff --git a/docs/reference/deprecated.md b/docs/reference/deprecated.md index 706787562b0e1..65d80a8d59388 100644 --- a/docs/reference/deprecated.md +++ b/docs/reference/deprecated.md @@ -6,7 +6,6 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo - `wp.compose.remountOnPropChange` has been removed. - The following editor store actions have been removed: `createNotice`, `removeNotice`, `createSuccessNotice`, `createInfoNotice`, `createErrorNotice`, `createWarningNotice`. Use the equivalent actions by the same name from the `@wordpress/notices` module. - The id prop of wp.nux.DotTip has been removed. Please use the tipId prop instead. -- Block `layout` support has been removed, including the `InnerBlocks` `layouts` prop. See: https://github.com/WordPress/gutenberg/blob/master/packages/editor/src/components/inner-blocks/README.md#usage ## 4.3.0 diff --git a/packages/editor/src/components/block-drop-zone/index.js b/packages/editor/src/components/block-drop-zone/index.js index 5324b88e1d361..ded228febbe32 100644 --- a/packages/editor/src/components/block-drop-zone/index.js +++ b/packages/editor/src/components/block-drop-zone/index.js @@ -151,11 +151,7 @@ export default compose( }, moveBlockToPosition( srcClientId, srcRootClientId, dstIndex ) { const { rootClientId: dstRootClientId, layout } = ownProps; - if ( layout === undefined ) { - moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, dstIndex ); - } else { - moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, layout, dstIndex ); - } + moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, layout, dstIndex ); }, }; } ), diff --git a/packages/editor/src/components/inner-blocks/README.md b/packages/editor/src/components/inner-blocks/README.md index 494fb750fb74c..5659a9cead961 100644 --- a/packages/editor/src/components/inner-blocks/README.md +++ b/packages/editor/src/components/inner-blocks/README.md @@ -7,7 +7,9 @@ Refer to the [implementation of the Columns block](https://github.com/WordPress/ ## Usage -In a block's `edit` implementation, render `InnerBlocks`. Then, in the `save` implementation, render `InnerBlocks.Content`. This will be replaced automatically with the content of the nested blocks. +In a block's `edit` implementation, render `InnerBlocks`, optionally with `layouts` of available nest areas: + +Then, in the `save` implementation, render `InnerBlocks.Content`. This will be replaced automatically with the content of the nested blocks. ```jsx import { registerBlockType } from '@wordpress/blocks'; @@ -34,7 +36,7 @@ registerBlockType( 'my-plugin/my-block', { } ); ``` -_Note:_ A block can render at most a single `InnerBlocks` and `InnerBlocks.Content` element in `edit` and `save` respectively. To create distinct arrangements of nested blocks, create a separate block type which renders its own `InnerBlocks` and assign as the sole `allowedBlocks` type. +_Note:_ A block can render at most a single `InnerBlocks` and `InnerBlocks.Content` element in `edit` and `save` respectively. To create distinct arrangements of nested blocks, refer to the `layouts` prop documented below. _Note:_ Because the save step will automatically apply props to the element returned by `save`, it is important to include the wrapping `div` in the above simple example even though we are applying no props of our own. In a real-world example, you may have your own attributes to apply to the saved markup, or sibling content adjacent to the rendered nested blocks. @@ -105,3 +107,25 @@ Template locking allows locking the `InnerBlocks` area for the current template. If locking is not set in an `InnerBlocks` area: the locking of the parent `InnerBlocks` area is used. If the block is a top level block: the locking of the Custom Post Type is used. + +### `layouts` +* **Type:** `Array|Object` + +To achieve distinct arrangements of nested blocks, you may assign layout as an object. When assigned, the rendered output will assign a layout-specific class which can be used in your block stylesheet to effect the visual arrangement of nested blocks. + +A layout is an object where each key is the `slug` of the layout and its value an object consisting of: + +- Icon (`icon: string`): The slug of the Dashicon to use in controls presented to the user in moving between layouts + - Reference: https://developer.wordpress.org/resource/dashicons/ +- Label (`label: string`): The text to display in the controls presented to the user in moving between layouts + +The `slug` is also used to create the class name for the block. A slug of `normal` would output the class `"layout-normal"`. + +**Example:** + +```jsx + +``` diff --git a/packages/editor/src/components/inner-blocks/index.js b/packages/editor/src/components/inner-blocks/index.js index c26d2e36e4151..9108743838c10 100644 --- a/packages/editor/src/components/inner-blocks/index.js +++ b/packages/editor/src/components/inner-blocks/index.js @@ -13,7 +13,6 @@ import { withSelect, withDispatch } from '@wordpress/data'; import { synchronizeBlocksWithTemplate, withBlockContentContext } from '@wordpress/blocks'; import isShallowEqual from '@wordpress/is-shallow-equal'; import { compose } from '@wordpress/compose'; -import deprecated from '@wordpress/deprecated'; /** * Internal dependencies @@ -106,14 +105,6 @@ class InnerBlocks extends Component { 'has-overlay': isSmallScreen && ! isSelectedBlockInRoot, } ); - if ( layouts !== undefined ) { - deprecated( 'InnerBlocks `layouts` prop', { - plugin: 'Gutenberg', - version: '2.4.0', - hint: 'Layout has been deprecated. The prop should be removed.', - } ); - } - return (
block.attributes.layout !== undefined ) ) { - deprecated( 'replaceBlocks with block including `layout` attribute', { - plugin: 'Gutenberg', - version: '2.4.0', - hint: 'Layout has been deprecated. The attribute should be removed.', - } ); - } - return { type: 'REPLACE_BLOCKS', clientIds: castArray( clientIds ), - blocks, + blocks: castArray( blocks ), time: Date.now(), }; } @@ -292,28 +274,15 @@ export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' ); * Returns an action object signalling that an indexed block should be moved * to a new index. * - * @param {?string} clientId The client ID of the block. - * @param {?string} fromRootClientId Root client ID source. - * @param {?string} toRootClientId Root client ID destination. - * @param {?string} indexOrDeprecatedLayout The index to move the block into. - * @param {?number} index The index to move the block into. + * @param {?string} clientId The client ID of the block. + * @param {?string} fromRootClientId Root client ID source. + * @param {?string} toRootClientId Root client ID destination. + * @param {?string} layout Layout to move the block into. + * @param {number} index The index to move the block into. * * @return {Object} Action object. */ -export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, indexOrDeprecatedLayout, index ) { - let layout; - if ( index === undefined ) { - index = indexOrDeprecatedLayout; - } else { - deprecated( 'moveBlockToPosition `layout` argument', { - plugin: 'Gutenberg', - version: '2.4.0', - hint: 'Layout has been deprecated. The argument should be removed.', - } ); - - layout = indexOrDeprecatedLayout; - } - +export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, layout, index ) { return { type: 'MOVE_BLOCK_TO_POSITION', fromRootClientId, @@ -351,14 +320,6 @@ export function insertBlock( block, index, rootClientId ) { * @return {Object} Action object. */ export function insertBlocks( blocks, index, rootClientId ) { - if ( blocks.some( ( block ) => block.attributes.layout !== undefined ) ) { - deprecated( 'insertBlocks with block including `layout` attribute', { - plugin: 'Gutenberg', - version: '2.4.0', - hint: 'Layout has been deprecated. The attribute should be removed.', - } ); - } - return { type: 'INSERT_BLOCKS', blocks: castArray( blocks ), diff --git a/packages/editor/src/store/test/actions.js b/packages/editor/src/store/test/actions.js index ab6ad500e266d..9c776f0cc47e8 100644 --- a/packages/editor/src/store/test/actions.js +++ b/packages/editor/src/store/test/actions.js @@ -150,7 +150,6 @@ describe( 'actions', () => { it( 'should return the REPLACE_BLOCKS action', () => { const block = { clientId: 'ribs', - attributes: {}, }; expect( replaceBlock( [ 'chicken' ], block ) ).toEqual( { @@ -166,7 +165,6 @@ describe( 'actions', () => { it( 'should return the REPLACE_BLOCKS action', () => { const blocks = [ { clientId: 'ribs', - attributes: {}, } ]; expect( replaceBlocks( [ 'chicken' ], blocks ) ).toEqual( { @@ -182,7 +180,6 @@ describe( 'actions', () => { it( 'should return the INSERT_BLOCKS action', () => { const block = { clientId: 'ribs', - attributes: {}, }; const index = 5; expect( insertBlock( block, index, 'testclientid' ) ).toEqual( { @@ -199,7 +196,6 @@ describe( 'actions', () => { it( 'should return the INSERT_BLOCKS action', () => { const blocks = [ { clientId: 'ribs', - attributes: {}, } ]; const index = 3; expect( insertBlocks( blocks, index, 'testclientid' ) ).toEqual( { From 4b17713c745e47f73699fa7c92047c928135e8ad Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 29 Oct 2018 09:57:26 -0400 Subject: [PATCH 3/4] Editor: Remove non-functional layout support --- docs/data/data-core-editor.md | 4 +- .../src/components/block-drop-zone/index.js | 18 +--- .../components/block-list-appender/index.js | 6 -- .../editor/src/components/block-list/block.js | 14 +-- .../editor/src/components/block-list/index.js | 22 +---- .../components/block-list/insertion-point.js | 4 +- .../default-block-appender/index.js | 14 +-- .../src/components/inner-blocks/README.md | 28 +----- .../src/components/inner-blocks/index.js | 3 +- .../inserter-with-shortcuts/index.js | 4 +- .../editor/src/components/inserter/index.js | 9 +- packages/editor/src/hooks/index.js | 1 - packages/editor/src/hooks/layout.js | 88 ------------------- packages/editor/src/hooks/test/layout.js | 66 -------------- packages/editor/src/store/actions.js | 4 +- .../src/store/effects/reusable-blocks.js | 1 - packages/editor/src/store/reducer.js | 17 ---- packages/editor/src/store/selectors.js | 9 +- packages/editor/src/store/test/selectors.js | 34 ------- packages/editor/src/utils/test/dom.js | 4 +- 20 files changed, 29 insertions(+), 321 deletions(-) delete mode 100644 packages/editor/src/hooks/layout.js delete mode 100644 packages/editor/src/hooks/test/layout.js diff --git a/docs/data/data-core-editor.md b/docs/data/data-core-editor.md index 6554b8d7535bd..a4fe2f576da27 100644 --- a/docs/data/data-core-editor.md +++ b/docs/data/data-core-editor.md @@ -930,8 +930,7 @@ be placed. Defaults to the last index. *Returns* -Insertion point object with `rootClientId`, `layout`, -`index`. +Insertion point object with `rootClientId`, `index`. ### isBlockInsertionPointVisible @@ -1512,7 +1511,6 @@ to a new index. * clientId: The client ID of the block. * fromRootClientId: Root client ID source. * toRootClientId: Root client ID destination. - * layout: Layout to move the block into. * index: The index to move the block into. ### insertBlock diff --git a/packages/editor/src/components/block-drop-zone/index.js b/packages/editor/src/components/block-drop-zone/index.js index ded228febbe32..5c4df43bb4ad5 100644 --- a/packages/editor/src/components/block-drop-zone/index.js +++ b/packages/editor/src/components/block-drop-zone/index.js @@ -1,7 +1,6 @@ /** * External Dependencies */ -import { castArray } from 'lodash'; import classnames from 'classnames'; /** @@ -10,7 +9,6 @@ import classnames from 'classnames'; import { DropZone } from '@wordpress/components'; import { rawHandler, - cloneBlock, getBlockTransforms, findTransform, } from '@wordpress/blocks'; @@ -132,17 +130,7 @@ export default compose( return { insertBlocks( blocks, index ) { - const { rootClientId, layout } = ownProps; - - if ( layout ) { - // A block's transform function may return a single - // transformed block or an array of blocks, so ensure - // to first coerce to an array before mapping to inject - // the layout attribute. - blocks = castArray( blocks ).map( ( block ) => ( - cloneBlock( block, { layout } ) - ) ); - } + const { rootClientId } = ownProps; insertBlocks( blocks, index, rootClientId ); }, @@ -150,8 +138,8 @@ export default compose( updateBlockAttributes( ...args ); }, moveBlockToPosition( srcClientId, srcRootClientId, dstIndex ) { - const { rootClientId: dstRootClientId, layout } = ownProps; - moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, layout, dstIndex ); + const { rootClientId: dstRootClientId } = ownProps; + moveBlockToPosition( srcClientId, srcRootClientId, dstRootClientId, dstIndex ); }, }; } ), diff --git a/packages/editor/src/components/block-list-appender/index.js b/packages/editor/src/components/block-list-appender/index.js index 5ee01b1e7c138..3f0bb11a22652 100644 --- a/packages/editor/src/components/block-list-appender/index.js +++ b/packages/editor/src/components/block-list-appender/index.js @@ -20,8 +20,6 @@ import Inserter from '../inserter'; function BlockListAppender( { blockClientIds, - layout, - isGroupedByLayout, rootClientId, canInsertDefaultBlock, isLocked, @@ -30,15 +28,12 @@ function BlockListAppender( { return null; } - const defaultLayout = isGroupedByLayout ? layout : undefined; - if ( canInsertDefaultBlock ) { return ( ); @@ -48,7 +43,6 @@ function BlockListAppender( {
(
@@ -655,8 +650,7 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { selectBlock( clientId, initialPosition ); }, onInsertBlocks( blocks, index ) { - const { rootClientId, layout } = ownProps; - blocks = blocks.map( ( block ) => cloneBlock( block, { layout } ) ); + const { rootClientId } = ownProps; insertBlocks( blocks, index, rootClientId ); }, onInsertDefaultBlockAfter() { @@ -670,10 +664,6 @@ const applyWithDispatch = withDispatch( ( dispatch, ownProps ) => { mergeBlocks( ...args ); }, onReplace( blocks ) { - const { layout } = ownProps; - blocks = castArray( blocks ).map( ( block ) => ( - cloneBlock( block, { layout } ) - ) ); replaceBlocks( [ ownProps.clientId ], blocks ); }, onMetaChange( meta ) { diff --git a/packages/editor/src/components/block-list/index.js b/packages/editor/src/components/block-list/index.js index 093b93740b6e9..5b89974d2e009 100644 --- a/packages/editor/src/components/block-list/index.js +++ b/packages/editor/src/components/block-list/index.js @@ -9,7 +9,6 @@ import { sortBy, throttle, } from 'lodash'; -import classnames from 'classnames'; /** * WordPress dependencies @@ -188,23 +187,12 @@ class BlockList extends Component { render() { const { blockClientIds, - layout, - isGroupedByLayout, rootClientId, isDraggable, } = this.props; - let defaultLayout; - if ( isGroupedByLayout ) { - defaultLayout = layout; - } - - const classes = classnames( 'editor-block-list__layout', { - [ `layout-${ layout }` ]: layout, - } ); - return ( -
+
{ map( blockClientIds, ( clientId, blockIndex ) => ( ) ) } - - +
); } diff --git a/packages/editor/src/components/block-list/insertion-point.js b/packages/editor/src/components/block-list/insertion-point.js index 022423d64014b..f6d52d8084035 100644 --- a/packages/editor/src/components/block-list/insertion-point.js +++ b/packages/editor/src/components/block-list/insertion-point.js @@ -42,8 +42,8 @@ class BlockInsertionPoint extends Component { } onClick() { - const { layout, rootClientId, index, ...props } = this.props; - props.insertDefaultBlock( { layout }, rootClientId, index ); + const { rootClientId, index, ...props } = this.props; + props.insertDefaultBlock( undefined, rootClientId, index ); props.startTyping(); this.onBlurInserter(); if ( props.onInsert ) { diff --git a/packages/editor/src/components/default-block-appender/index.js b/packages/editor/src/components/default-block-appender/index.js index f850fff57f1d5..dd6817b674cfe 100644 --- a/packages/editor/src/components/default-block-appender/index.js +++ b/packages/editor/src/components/default-block-appender/index.js @@ -25,7 +25,6 @@ export function DefaultBlockAppender( { onAppend, showPrompt, placeholder, - layout, rootClientId, } ) { if ( isLocked || ! isVisible ) { @@ -51,7 +50,7 @@ export function DefaultBlockAppender( { return (
- + - +
); @@ -91,14 +90,9 @@ export default compose( return { onAppend() { - const { layout, rootClientId } = ownProps; + const { rootClientId } = ownProps; - let attributes; - if ( layout ) { - attributes = { layout }; - } - - insertDefaultBlock( attributes, rootClientId ); + insertDefaultBlock( undefined, rootClientId ); startTyping(); }, }; diff --git a/packages/editor/src/components/inner-blocks/README.md b/packages/editor/src/components/inner-blocks/README.md index 5659a9cead961..494fb750fb74c 100644 --- a/packages/editor/src/components/inner-blocks/README.md +++ b/packages/editor/src/components/inner-blocks/README.md @@ -7,9 +7,7 @@ Refer to the [implementation of the Columns block](https://github.com/WordPress/ ## Usage -In a block's `edit` implementation, render `InnerBlocks`, optionally with `layouts` of available nest areas: - -Then, in the `save` implementation, render `InnerBlocks.Content`. This will be replaced automatically with the content of the nested blocks. +In a block's `edit` implementation, render `InnerBlocks`. Then, in the `save` implementation, render `InnerBlocks.Content`. This will be replaced automatically with the content of the nested blocks. ```jsx import { registerBlockType } from '@wordpress/blocks'; @@ -36,7 +34,7 @@ registerBlockType( 'my-plugin/my-block', { } ); ``` -_Note:_ A block can render at most a single `InnerBlocks` and `InnerBlocks.Content` element in `edit` and `save` respectively. To create distinct arrangements of nested blocks, refer to the `layouts` prop documented below. +_Note:_ A block can render at most a single `InnerBlocks` and `InnerBlocks.Content` element in `edit` and `save` respectively. To create distinct arrangements of nested blocks, create a separate block type which renders its own `InnerBlocks` and assign as the sole `allowedBlocks` type. _Note:_ Because the save step will automatically apply props to the element returned by `save`, it is important to include the wrapping `div` in the above simple example even though we are applying no props of our own. In a real-world example, you may have your own attributes to apply to the saved markup, or sibling content adjacent to the rendered nested blocks. @@ -107,25 +105,3 @@ Template locking allows locking the `InnerBlocks` area for the current template. If locking is not set in an `InnerBlocks` area: the locking of the parent `InnerBlocks` area is used. If the block is a top level block: the locking of the Custom Post Type is used. - -### `layouts` -* **Type:** `Array|Object` - -To achieve distinct arrangements of nested blocks, you may assign layout as an object. When assigned, the rendered output will assign a layout-specific class which can be used in your block stylesheet to effect the visual arrangement of nested blocks. - -A layout is an object where each key is the `slug` of the layout and its value an object consisting of: - -- Icon (`icon: string`): The slug of the Dashicon to use in controls presented to the user in moving between layouts - - Reference: https://developer.wordpress.org/resource/dashicons/ -- Label (`label: string`): The text to display in the controls presented to the user in moving between layouts - -The `slug` is also used to create the class name for the block. A slug of `normal` would output the class `"layout-normal"`. - -**Example:** - -```jsx - -``` diff --git a/packages/editor/src/components/inner-blocks/index.js b/packages/editor/src/components/inner-blocks/index.js index 9108743838c10..0c06acd345eb5 100644 --- a/packages/editor/src/components/inner-blocks/index.js +++ b/packages/editor/src/components/inner-blocks/index.js @@ -93,7 +93,6 @@ class InnerBlocks extends Component { render() { const { clientId, - layouts, allowedBlocks, templateLock, template, @@ -109,7 +108,7 @@ class InnerBlocks extends Component {
); diff --git a/packages/editor/src/components/inserter-with-shortcuts/index.js b/packages/editor/src/components/inserter-with-shortcuts/index.js index 2082eadffaaf5..7fb8d68b51b21 100644 --- a/packages/editor/src/components/inserter-with-shortcuts/index.js +++ b/packages/editor/src/components/inserter-with-shortcuts/index.js @@ -56,11 +56,11 @@ export default compose( }; } ), withDispatch( ( dispatch, ownProps ) => { - const { clientId, rootClientId, layout } = ownProps; + const { clientId, rootClientId } = ownProps; return { onInsert( { name, initialAttributes } ) { - const block = createBlock( name, { ...initialAttributes, layout } ); + const block = createBlock( name, initialAttributes ); if ( clientId ) { dispatch( 'core/editor' ).replaceBlocks( clientId, block ); } else { diff --git a/packages/editor/src/components/inserter/index.js b/packages/editor/src/components/inserter/index.js index 92df06eeda445..d10f70e315af2 100644 --- a/packages/editor/src/components/inserter/index.js +++ b/packages/editor/src/components/inserter/index.js @@ -86,7 +86,7 @@ class Inserter extends Component { } export default compose( [ - withSelect( ( select, { rootClientId, layout } ) => { + withSelect( ( select, { rootClientId } ) => { const { getEditedPostAttribute, getBlockInsertionPoint, @@ -101,23 +101,22 @@ export default compose( [ // Otherwise, the default behavior for an undefined index is to // append block to the end of the rootClientId context. const insertionPoint = getBlockInsertionPoint(); - ( { rootClientId, layout, index } = insertionPoint ); + ( { rootClientId, index } = insertionPoint ); } return { title: getEditedPostAttribute( 'title' ), selectedBlock: getSelectedBlock(), items: getInserterItems( rootClientId ), - layout, index, rootClientId, }; } ), withDispatch( ( dispatch, ownProps ) => ( { onInsertBlock: ( item ) => { - const { selectedBlock, index, rootClientId, layout } = ownProps; + const { selectedBlock, index, rootClientId } = ownProps; const { name, initialAttributes } = item; - const insertedBlock = createBlock( name, { ...initialAttributes, layout } ); + const insertedBlock = createBlock( name, initialAttributes ); if ( selectedBlock && isUnmodifiedDefaultBlock( selectedBlock ) ) { return dispatch( 'core/editor' ).replaceBlocks( selectedBlock.clientId, insertedBlock ); } diff --git a/packages/editor/src/hooks/index.js b/packages/editor/src/hooks/index.js index e464747bf6e95..e0a1ee626d672 100644 --- a/packages/editor/src/hooks/index.js +++ b/packages/editor/src/hooks/index.js @@ -6,4 +6,3 @@ import './anchor'; import './custom-class-name'; import './default-autocompleters'; import './generated-class-name'; -import './layout'; diff --git a/packages/editor/src/hooks/layout.js b/packages/editor/src/hooks/layout.js deleted file mode 100644 index 5a92d73b1269e..0000000000000 --- a/packages/editor/src/hooks/layout.js +++ /dev/null @@ -1,88 +0,0 @@ -/** - * External dependencies - */ -import { assign, compact, get, without } from 'lodash'; - -/** - * WordPress dependencies - */ -import { addFilter } from '@wordpress/hooks'; - -/** - * Filters registered block settings, extending attributes with layout. - * - * @param {Object} settings Original block settings. - * - * @return {Object} Filtered block settings. - */ -export function addAttribute( settings ) { - // Use Lodash's assign to gracefully handle if attributes are undefined - settings.attributes = assign( settings.attributes, { - layout: { - type: 'string', - }, - } ); - - return settings; -} - -/** - * Override props assigned to save component to inject layout class. This is - * only applied if the block's save result is an element and not a markup - * string. - * - * @param {Object} extraProps Additional props applied to save element. - * @param {Object} blockType Block type. - * @param {Object} attributes Current block attributes. - * - * @return {Object} Filtered props applied to save element. - */ -export function addSaveProps( extraProps, blockType, attributes ) { - const { layout } = attributes; - if ( layout ) { - extraProps.className = compact( [ - extraProps.className, - 'layout-' + layout, - ] ).join( ' ' ); - } - - return extraProps; -} - -/** - * Given a transformed block, assigns the layout from the original block. Since - * layout is a "global" attribute implemented via hooks, the individual block - * transforms are not expected to handle this themselves, and a transform would - * otherwise lose assigned layout. - * - * @param {Object} transformedBlock Original transformed block. - * @param {Object} blocks Blocks on which transform was applied. - * - * @return {Object} Modified transformed block, with layout preserved. - */ -function preserveLayoutAttribute( transformedBlock, blocks ) { - // Since block transforms are many-to-many, use the layout attribute from - // the first of the source blocks. - const layout = get( blocks, [ 0, 'attributes', 'layout' ] ); - - transformedBlock.attributes.layout = layout; - - return transformedBlock; -} - -/** - * Excludes the layout from the list of attributes to check - * when determining if a block is unmodified or not. - * - * @param {Object} attributeKeys Attribute keys to check - * - * @return {Object} Modified list of attribute keys - */ -function excludeLayoutFromUnmodifiedBlockCheck( attributeKeys ) { - return without( attributeKeys, 'layout' ); -} - -addFilter( 'blocks.registerBlockType', 'core/layout/attribute', addAttribute ); -addFilter( 'blocks.getSaveContent.extraProps', 'core/layout/save-props', addSaveProps ); -addFilter( 'blocks.switchToBlockType.transformedBlock', 'core/layout/preserve-layout', preserveLayoutAttribute ); -addFilter( 'blocks.isUnmodifiedDefaultBlock.attributes', 'core/layout/exclude-layout-attribute-check', excludeLayoutFromUnmodifiedBlockCheck ); diff --git a/packages/editor/src/hooks/test/layout.js b/packages/editor/src/hooks/test/layout.js deleted file mode 100644 index cc5e6a5b0ba49..0000000000000 --- a/packages/editor/src/hooks/test/layout.js +++ /dev/null @@ -1,66 +0,0 @@ -/** - * External dependencies - */ -import { noop } from 'lodash'; - -/** - * WordPress dependencies - */ -import { applyFilters } from '@wordpress/hooks'; - -/** - * Internal dependencies - */ -import '../layout'; - -describe( 'layout', () => { - const blockSettings = { - save: noop, - category: 'common', - title: 'block title', - }; - - describe( 'addAttribute()', () => { - const registerBlockType = applyFilters.bind( null, 'blocks.registerBlockType' ); - - it( 'should assign a new layout attribute', () => { - const settings = registerBlockType( blockSettings ); - - expect( settings.attributes ).toHaveProperty( 'layout' ); - } ); - } ); - - describe( 'addSaveProps', () => { - const getSaveContentExtraProps = applyFilters.bind( null, 'blocks.getSaveContent.extraProps' ); - - it( 'should merge layout class name', () => { - const attributes = { layout: 'wide' }; - const extraProps = getSaveContentExtraProps( { - className: 'wizard', - }, blockSettings, attributes ); - - expect( extraProps.className ).toBe( 'wizard layout-wide' ); - } ); - } ); - - describe( 'preserveLayoutAttribute', () => { - const transformBlock = applyFilters.bind( null, 'blocks.switchToBlockType.transformedBlock' ); - - it( 'should preserve layout attribute', () => { - const blocks = [ { attributes: { layout: 'wide' } } ]; - const transformedBlock = transformBlock( { attributes: {} }, blocks ); - - expect( transformedBlock.attributes.layout ).toBe( 'wide' ); - } ); - } ); - - describe( 'excludeLayoutFromUnmodifiedBlockCheck', () => { - const excludeLayoutAttribute = applyFilters.bind( null, 'blocks.isUnmodifiedDefaultBlock.attributes' ); - - it( 'should exclude the layout attribute', () => { - const attributeKeys = excludeLayoutAttribute( [ 'align', 'content', 'layout' ] ); - - expect( attributeKeys ).toEqual( [ 'align', 'content' ] ); - } ); - } ); -} ); diff --git a/packages/editor/src/store/actions.js b/packages/editor/src/store/actions.js index d074b85ae3d4e..bf2fd1f7a7340 100644 --- a/packages/editor/src/store/actions.js +++ b/packages/editor/src/store/actions.js @@ -277,19 +277,17 @@ export const moveBlocksUp = createOnMove( 'MOVE_BLOCKS_UP' ); * @param {?string} clientId The client ID of the block. * @param {?string} fromRootClientId Root client ID source. * @param {?string} toRootClientId Root client ID destination. - * @param {?string} layout Layout to move the block into. * @param {number} index The index to move the block into. * * @return {Object} Action object. */ -export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, layout, index ) { +export function moveBlockToPosition( clientId, fromRootClientId, toRootClientId, index ) { return { type: 'MOVE_BLOCK_TO_POSITION', fromRootClientId, toRootClientId, clientId, index, - layout, }; } diff --git a/packages/editor/src/store/effects/reusable-blocks.js b/packages/editor/src/store/effects/reusable-blocks.js index 0cf9469ff19e2..861c1821498ce 100644 --- a/packages/editor/src/store/effects/reusable-blocks.js +++ b/packages/editor/src/store/effects/reusable-blocks.js @@ -282,7 +282,6 @@ export const convertBlockToReusable = ( action, store ) => { action.clientIds, createBlock( 'core/block', { ref: reusableBlock.id, - layout: parsedBlock.attributes.layout, } ) ) ); diff --git a/packages/editor/src/store/reducer.js b/packages/editor/src/store/reducer.js index e3472344f58c1..306451865409e 100644 --- a/packages/editor/src/store/reducer.js +++ b/packages/editor/src/store/reducer.js @@ -324,23 +324,6 @@ export const editor = flow( [ }, }; - case 'MOVE_BLOCK_TO_POSITION': - // Avoid creating a new instance if the layout didn't change. - if ( state[ action.clientId ].attributes.layout === action.layout ) { - return state; - } - - return { - ...state, - [ action.clientId ]: { - ...state[ action.clientId ], - attributes: { - ...state[ action.clientId ].attributes, - layout: action.layout, - }, - }, - }; - case 'UPDATE_BLOCK': // Ignore updates if block isn't known if ( ! state[ action.clientId ] ) { diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index df1ccae61d91d..1c5036e3d73cc 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1272,23 +1272,20 @@ export function isCaretWithinFormattedText( state ) { * * @param {Object} state Editor state. * - * @return {Object} Insertion point object with `rootClientId`, `layout`, - * `index`. + * @return {Object} Insertion point object with `rootClientId`, `index`. */ export function getBlockInsertionPoint( state ) { - let rootClientId, layout, index; + let rootClientId, index; const { end } = state.blockSelection; if ( end ) { rootClientId = getBlockRootClientId( state, end ) || undefined; - - layout = get( getBlock( state, end ), [ 'attributes', 'layout' ] ); index = getBlockIndex( state, end, rootClientId ) + 1; } else { index = getBlockOrder( state ).length; } - return { rootClientId, layout, index }; + return { rootClientId, index }; } /** diff --git a/packages/editor/src/store/test/selectors.js b/packages/editor/src/store/test/selectors.js index bd348c1357ead..f94b4c407e345 100644 --- a/packages/editor/src/store/test/selectors.js +++ b/packages/editor/src/store/test/selectors.js @@ -2786,7 +2786,6 @@ describe( 'selectors', () => { expect( getBlockInsertionPoint( state ) ).toEqual( { rootClientId: undefined, - layout: undefined, index: 1, } ); } ); @@ -2818,37 +2817,6 @@ describe( 'selectors', () => { expect( getBlockInsertionPoint( state ) ).toEqual( { rootClientId: 'clientId1', - layout: undefined, - index: 1, - } ); - } ); - - it( 'should return an object for the selected block with layout', () => { - const state = { - currentPost: {}, - preferences: { mode: 'visual' }, - blockSelection: { - start: 'clientId1', - end: 'clientId1', - }, - editor: { - present: { - blocksByClientId: { - clientId1: { clientId: 'clientId1', attributes: { layout: 'wide' } }, - }, - blockOrder: { - '': [ 'clientId1' ], - clientId1: [], - }, - edits: {}, - }, - }, - isInsertionPointVisible: false, - }; - - expect( getBlockInsertionPoint( state ) ).toEqual( { - rootClientId: undefined, - layout: 'wide', index: 1, } ); } ); @@ -2880,7 +2848,6 @@ describe( 'selectors', () => { expect( getBlockInsertionPoint( state ) ).toEqual( { rootClientId: undefined, - layout: undefined, index: 2, } ); } ); @@ -2912,7 +2879,6 @@ describe( 'selectors', () => { expect( getBlockInsertionPoint( state ) ).toEqual( { rootClientId: undefined, - layout: undefined, index: 2, } ); } ); diff --git a/packages/editor/src/utils/test/dom.js b/packages/editor/src/utils/test/dom.js index 69be43576373f..cb42bbab841e4 100644 --- a/packages/editor/src/utils/test/dom.js +++ b/packages/editor/src/utils/test/dom.js @@ -24,8 +24,8 @@ describe( 'hasInnerBlocksContext()', () => { '
' + '
' + '
' + - '
' + - '
' + + '
' + + '
' + '
' + '
' + '
' From 45cb51784738a0934a46066ac92c89ee92ba8b31 Mon Sep 17 00:00:00 2001 From: Andrew Duthie Date: Mon, 29 Oct 2018 10:50:39 -0400 Subject: [PATCH 4/4] Blocks: Restore and test Columns migration --- packages/block-library/src/columns/index.js | 63 ++++++++++---- .../fixtures/core__columns__deprecated.html | 16 ++++ .../fixtures/core__columns__deprecated.json | 85 +++++++++++++++++++ .../core__columns__deprecated.parsed.json | 49 +++++++++++ .../core__columns__deprecated.serialized.html | 23 +++++ .../full-content/full-content.spec.js | 10 ++- 6 files changed, 227 insertions(+), 19 deletions(-) create mode 100644 test/integration/full-content/fixtures/core__columns__deprecated.html create mode 100644 test/integration/full-content/fixtures/core__columns__deprecated.json create mode 100644 test/integration/full-content/fixtures/core__columns__deprecated.parsed.json create mode 100644 test/integration/full-content/fixtures/core__columns__deprecated.serialized.html diff --git a/packages/block-library/src/columns/index.js b/packages/block-library/src/columns/index.js index a18e7b3909da8..3b9d5b76c4f0a 100644 --- a/packages/block-library/src/columns/index.js +++ b/packages/block-library/src/columns/index.js @@ -1,7 +1,7 @@ /** * External dependencies */ -import { times, property, omit } from 'lodash'; +import { times } from 'lodash'; import classnames from 'classnames'; import memoize from 'memize'; @@ -39,6 +39,32 @@ const getColumnsTemplate = memoize( ( columns ) => { return times( columns, () => [ 'core/column' ] ); } ); +/** + * Given an HTML string for a deprecated columns inner block, returns the + * column index to which the migrated inner block should be assigned. Returns + * undefined if the inner block was not assigned to a column. + * + * @param {string} originalContent Deprecated Columns inner block HTML. + * + * @return {?number} Column to which inner block is to be assigned. + */ +function getDeprecatedLayoutColumn( originalContent ) { + let { doc } = getDeprecatedLayoutColumn; + if ( ! doc ) { + doc = document.implementation.createHTMLDocument( '' ); + getDeprecatedLayoutColumn.doc = doc; + } + + let columnMatch; + + doc.body.innerHTML = originalContent; + for ( const classListItem of doc.body.firstChild.classList ) { + if ( ( columnMatch = classListItem.match( /^layout-column-(\d+)$/ ) ) ) { + return Number( columnMatch[ 1 ] ) - 1; + } + } +} + export const name = 'core/columns'; export const settings = { @@ -70,23 +96,30 @@ export const settings = { }, }, isEligible( attributes, innerBlocks ) { - return innerBlocks.some( property( [ 'attributes', 'layout' ] ) ); - }, - migrate( attributes, innerBlocks ) { - function withoutLayout( block ) { - return { - ...block, - attributes: omit( block.attributes, [ 'layout' ] ), - }; + // Since isEligible is called on every valid instance of the + // Columns block and a deprecation is the unlikely case due to + // its subsequent migration, optimize for the `false` condition + // by performing a naive, inaccurate pass at inner blocks. + const isFastPassEligible = innerBlocks.some( ( innerBlock ) => ( + /layout-column-\d+/.test( innerBlock.originalContent ) + ) ); + + if ( ! isFastPassEligible ) { + return false; } + // Only if the fast pass is considered eligible is the more + // accurate, durable, slower condition performed. + return innerBlocks.some( ( innerBlock ) => ( + getDeprecatedLayoutColumn( innerBlock.originalContent ) !== undefined + ) ); + }, + migrate( attributes, innerBlocks ) { const columns = innerBlocks.reduce( ( result, innerBlock ) => { - const { layout } = innerBlock.attributes; + const { originalContent } = innerBlock; - let columnIndex, columnMatch; - if ( layout && ( columnMatch = layout.match( /^column-(\d+)$/ ) ) ) { - columnIndex = Number( columnMatch[ 1 ] ) - 1; - } else { + let columnIndex = getDeprecatedLayoutColumn( originalContent ); + if ( columnIndex === undefined ) { columnIndex = 0; } @@ -94,7 +127,7 @@ export const settings = { result[ columnIndex ] = []; } - result[ columnIndex ].push( withoutLayout( innerBlock ) ); + result[ columnIndex ].push( innerBlock ); return result; }, [] ); diff --git a/test/integration/full-content/fixtures/core__columns__deprecated.html b/test/integration/full-content/fixtures/core__columns__deprecated.html new file mode 100644 index 0000000000000..ae96a2e33b146 --- /dev/null +++ b/test/integration/full-content/fixtures/core__columns__deprecated.html @@ -0,0 +1,16 @@ + +
+ +

Column One, Paragraph One

+ + +

Column One, Paragraph Two

+ + +

Column Two, Paragraph One

+ + +

Column Three, Paragraph One

+ +
+ diff --git a/test/integration/full-content/fixtures/core__columns__deprecated.json b/test/integration/full-content/fixtures/core__columns__deprecated.json new file mode 100644 index 0000000000000..6993fb5da69c4 --- /dev/null +++ b/test/integration/full-content/fixtures/core__columns__deprecated.json @@ -0,0 +1,85 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/columns", + "isValid": true, + "attributes": { + "columns": 3 + }, + "innerBlocks": [ + { + "clientId": "_clientId_0", + "name": "core/column", + "isValid": true, + "attributes": {}, + "innerBlocks": [ + { + "clientId": "_clientId_0", + "name": "core/paragraph", + "isValid": true, + "attributes": { + "content": "Column One, Paragraph One", + "dropCap": false, + "className": "layout-column-1" + }, + "innerBlocks": [], + "originalContent": "

Column One, Paragraph One

" + }, + { + "clientId": "_clientId_1", + "name": "core/paragraph", + "isValid": true, + "attributes": { + "content": "Column One, Paragraph Two", + "dropCap": false, + "className": "layout-column-1" + }, + "innerBlocks": [], + "originalContent": "

Column One, Paragraph Two

" + } + ] + }, + { + "clientId": "_clientId_1", + "name": "core/column", + "isValid": true, + "attributes": {}, + "innerBlocks": [ + { + "clientId": "_clientId_0", + "name": "core/paragraph", + "isValid": true, + "attributes": { + "content": "Column Two, Paragraph One", + "dropCap": false, + "className": "layout-column-2" + }, + "innerBlocks": [], + "originalContent": "

Column Two, Paragraph One

" + } + ] + }, + { + "clientId": "_clientId_2", + "name": "core/column", + "isValid": true, + "attributes": {}, + "innerBlocks": [ + { + "clientId": "_clientId_0", + "name": "core/paragraph", + "isValid": true, + "attributes": { + "content": "Column Three, Paragraph One", + "dropCap": false, + "className": "layout-column-3" + }, + "innerBlocks": [], + "originalContent": "

Column Three, Paragraph One

" + } + ] + } + ], + "originalContent": "
\n\t\n\t\n\t\n\t\n
" + } +] diff --git a/test/integration/full-content/fixtures/core__columns__deprecated.parsed.json b/test/integration/full-content/fixtures/core__columns__deprecated.parsed.json new file mode 100644 index 0000000000000..2d973027f4a5a --- /dev/null +++ b/test/integration/full-content/fixtures/core__columns__deprecated.parsed.json @@ -0,0 +1,49 @@ +[ + { + "blockName": "core/columns", + "attrs": { + "columns": 3 + }, + "innerBlocks": [ + { + "blockName": "core/paragraph", + "attrs": { + "layout": "column-1" + }, + "innerBlocks": [], + "innerHTML": "\n\t

Column One, Paragraph One

\n\t" + }, + { + "blockName": "core/paragraph", + "attrs": { + "layout": "column-1" + }, + "innerBlocks": [], + "innerHTML": "\n\t

Column One, Paragraph Two

\n\t" + }, + { + "blockName": "core/paragraph", + "attrs": { + "layout": "column-2" + }, + "innerBlocks": [], + "innerHTML": "\n\t

Column Two, Paragraph One

\n\t" + }, + { + "blockName": "core/paragraph", + "attrs": { + "layout": "column-3" + }, + "innerBlocks": [], + "innerHTML": "\n\t

Column Three, Paragraph One

\n\t" + } + ], + "innerHTML": "\n
\n\t\n\t\n\t\n\t\n
\n" + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n" + } +] diff --git a/test/integration/full-content/fixtures/core__columns__deprecated.serialized.html b/test/integration/full-content/fixtures/core__columns__deprecated.serialized.html new file mode 100644 index 0000000000000..88041c92cb39d --- /dev/null +++ b/test/integration/full-content/fixtures/core__columns__deprecated.serialized.html @@ -0,0 +1,23 @@ + +
+
+

Column One, Paragraph One

+ + + +

Column One, Paragraph Two

+
+ + + +
+

Column Two, Paragraph One

+
+ + + +
+

Column Three, Paragraph One

+
+
+ diff --git a/test/integration/full-content/full-content.spec.js b/test/integration/full-content/full-content.spec.js index 99ae5c7f252a9..42132dea401bc 100644 --- a/test/integration/full-content/full-content.spec.js +++ b/test/integration/full-content/full-content.spec.js @@ -117,13 +117,15 @@ describe( 'full post content fixture', () => { const blocksActual = parse( content ); - // Block validation logs during deprecation migration. Since this - // is expected for deprecated blocks, match on filename and allow. + // Block validation may log errors during deprecation migration, + // unless explicitly handled from a valid block via isEligible. + // Match on filename for deprecated blocks fixtures to allow. const isDeprecated = /__deprecated([-_]|$)/.test( f ); if ( isDeprecated ) { - // eslint-disable-next-line no-console + /* eslint-disable no-console */ console.warn.mockReset(); - expect( console ).toHaveErrored(); + console.error.mockReset(); + /* eslint-enable no-console */ } const blocksActualNormalized = normalizeParsedBlocks( blocksActual );