From 5174a52742e53875eaa176b701ece1d605979205 Mon Sep 17 00:00:00 2001 From: Zebulan Stanphill Date: Sun, 14 Jun 2020 17:22:30 -0500 Subject: [PATCH] Buttons block: remove block alignment options. --- lib/patterns/two-buttons.php | 2 +- packages/block-library/src/buttons/block.json | 2 - .../block-library/src/buttons/deprecated.js | 30 +++++++++++++ .../block-library/src/buttons/edit.native.js | 3 -- packages/block-library/src/buttons/index.js | 2 + .../fixtures/blocks/core__buttons.html | 4 +- .../fixtures/blocks/core__buttons.json | 8 ++-- .../fixtures/blocks/core__buttons.parsed.json | 8 ++-- .../blocks/core__buttons.serialized.html | 4 +- .../blocks/core__buttons__deprecated.html | 11 +++++ .../blocks/core__buttons__deprecated.json | 33 ++++++++++++++ .../core__buttons__deprecated.parsed.json | 45 +++++++++++++++++++ .../core__buttons__deprecated.serialized.html | 9 ++++ .../adding-patterns.test.js.snap | 4 +- 14 files changed, 145 insertions(+), 20 deletions(-) create mode 100644 packages/block-library/src/buttons/deprecated.js create mode 100644 packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.html create mode 100644 packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.parsed.json create mode 100644 packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.serialized.html diff --git a/lib/patterns/two-buttons.php b/lib/patterns/two-buttons.php index ff434b858782d1..0cebc9dfe8fa9b 100644 --- a/lib/patterns/two-buttons.php +++ b/lib/patterns/two-buttons.php @@ -7,7 +7,7 @@ return array( 'title' => __( 'Two Buttons', 'gutenberg' ), - 'content' => "\n
\n\n\n\n\n\n
\n", + 'content' => "\n
\n\n\n\n\n\n
\n", 'viewportWidth' => 500, 'categories' => array( 'buttons' ), ); diff --git a/packages/block-library/src/buttons/block.json b/packages/block-library/src/buttons/block.json index 4004a9591a99e6..3751e2960bd9c6 100644 --- a/packages/block-library/src/buttons/block.json +++ b/packages/block-library/src/buttons/block.json @@ -2,8 +2,6 @@ "name": "core/buttons", "category": "design", "supports": { - "align": true, - "alignWide": false, "lightBlockWrapper": true } } diff --git a/packages/block-library/src/buttons/deprecated.js b/packages/block-library/src/buttons/deprecated.js new file mode 100644 index 00000000000000..cf0e9d6b0f6ac2 --- /dev/null +++ b/packages/block-library/src/buttons/deprecated.js @@ -0,0 +1,30 @@ +/** + * External dependencies + */ +import { omit } from 'lodash'; + +/** + * WordPress dependencies + */ +import { InnerBlocks } from '@wordpress/block-editor'; + +const deprecated = [ + { + supports: { + align: true, + alignWide: false, + }, + save() { + return ( +
+ +
+ ); + }, + migrate( attributes ) { + return omit( attributes, [ 'align' ] ); + }, + }, +]; + +export default deprecated; diff --git a/packages/block-library/src/buttons/edit.native.js b/packages/block-library/src/buttons/edit.native.js index 9e28f7c3e0b6a5..a5d9394ceeaeec 100644 --- a/packages/block-library/src/buttons/edit.native.js +++ b/packages/block-library/src/buttons/edit.native.js @@ -25,13 +25,11 @@ const BUTTONS_TEMPLATE = [ [ 'core/button' ] ]; function ButtonsEdit( { isSelected, - attributes, onDelete, onAddNextButton, shouldDelete, isInnerButtonSelected, } ) { - const { align } = attributes; const [ resizeObserver, sizes ] = useResizeObserver(); const [ maxWidth, setMaxWidth ] = useState( 0 ); const shouldRenderFooterAppender = isSelected || isInnerButtonSelected; @@ -69,7 +67,6 @@ function ButtonsEdit( { shouldRenderFooterAppender && renderFooterAppender.current } __experimentalMoverDirection="horizontal" - horizontalAlignment={ align } onDeleteBlock={ shouldDelete ? onDelete : undefined } onAddBlock={ onAddNextButton } parentWidth={ maxWidth } diff --git a/packages/block-library/src/buttons/index.js b/packages/block-library/src/buttons/index.js index 68f51a5a476b99..d7478df2bd9916 100644 --- a/packages/block-library/src/buttons/index.js +++ b/packages/block-library/src/buttons/index.js @@ -7,6 +7,7 @@ import { button as icon } from '@wordpress/icons'; /** * Internal dependencies */ +import deprecated from './deprecated'; import transforms from './transforms'; import edit from './edit'; import metadata from './block.json'; @@ -23,6 +24,7 @@ export const settings = { ), icon, keywords: [ __( 'link' ) ], + deprecated, transforms, edit, save, diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.html b/packages/e2e-tests/fixtures/blocks/core__buttons.html index e70af7acc72ad4..4e0a4e6ef67087 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.html +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.html @@ -1,11 +1,11 @@
- + - +
diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.json b/packages/e2e-tests/fixtures/blocks/core__buttons.json index 044daeb82101ac..8b23652b2b25c3 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.json +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.json @@ -10,20 +10,20 @@ "name": "core/button", "isValid": true, "attributes": { - "text": "My button 1" + "text": "first" }, "innerBlocks": [], - "originalContent": "
My button 1
" + "originalContent": "
first
" }, { "clientId": "_clientId_1", "name": "core/button", "isValid": true, "attributes": { - "text": "My button 2" + "text": "second" }, "innerBlocks": [], - "originalContent": "
My button 2
" + "originalContent": "
second
" } ], "originalContent": "
\n\t\n\n\t\n
" diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json b/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json index b96b1f50db1fc9..7958bb59226637 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.parsed.json @@ -7,18 +7,18 @@ "blockName": "core/button", "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\t
My button 1
\n\t", + "innerHTML": "\n\t
first
\n\t", "innerContent": [ - "\n\t
My button 1
\n\t" + "\n\t
first
\n\t" ] }, { "blockName": "core/button", "attrs": {}, "innerBlocks": [], - "innerHTML": "\n\t
My button 2
\n\t", + "innerHTML": "\n\t
second
\n\t", "innerContent": [ - "\n\t
My button 2
\n\t" + "\n\t
second
\n\t" ] } ], diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons.serialized.html b/packages/e2e-tests/fixtures/blocks/core__buttons.serialized.html index baf0a0226c066c..b0c6e5a3941684 100644 --- a/packages/e2e-tests/fixtures/blocks/core__buttons.serialized.html +++ b/packages/e2e-tests/fixtures/blocks/core__buttons.serialized.html @@ -1,9 +1,9 @@
- + - +
diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.html b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.html new file mode 100644 index 00000000000000..d1720846455475 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.html @@ -0,0 +1,11 @@ + +
+ + + + + + + +
+ diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.json b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.json new file mode 100644 index 00000000000000..0c881758c296e1 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.json @@ -0,0 +1,33 @@ +[ + { + "clientId": "_clientId_0", + "name": "core/buttons", + "isValid": true, + "attributes": { + "className": "aligncenter" + }, + "innerBlocks": [ + { + "clientId": "_clientId_0", + "name": "core/button", + "isValid": true, + "attributes": { + "text": "first" + }, + "innerBlocks": [], + "originalContent": "
first
" + }, + { + "clientId": "_clientId_1", + "name": "core/button", + "isValid": true, + "attributes": { + "text": "second" + }, + "innerBlocks": [], + "originalContent": "
second
" + } + ], + "originalContent": "
\n\t\n\n\t\n
" + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.parsed.json b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.parsed.json new file mode 100644 index 00000000000000..465624073eefc1 --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.parsed.json @@ -0,0 +1,45 @@ +[ + { + "blockName": "core/buttons", + "attrs": { + "align": "center" + }, + "innerBlocks": [ + { + "blockName": "core/button", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\t
first
\n\t", + "innerContent": [ + "\n\t
first
\n\t" + ] + }, + { + "blockName": "core/button", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n\t
second
\n\t", + "innerContent": [ + "\n\t
second
\n\t" + ] + } + ], + "innerHTML": "\n
\n\t\n\n\t\n
\n", + "innerContent": [ + "\n
\n\t", + null, + "\n\n\t", + null, + "\n
\n" + ] + }, + { + "blockName": null, + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n", + "innerContent": [ + "\n" + ] + } +] diff --git a/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.serialized.html b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.serialized.html new file mode 100644 index 00000000000000..fc47ec8898ea2c --- /dev/null +++ b/packages/e2e-tests/fixtures/blocks/core__buttons__deprecated.serialized.html @@ -0,0 +1,9 @@ + +
+ + + + + +
+ diff --git a/packages/e2e-tests/specs/editor/various/__snapshots__/adding-patterns.test.js.snap b/packages/e2e-tests/specs/editor/various/__snapshots__/adding-patterns.test.js.snap index 6edf4efa96041a..59c034c06ba605 100644 --- a/packages/e2e-tests/specs/editor/various/__snapshots__/adding-patterns.test.js.snap +++ b/packages/e2e-tests/specs/editor/various/__snapshots__/adding-patterns.test.js.snap @@ -1,8 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`adding blocks should insert a block pattern 1`] = ` -" -
+" +