Skip to content

Commit

Permalink
Layout cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
youknowriad committed Jul 13, 2021
1 parent 9152627 commit 1e44fe1
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 63 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/group/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ function GroupEdit( { attributes, setAttributes, clientId } ) {
renderAppender: hasInnerBlocks
? undefined
: InnerBlocks.ButtonBlockAppender,
__experimentalLayout: usedLayout,
__experimentalLayout: themeSupportsLayout ? usedLayout : undefined,
}
);

Expand Down
19 changes: 2 additions & 17 deletions packages/block-library/src/post-content/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -73,7 +58,7 @@ function EditableContent( { layout, context = {} } ) {
value: blocks,
onInput,
onChange,
__experimentalLayout: _layout,
__experimentalLayout: themeSupportsLayout ? usedLayout : undefined,
}
);
return <div { ...props } />;
Expand Down
19 changes: 2 additions & 17 deletions packages/block-library/src/query/edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 );
Expand Down
18 changes: 1 addition & 17 deletions packages/block-library/src/template-part/edit/inner-blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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',
Expand All @@ -55,7 +39,7 @@ export default function TemplatePartInnerBlocks( {
renderAppender: hasInnerBlocks
? undefined
: InnerBlocks.ButtonBlockAppender,
__experimentalLayout: _layout,
__experimentalLayout: themeSupportsLayout ? usedLayout : undefined,
} );

return (
Expand Down
14 changes: 3 additions & 11 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (
<div
Expand Down

0 comments on commit 1e44fe1

Please sign in to comment.