From 54149f2b7b42ce13a7a39496e18c2caff23b16e1 Mon Sep 17 00:00:00 2001 From: Riad Benguella Date: Tue, 13 Jul 2021 14:16:20 +0100 Subject: [PATCH] Layout cleanup --- packages/block-library/src/group/edit.js | 2 +- .../block-library/src/post-content/edit.js | 19 ++----------------- .../block-library/src/query/edit/index.js | 19 ++----------------- .../src/template-part/edit/inner-blocks.js | 18 +----------------- .../src/components/visual-editor/index.js | 14 +++----------- 5 files changed, 9 insertions(+), 63 deletions(-) diff --git a/packages/block-library/src/group/edit.js b/packages/block-library/src/group/edit.js index 954acd18d1b4be..5628ea0105ce8d 100644 --- a/packages/block-library/src/group/edit.js +++ b/packages/block-library/src/group/edit.js @@ -39,7 +39,7 @@ function GroupEdit( { attributes, setAttributes, clientId } ) { renderAppender: hasInnerBlocks ? undefined : InnerBlocks.ButtonBlockAppender, - __experimentalLayout: usedLayout, + __experimentalLayout: themeSupportsLayout ? usedLayout : undefined, } ); diff --git a/packages/block-library/src/post-content/edit.js b/packages/block-library/src/post-content/edit.js index 537181c6b8cd83..6fb898fab3c444 100644 --- a/packages/block-library/src/post-content/edit.js +++ b/packages/block-library/src/post-content/edit.js @@ -3,7 +3,7 @@ */ import { __ } from '@wordpress/i18n'; import { useSelect } from '@wordpress/data'; -import { useMemo, RawHTML } from '@wordpress/element'; +import { RawHTML } from '@wordpress/element'; import { useBlockProps, __experimentalUseInnerBlocksProps as useInnerBlocksProps, @@ -46,21 +46,6 @@ function EditableContent( { layout, context = {} } ) { }, [] ); const defaultLayout = useSetting( 'layout' ) || {}; const usedLayout = !! layout && layout.inherit ? defaultLayout : layout; - const { contentSize, wideSize } = usedLayout; - const _layout = useMemo( () => { - if ( themeSupportsLayout ) { - const alignments = - contentSize || wideSize - ? [ 'wide', 'full', 'left', 'center', 'right' ] - : [ 'left', 'center', 'right' ]; - return { - type: 'default', - // Find a way to inject this in the support flag code (hooks). - alignments, - }; - } - return undefined; - }, [ themeSupportsLayout, contentSize, wideSize ] ); const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', postType, @@ -73,7 +58,7 @@ function EditableContent( { layout, context = {} } ) { value: blocks, onInput, onChange, - __experimentalLayout: _layout, + __experimentalLayout: themeSupportsLayout ? usedLayout : undefined, } ); return
; diff --git a/packages/block-library/src/query/edit/index.js b/packages/block-library/src/query/edit/index.js index b03d68aceae9ef..e297534ed8f797 100644 --- a/packages/block-library/src/query/edit/index.js +++ b/packages/block-library/src/query/edit/index.js @@ -4,7 +4,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { cloneBlock } from '@wordpress/blocks'; import { useInstanceId } from '@wordpress/compose'; -import { useEffect, useMemo } from '@wordpress/element'; +import { useEffect } from '@wordpress/element'; import { BlockControls, InspectorAdvancedControls, @@ -45,25 +45,10 @@ export function QueryContent( { attributes, setAttributes } ) { }, [] ); const defaultLayout = useSetting( 'layout' ) || {}; const usedLayout = !! layout && layout.inherit ? defaultLayout : layout; - const { contentSize, wideSize } = usedLayout; const blockProps = useBlockProps(); - const _layout = useMemo( () => { - if ( themeSupportsLayout ) { - const alignments = - contentSize || wideSize - ? [ 'wide', 'full', 'left', 'center', 'right' ] - : [ 'left', 'center', 'right' ]; - return { - type: 'default', - // Find a way to inject this in the support flag code (hooks). - alignments, - }; - } - return undefined; - }, [ themeSupportsLayout, contentSize, wideSize ] ); const innerBlocksProps = useInnerBlocksProps( blockProps, { template: TEMPLATE, - __experimentalLayout: _layout, + __experimentalLayout: themeSupportsLayout ? usedLayout : undefined, } ); const { postsPerPage } = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); diff --git a/packages/block-library/src/template-part/edit/inner-blocks.js b/packages/block-library/src/template-part/edit/inner-blocks.js index e55d7e6bdbe582..ba07a28e14f19f 100644 --- a/packages/block-library/src/template-part/edit/inner-blocks.js +++ b/packages/block-library/src/template-part/edit/inner-blocks.js @@ -10,7 +10,6 @@ import { store as blockEditorStore, } from '@wordpress/block-editor'; import { useSelect } from '@wordpress/data'; -import { useMemo } from '@wordpress/element'; export default function TemplatePartInnerBlocks( { postId: id, @@ -26,21 +25,6 @@ export default function TemplatePartInnerBlocks( { }, [] ); const defaultLayout = useSetting( 'layout' ) || {}; const usedLayout = !! layout && layout.inherit ? defaultLayout : layout; - const { contentSize, wideSize } = usedLayout; - const _layout = useMemo( () => { - if ( themeSupportsLayout ) { - const alignments = - contentSize || wideSize - ? [ 'wide', 'full', 'left', 'center', 'right' ] - : [ 'left', 'center', 'right' ]; - return { - type: 'default', - // Find a way to inject this in the support flag code (hooks). - alignments, - }; - } - return undefined; - }, [ themeSupportsLayout, contentSize, wideSize ] ); const [ blocks, onInput, onChange ] = useEntityBlockEditor( 'postType', @@ -55,7 +39,7 @@ export default function TemplatePartInnerBlocks( { renderAppender: hasInnerBlocks ? undefined : InnerBlocks.ButtonBlockAppender, - __experimentalLayout: _layout, + __experimentalLayout: themeSupportsLayout ? usedLayout : undefined, } ); return ( diff --git a/packages/edit-post/src/components/visual-editor/index.js b/packages/edit-post/src/components/visual-editor/index.js index 0b4d5ede5e645a..9a37eef568cd24 100644 --- a/packages/edit-post/src/components/visual-editor/index.js +++ b/packages/edit-post/src/components/visual-editor/index.js @@ -136,7 +136,6 @@ export default function VisualEditor( { styles } ) { }; const resizedCanvasStyles = useResizeCanvas( deviceType, isTemplateMode ); const defaultLayout = useSetting( 'layout' ); - const { contentSize, wideSize } = defaultLayout || {}; const previewMode = 'is-' + deviceType.toLowerCase() + '-preview'; let animatedStyles = isTemplateMode @@ -177,18 +176,11 @@ export default function VisualEditor( { styles } ) { } if ( themeSupportsLayout ) { - const alignments = - contentSize || wideSize - ? [ 'wide', 'full', 'left', 'center', 'right' ] - : [ 'left', 'center', 'right' ]; - return { - type: 'default', - // Find a way to inject this in the support flag code (hooks). - alignments, - }; + return defaultLayout; } + return undefined; - }, [ isTemplateMode, themeSupportsLayout, contentSize, wideSize ] ); + }, [ isTemplateMode, themeSupportsLayout ] ); return (