Skip to content

Commit

Permalink
Address review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Feb 23, 2023
1 parent 153d8ca commit bb125de
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
15 changes: 6 additions & 9 deletions lib/experimental/block-editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,16 @@ function get_post_content_block( $blocks ) {
}

if ( ! empty( $current_template ) ) {
$template_blocks = parse_blocks( $current_template[0]->content );
$post_content_block = get_post_content_block( $template_blocks );
$template_blocks = parse_blocks( $current_template[0]->content );
$post_content_block = get_post_content_block( $template_blocks );
$post_content_attributes = $post_content_block['attrs'];

if ( ! empty( $post_content_block ) ) {
// mismatched naming x(.
if ( empty( $post_content_block['attributes'] ) && ! empty( $post_content_block['attrs'] ) ) {
$post_content_block['attributes'] = $post_content_block['attrs'];
}
$settings['postContentBlock'] = $post_content_block;
if ( ! empty( $post_content_attributes ) ) {
$settings['postContentAttributes'] = $post_content_attributes;
}
}

return $settings;
}

add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_experimental', PHP_INT_MAX );
add_filter( 'block_editor_settings_all', 'gutenberg_get_block_editor_settings_experimental', PHP_INT_MAX );
26 changes: 12 additions & 14 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,23 +35,21 @@ const layoutBlockSupportKey = '__experimentalLayout';
/**
* Generates the utility classnames for the given block's layout attributes.
*
* @param { Object } block Block object.
* @param { Object } layout Layout object.
* @param { string } blockName Block name.
*
* @return { Array } Array of CSS classname strings.
*/
export function useLayoutClasses( block = {} ) {
export function useLayoutClasses( layout, blockName ) {
const rootPaddingAlignment = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return getSettings().__experimentalFeatures
?.useRootPaddingAwareAlignments;
}, [] );
const globalLayoutSettings = useSetting( 'layout' ) || {};

const { attributes = {}, name } = block;
const { layout } = attributes;

const { default: defaultBlockLayout } =
getBlockSupport( name, layoutBlockSupportKey ) || {};
getBlockSupport( blockName, layoutBlockSupportKey ) || {};
const usedLayout =
layout?.inherit || layout?.contentSize || layout?.wideSize
? { ...layout, type: 'constrained' }
Expand Down Expand Up @@ -100,14 +98,14 @@ export function useLayoutClasses( block = {} ) {
/**
* Generates a CSS rule with the given block's layout styles.
*
* @param { Object } block Block object.
* @param { string } selector A selector to use in generating the CSS rule.
* @param { Object } blockAttributes Block attributes.
* @param { string } blockName Block name.
* @param { string } selector A selector to use in generating the CSS rule.
*
* @return { string } CSS rule.
*/
export function useLayoutStyles( block = {}, selector ) {
const { attributes = {}, name } = block;
const { layout = {}, style = {} } = attributes;
export function useLayoutStyles( blockAttributes, blockName, selector ) {
const { layout = {}, style = {} } = blockAttributes;
// Update type for blocks using legacy layouts.
const usedLayout =
layout?.inherit || layout?.contentSize || layout?.wideSize
Expand All @@ -118,7 +116,7 @@ export function useLayoutStyles( block = {}, selector ) {
const blockGapSupport = useSetting( 'spacing.blockGap' );
const hasBlockGapSupport = blockGapSupport !== null;
const css = fullLayoutType?.getLayoutStyle?.( {
blockName: name,
blockName,
selector,
layout,
layoutDefinitions: globalLayoutSettings?.definitions,
Expand Down Expand Up @@ -338,7 +336,7 @@ export const withInspectorControls = createHigherOrderComponent(
*/
export const withLayoutStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const { name, attributes, block } = props;
const { name, attributes } = props;
const hasLayoutBlockSupport = hasBlockSupport(
name,
layoutBlockSupportKey
Expand All @@ -360,7 +358,7 @@ export const withLayoutStyles = createHigherOrderComponent(
? { ...layout, type: 'constrained' }
: layout || defaultBlockLayout || {};
const layoutClasses = hasLayoutBlockSupport
? useLayoutClasses( block )
? useLayoutClasses( layout, name )
: null;
// Higher specificity to override defaults from theme.json.
const selector = `.wp-container-${ id }.wp-container-${ id }`;
Expand Down
18 changes: 11 additions & 7 deletions packages/edit-post/src/components/visual-editor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function VisualEditor( { styles } ) {
deviceType,
isWelcomeGuideVisible,
isTemplateMode,
postContentBlock,
postContentAttributes,
wrapperBlockName,
wrapperUniqueId,
isBlockBasedTheme,
Expand All @@ -108,7 +108,7 @@ export default function VisualEditor( { styles } ) {
deviceType: __experimentalGetPreviewDeviceType(),
isWelcomeGuideVisible: isFeatureActive( 'welcomeGuide' ),
isTemplateMode: _isTemplateMode,
postContentBlock: getEditorSettings().postContentBlock,
postContentAttributes: getEditorSettings().postContentAttributes,
wrapperBlockName: _wrapperBlockName,
wrapperUniqueId: getCurrentPostId(),
isBlockBasedTheme: editorSettings.__unstableIsBlockBasedTheme,
Expand Down Expand Up @@ -192,7 +192,12 @@ export default function VisualEditor( { styles } ) {
return { type: 'default' };
}, [ isTemplateMode, themeSupportsLayout, globalLayoutSettings ] );

const postContentLayoutClasses = useLayoutClasses( postContentBlock );
const layout = postContentAttributes?.layout || {};

const postContentLayoutClasses = useLayoutClasses(
layout,
'core/post-content'
);

const blockListLayoutClass = classnames(
{
Expand All @@ -202,12 +207,11 @@ export default function VisualEditor( { styles } ) {
);

const postContentLayoutStyles = useLayoutStyles(
postContentBlock,
postContentAttributes,
'core/post-content',
'.block-editor-block-list__layout.is-root-container'
);

const layout = postContentBlock?.attributes?.layout || {};

// Update type for blocks using legacy layouts.
const postContentLayout = useMemo( () => {
return layout &&
Expand All @@ -227,7 +231,7 @@ export default function VisualEditor( { styles } ) {

// If there is a Post Content block we use its layout for the block list;
// if not, this must be a classic theme, in which case we use the fallback layout.
const blockListLayout = postContentBlock
const blockListLayout = postContentAttributes
? postContentLayout
: fallbackLayout;

Expand Down

0 comments on commit bb125de

Please sign in to comment.