From cdbd33b03040672c8af141e8e4c8c15f571170ef Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Wed, 20 Jan 2021 10:35:58 +0100 Subject: [PATCH] Enable alignments for all blocks by default --- .../src/components/inner-blocks/index.js | 12 ++++++++++-- .../src/components/inner-blocks/index.native.js | 12 ++++++++++-- .../src/components/inner-blocks/layout.js | 1 + packages/block-editor/src/hooks/align.js | 8 ++++---- packages/block-library/src/block/block.json | 1 + packages/block-library/src/column/block.json | 4 +--- packages/block-library/src/freeform/block.json | 3 ++- packages/block-library/src/html/block.json | 3 ++- packages/block-library/src/image/block.json | 1 + packages/block-library/src/more/block.json | 3 ++- packages/block-library/src/nextpage/block.json | 3 ++- packages/block-library/src/paragraph/block.json | 8 +++----- packages/block-library/src/quote/block.json | 3 ++- packages/block-library/src/shortcode/block.json | 3 ++- 14 files changed, 43 insertions(+), 22 deletions(-) diff --git a/packages/block-editor/src/components/inner-blocks/index.js b/packages/block-editor/src/components/inner-blocks/index.js index b8f3c72863318..22a32c68d27fc 100644 --- a/packages/block-editor/src/components/inner-blocks/index.js +++ b/packages/block-editor/src/components/inner-blocks/index.js @@ -27,7 +27,7 @@ import { BlockListItems } from '../block-list'; import { BlockContextProvider } from '../block-context'; import { useBlockEditContext } from '../block-edit/context'; import useBlockSync from '../provider/use-block-sync'; -import { defaultLayout, LayoutProvider } from './layout'; +import { defaultLayout, flexHorizontalLayout, LayoutProvider } from './layout'; /** * InnerBlocks is a component which allows a single block to have multiple blocks @@ -50,9 +50,17 @@ function UncontrolledInnerBlocks( props ) { renderAppender, orientation, placeholder, - __experimentalLayout: layout = defaultLayout, + __experimentalLayout, } = props; + let layout = __experimentalLayout; + if ( ! layout && orientation === 'horizontal' ) { + layout = flexHorizontalLayout; + } + if ( ! layout && orientation !== 'horizontal' ) { + layout = defaultLayout; + } + useNestedSettingsUpdate( clientId, allowedBlocks, diff --git a/packages/block-editor/src/components/inner-blocks/index.native.js b/packages/block-editor/src/components/inner-blocks/index.native.js index 13e6f2b506138..783a2ae4028ce 100644 --- a/packages/block-editor/src/components/inner-blocks/index.native.js +++ b/packages/block-editor/src/components/inner-blocks/index.native.js @@ -20,7 +20,7 @@ import BlockList from '../block-list'; import { useBlockEditContext } from '../block-edit/context'; import useBlockSync from '../provider/use-block-sync'; import { BlockContextProvider } from '../block-context'; -import { defaultLayout, LayoutProvider } from './layout'; +import { defaultLayout, flexHorizontalLayout, LayoutProvider } from './layout'; /** * InnerBlocks is a component which allows a single block to have multiple blocks @@ -51,9 +51,17 @@ function UncontrolledInnerBlocks( props ) { horizontalAlignment, filterInnerBlocks, blockWidth, - __experimentalLayout: layout = defaultLayout, + __experimentalLayout, } = props; + let layout = __experimentalLayout; + if ( ! layout && orientation === 'horizontal' ) { + layout = flexHorizontalLayout; + } + if ( ! layout && orientation !== 'horizontal' ) { + layout = defaultLayout; + } + const block = useSelect( ( select ) => select( 'core/block-editor' ).getBlock( clientId ), [ clientId ] diff --git a/packages/block-editor/src/components/inner-blocks/layout.js b/packages/block-editor/src/components/inner-blocks/layout.js index 745b59945ea61..4c59d11bccb7a 100644 --- a/packages/block-editor/src/components/inner-blocks/layout.js +++ b/packages/block-editor/src/components/inner-blocks/layout.js @@ -4,6 +4,7 @@ import { createContext, useContext } from '@wordpress/element'; export const defaultLayout = { type: 'default' }; +export const flexHorizontalLayout = { type: 'flex-horizontal' }; const Layout = createContext( defaultLayout ); diff --git a/packages/block-editor/src/hooks/align.js b/packages/block-editor/src/hooks/align.js index 67b8e80367333..d97f11a2e04da 100644 --- a/packages/block-editor/src/hooks/align.js +++ b/packages/block-editor/src/hooks/align.js @@ -89,7 +89,7 @@ export function addAttribute( settings ) { if ( has( settings.attributes, [ 'align', 'type' ] ) ) { return settings; } - if ( hasBlockSupport( settings, 'align' ) ) { + if ( hasBlockSupport( settings, 'align', true ) ) { // Gracefully handle if settings.attributes is undefined. settings.attributes = { ...settings.attributes, @@ -120,7 +120,7 @@ export const withToolbarControls = createHigherOrderComponent( // and without checking the layout for availble alignments. // BlockAlignmentToolbar takes both of these into account. const validAlignments = getValidAlignments( - getBlockSupport( blockName, 'align' ), + getBlockSupport( blockName, 'align', true ), hasBlockSupport( blockName, 'alignWide', true ) ); @@ -174,7 +174,7 @@ export const withDataAlign = createHigherOrderComponent( } const validAlignments = getValidAlignments( - getBlockSupport( name, 'align' ), + getBlockSupport( name, 'align', true ), hasBlockSupport( name, 'alignWide', true ), hasWideEnabled ); @@ -199,7 +199,7 @@ export const withDataAlign = createHigherOrderComponent( */ export function addAssignedAlign( props, blockType, attributes ) { const { align } = attributes; - const blockAlign = getBlockSupport( blockType, 'align' ); + const blockAlign = getBlockSupport( blockType, 'align', true ); const hasWideBlockSupport = hasBlockSupport( blockType, 'alignWide', true ); // Compute valid alignments without taking into account if diff --git a/packages/block-library/src/block/block.json b/packages/block-library/src/block/block.json index aece916ab601b..d8e7925f2b704 100644 --- a/packages/block-library/src/block/block.json +++ b/packages/block-library/src/block/block.json @@ -8,6 +8,7 @@ } }, "supports": { + "align": false, "customClassName": false, "html": false, "inserter": false diff --git a/packages/block-library/src/column/block.json b/packages/block-library/src/column/block.json index 02c2084dabb3f..5d29a9d809178 100644 --- a/packages/block-library/src/column/block.json +++ b/packages/block-library/src/column/block.json @@ -2,9 +2,7 @@ "apiVersion": 2, "name": "core/column", "category": "text", - "parent": [ - "core/columns" - ], + "parent": [ "core/columns" ], "attributes": { "verticalAlignment": { "type": "string" diff --git a/packages/block-library/src/freeform/block.json b/packages/block-library/src/freeform/block.json index a18cd84635004..4553624e3b036 100644 --- a/packages/block-library/src/freeform/block.json +++ b/packages/block-library/src/freeform/block.json @@ -11,7 +11,8 @@ "supports": { "className": false, "customClassName": false, - "reusable": false + "reusable": false, + "align": false }, "editorStyle": "wp-block-freeform-editor" } diff --git a/packages/block-library/src/html/block.json b/packages/block-library/src/html/block.json index 266b4511e0fe5..c3858fa1783fc 100644 --- a/packages/block-library/src/html/block.json +++ b/packages/block-library/src/html/block.json @@ -11,7 +11,8 @@ "supports": { "customClassName": false, "className": false, - "html": false + "html": false, + "align": false }, "editorStyle": "wp-block-html-editor" } diff --git a/packages/block-library/src/image/block.json b/packages/block-library/src/image/block.json index 02cfd21dfd9cd..2c5cffc34f858 100644 --- a/packages/block-library/src/image/block.json +++ b/packages/block-library/src/image/block.json @@ -71,6 +71,7 @@ } }, "supports": { + "align": false, "anchor": true }, "editorStyle": "wp-block-image-editor", diff --git a/packages/block-library/src/more/block.json b/packages/block-library/src/more/block.json index f49bbd58583a3..b5e93679639c3 100644 --- a/packages/block-library/src/more/block.json +++ b/packages/block-library/src/more/block.json @@ -15,7 +15,8 @@ "customClassName": false, "className": false, "html": false, - "multiple": false + "multiple": false, + "align": false }, "editorStyle": "wp-block-more-editor" } diff --git a/packages/block-library/src/nextpage/block.json b/packages/block-library/src/nextpage/block.json index f1a8a2745cb57..75bab3627f644 100644 --- a/packages/block-library/src/nextpage/block.json +++ b/packages/block-library/src/nextpage/block.json @@ -6,7 +6,8 @@ "supports": { "customClassName": false, "className": false, - "html": false + "html": false, + "align": false }, "editorStyle": "wp-block-nextpage-editor" } diff --git a/packages/block-library/src/paragraph/block.json b/packages/block-library/src/paragraph/block.json index a29e22c01d5af..6744e2d403e82 100644 --- a/packages/block-library/src/paragraph/block.json +++ b/packages/block-library/src/paragraph/block.json @@ -21,10 +21,7 @@ }, "direction": { "type": "string", - "enum": [ - "ltr", - "rtl" - ] + "enum": [ "ltr", "rtl" ] } }, "supports": { @@ -36,7 +33,8 @@ "fontSize": true, "lineHeight": true, "__experimentalSelector": "p", - "__unstablePasteTextInline": true + "__unstablePasteTextInline": true, + "align": false }, "editorStyle": "wp-block-paragraph-editor", "style": "wp-block-paragraph" diff --git a/packages/block-library/src/quote/block.json b/packages/block-library/src/quote/block.json index bba83461367fa..51d1dfb5a6af6 100644 --- a/packages/block-library/src/quote/block.json +++ b/packages/block-library/src/quote/block.json @@ -21,7 +21,8 @@ } }, "supports": { - "anchor": true + "anchor": true, + "align": false }, "editorStyle": "wp-block-quote-editor", "style": "wp-block-quote" diff --git a/packages/block-library/src/shortcode/block.json b/packages/block-library/src/shortcode/block.json index 4f92abd419f6e..d2a814c27dee9 100644 --- a/packages/block-library/src/shortcode/block.json +++ b/packages/block-library/src/shortcode/block.json @@ -11,7 +11,8 @@ "supports": { "className": false, "customClassName": false, - "html": false + "html": false, + "align": false }, "editorStyle": "wp-block-shortcode-editor" }