Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/explanations/architecture/styles.md
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ In addition to styles at the individual block level and in global styles, there

The layout block support is an experimental approach for outputting common layout styles that are shared between blocks that are used for creating layouts. Layout styles are useful for providing common styling for any block that is a container for other blocks. Examples of blocks that depend on these layout styles include Group, Row, Columns, Buttons, and Social Icons.

While the feature is part of WordPress core, it is still flagged as experimental in the sense that the features and output are still undergoing active development. It is therefore not yet a stable feature from the perspective of 3rd party blocks, as the API is likely to change. The feature is enabled in core blocks via the `__experimentalLayout` setting under `supports` in a block's `block.json` file.
While the feature is part of WordPress core, it is still flagged as experimental in the sense that the features and output are still undergoing active development. It is therefore not yet a stable feature from the perspective of 3rd party blocks, as the API is likely to change. The feature is enabled in core blocks via the `layout` setting under `supports` in a block's `block.json` file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for now, but once 6.3 is released, let's remember to come back to this document to update the wording to reflect that it's no longer experimental.


There are two primary places where Layout styles are output:

Expand Down
26 changes: 13 additions & 13 deletions docs/reference-guides/core-blocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ Prompt visitors to take action with a group of button-style links. ([Source](htt

- **Name:** core/buttons
- **Category:** design
- **Supports:** align (full, wide), anchor, spacing (blockGap, margin), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, layout (default, ~~allowInheriting~~, ~~allowSwitching~~), spacing (blockGap, margin), typography (fontSize, lineHeight), ~~html~~
- **Attributes:**

## Calendar
Expand Down Expand Up @@ -98,7 +98,7 @@ A single column within a columns block. ([Source](https://github.com/WordPress/g
- **Name:** core/column
- **Category:** design
- **Parent:** core/columns
- **Supports:** anchor, color (background, gradients, link, text), spacing (blockGap, padding), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Supports:** anchor, color (background, gradients, link, text), layout, spacing (blockGap, padding), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** allowedBlocks, templateLock, verticalAlignment, width

## Columns
Expand All @@ -107,7 +107,7 @@ Display content in multiple columns, with blocks added to each column. ([Source]

- **Name:** core/columns
- **Category:** design
- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, color (background, gradients, link, text), layout (default, ~~allowEditing~~, ~~allowInheriting~~, ~~allowSwitching~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** isStackedOnMobile, templateLock, verticalAlignment

## Comment Author Avatar (deprecated)
Expand Down Expand Up @@ -191,7 +191,7 @@ Displays a paginated navigation to next/previous set of comments, when applicabl
- **Name:** core/comments-pagination
- **Category:** theme
- **Parent:** core/comments
- **Supports:** align, color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Supports:** align, color (background, gradients, link, text), layout (default, ~~allowInheriting~~, ~~allowSwitching~~), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** paginationArrow

## Comments Next Page
Expand Down Expand Up @@ -239,7 +239,7 @@ Add an image or video with a text overlay. ([Source](https://github.com/WordPres

- **Name:** core/cover
- **Category:** media
- **Supports:** align, anchor, color (text, ~~background~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align, anchor, color (text, ~~background~~), layout (~~allowJustification~~), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** allowedBlocks, alt, backgroundType, contentPosition, customGradient, customOverlayColor, dimRatio, focalPoint, gradient, hasParallax, id, isDark, isRepeated, minHeight, minHeightUnit, overlayColor, tagName, templateLock, url, useFeaturedImage

## Details
Expand Down Expand Up @@ -284,7 +284,7 @@ Display multiple images in a rich gallery. ([Source](https://github.com/WordPres

- **Name:** core/gallery
- **Category:** media
- **Supports:** align, anchor, color (background, gradients, ~~text~~), spacing (blockGap, margin, padding), units (em, px, rem, vh, vw), ~~html~~
- **Supports:** align, anchor, color (background, gradients, ~~text~~), layout (default, ~~allowEditing~~, ~~allowInheriting~~, ~~allowSwitching~~), spacing (blockGap, margin, padding), units (em, px, rem, vh, vw), ~~html~~
- **Attributes:** allowResize, caption, columns, fixedHeight, ids, imageCrop, images, linkTarget, linkTo, shortCodeTransforms, sizeSlug

## Group
Expand All @@ -293,7 +293,7 @@ Gather blocks in a layout container. ([Source](https://github.com/WordPress/gute

- **Name:** core/group
- **Category:** design
- **Supports:** align (full, wide), anchor, ariaLabel, color (background, gradients, link, text), dimensions (minHeight), position (sticky), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), anchor, ariaLabel, color (background, gradients, link, text), dimensions (minHeight), layout (allowSizingOnChildren), position (sticky), spacing (blockGap, margin, padding), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** allowedBlocks, tagName, templateLock

## Heading
Expand Down Expand Up @@ -412,7 +412,7 @@ A collection of blocks that allow visitors to get around your site. ([Source](ht

- **Name:** core/navigation
- **Category:** theme
- **Supports:** align (full, wide), inserter, spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), inserter, layout (allowSizingOnChildren, default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, units), typography (fontSize, lineHeight), ~~html~~
- **Attributes:** __unstableLocation, backgroundColor, customBackgroundColor, customOverlayBackgroundColor, customOverlayTextColor, customTextColor, hasIcon, icon, maxNestingLevel, openSubmenusOnClick, overlayBackgroundColor, overlayMenu, overlayTextColor, ref, rgbBackgroundColor, rgbTextColor, showSubmenuIcon, templateLock, textColor

## Custom Link
Expand Down Expand Up @@ -554,7 +554,7 @@ Displays the contents of a post or page. ([Source](https://github.com/WordPress/

- **Name:** core/post-content
- **Category:** theme
- **Supports:** align (full, wide), dimensions (minHeight), typography (fontSize, lineHeight), ~~html~~
- **Supports:** align (full, wide), dimensions (minHeight), layout, typography (fontSize, lineHeight), ~~html~~
- **Attributes:**

## Post Date
Expand Down Expand Up @@ -600,7 +600,7 @@ Contains the block elements used to render a post, like the title, date, feature
- **Name:** core/post-template
- **Category:** theme
- **Parent:** core/query
- **Supports:** align (full, wide), color (background, gradients, link, text), spacing (blockGap), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Supports:** align (full, wide), color (background, gradients, link, text), layout, spacing (blockGap), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:**

## Post Terms
Expand Down Expand Up @@ -655,7 +655,7 @@ An advanced block that allows displaying post types based on different query par

- **Name:** core/query
- **Category:** theme
- **Supports:** align (full, wide), ~~html~~
- **Supports:** align (full, wide), layout, ~~html~~
- **Attributes:** namespace, query, queryId, tagName

## No results
Expand All @@ -675,7 +675,7 @@ Displays a paginated navigation to next/previous set of posts, when applicable.
- **Name:** core/query-pagination
- **Category:** theme
- **Parent:** core/query
- **Supports:** align, color (background, gradients, link, text), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Supports:** align, color (background, gradients, link, text), layout (default, ~~allowInheriting~~, ~~allowSwitching~~), typography (fontSize, lineHeight), ~~html~~, ~~reusable~~
- **Attributes:** paginationArrow, showLabel

## Next Page
Expand Down Expand Up @@ -814,7 +814,7 @@ Display icons linking to your social media profiles or sites. ([Source](https://

- **Name:** core/social-links
- **Category:** widgets
- **Supports:** align (center, left, right), anchor, color (background, gradients, ~~enableContrastChecker~~, ~~text~~), spacing (blockGap, margin, padding, units)
- **Supports:** align (center, left, right), anchor, color (background, gradients, ~~enableContrastChecker~~, ~~text~~), layout (default, ~~allowInheriting~~, ~~allowSwitching~~, ~~allowVerticalAlignment~~), spacing (blockGap, margin, padding, units)
- **Attributes:** customIconBackgroundColor, customIconColor, iconBackgroundColor, iconBackgroundColorValue, iconColor, iconColorValue, openInNewTab, showLabels, size

## Spacer
Expand Down
7 changes: 4 additions & 3 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ function gutenberg_get_layout_definitions() {
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_layout_support( $block_type ) {
$support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false );
$support_layout = block_has_support( $block_type, array( 'layout' ), false ) || block_has_support( $block_type, array( '__experimentalLayout' ), false );
if ( $support_layout ) {
if ( ! $block_type->attributes ) {
$block_type->attributes = array();
Expand Down Expand Up @@ -530,7 +530,7 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
*/
function gutenberg_render_layout_support_flag( $block_content, $block ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block['blockName'] );
$support_layout = block_has_support( $block_type, array( '__experimentalLayout' ), false );
$support_layout = block_has_support( $block_type, array( 'layout' ), false ) || block_has_support( $block_type, array( '__experimentalLayout' ), false );
$has_child_layout = isset( $block['attrs']['style']['layout']['selfStretch'] );

if ( ! $support_layout
Expand Down Expand Up @@ -584,7 +584,8 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
}

$global_settings = gutenberg_get_global_settings();
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
$fallback_layout = ! empty( _wp_array_get( $block_type->supports, array( 'layout', 'default' ), array() ) ) ? _wp_array_get( $block_type->supports, array( 'layout', 'default' ), array() ) : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : $fallback_layout;

$class_names = array();
$layout_definitions = gutenberg_get_layout_definitions();
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -1265,7 +1265,7 @@ protected function get_layout_styles( $block_metadata ) {

if ( isset( $block_metadata['name'] ) ) {
$block_type = WP_Block_Type_Registry::get_instance()->get_registered( $block_metadata['name'] );
if ( ! block_has_support( $block_type, array( '__experimentalLayout' ), false ) ) {
if ( ! block_has_support( $block_type, array( 'layout' ), false ) && ! block_has_support( $block_type, array( '__experimentalLayout' ), false ) ) {
return $block_rules;
}
}
Expand Down
8 changes: 3 additions & 5 deletions packages/block-editor/src/components/block-edit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ export default function BlockEdit( props ) {
__unstableLayoutClassNames,
} = props;
const { layout = null } = attributes;
const layoutSupport = hasBlockSupport(
name,
'__experimentalLayout',
false
);
const layoutSupport =
hasBlockSupport( name, 'layout', false ) ||
hasBlockSupport( name, '__experimentalLayout', false );
const context = {
name,
isSelected,
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/block-list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ function Items( {
rootClientId,
renderAppender,
__experimentalAppenderTagName,
__experimentalLayout: layout = defaultLayout,
layout = defaultLayout,
} ) {
const { order, selectedBlocks, visibleBlocks } = useSelect(
( select ) => {
Expand Down
21 changes: 7 additions & 14 deletions packages/block-editor/src/components/block-preview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,14 @@ export default memo( BlockPreview );
* returns. Optionally, you can also pass any other props through this hook, and
* they will be merged and returned.
*
* @param {Object} options Preview options.
* @param {WPBlock[]} options.blocks Block objects.
* @param {Object} options.props Optional. Props to pass to the element. Must contain
* the ref if one is defined.
* @param {Object} options.__experimentalLayout Layout settings to be used in the preview.
* @param {Object} options Preview options.
* @param {WPBlock[]} options.blocks Block objects.
* @param {Object} options.props Optional. Props to pass to the element. Must contain
* the ref if one is defined.
* @param {Object} options.layout Layout settings to be used in the preview.
*
*/
export function useBlockPreview( {
blocks,
props = {},
__experimentalLayout,
} ) {
export function useBlockPreview( { blocks, props = {}, layout } ) {
const originalSettings = useSelect(
( select ) => select( blockEditorStore ).getSettings(),
[]
Expand All @@ -133,10 +129,7 @@ export function useBlockPreview( {
value={ renderedBlocks }
settings={ settings }
>
<BlockListItems
renderAppender={ false }
__experimentalLayout={ __experimentalLayout }
/>
<BlockListItems renderAppender={ false } layout={ layout } />
</ExperimentalBlockEditorProvider>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,9 @@ export const getBlockSelectors = ( blockTypes, getBlockStyles ) => {
duotoneSupport && scopeSelector( rootSelector, duotoneSupport );
}

const hasLayoutSupport = !! blockType?.supports?.__experimentalLayout;
const hasLayoutSupport =
!! blockType?.supports?.layout ||
!! blockType?.supports?.__experimentalLayout;
const fallbackGapValue =
blockType?.supports?.spacing?.blockGap?.__experimentalDefault;

Expand Down
1 change: 0 additions & 1 deletion packages/block-editor/src/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ export { default as __experimentalUseResizeCanvas } from './use-resize-canvas';
export { default as BlockInspector } from './block-inspector';
export { default as BlockList } from './block-list';
export { useBlockProps } from './block-list/use-block-props';
export { LayoutStyle as __experimentalLayoutStyle } from './block-list/layout';
export { default as BlockMover } from './block-mover';
export {
default as BlockPreview,
Expand Down
6 changes: 4 additions & 2 deletions packages/block-editor/src/components/inner-blocks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function UncontrolledInnerBlocks( props ) {
);

const defaultLayoutBlockSupport =
getBlockSupport( name, '__experimentalLayout' ) || EMPTY_OBJECT;
getBlockSupport( name, 'layout' ) ||
getBlockSupport( name, '__experimentalLayout' ) ||
EMPTY_OBJECT;

const { allowSizingOnChildren = false } = defaultLayoutBlockSupport;

Expand Down Expand Up @@ -116,7 +118,7 @@ function UncontrolledInnerBlocks( props ) {
rootClientId={ clientId }
renderAppender={ renderAppender }
__experimentalAppenderTagName={ __experimentalAppenderTagName }
__experimentalLayout={ memoedLayout }
layout={ memoedLayout }
wrapperRef={ wrapperRef }
placeholder={ placeholder }
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function UncontrolledInnerBlocks( props ) {
horizontalAlignment,
filterInnerBlocks,
blockWidth,
__experimentalLayout: layout = defaultLayout,
layout = defaultLayout,
gridProperties,
} = props;

Expand Down
25 changes: 13 additions & 12 deletions packages/block-editor/src/hooks/layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,14 @@ import { getLayoutType, getLayoutTypes } from '../layouts';
import { useBlockEditingMode } from '../components/block-editing-mode';
import { LAYOUT_DEFINITIONS } from '../layouts/definitions';

const layoutBlockSupportKey = '__experimentalLayout';
const layoutBlockSupportKey = 'layout';

function hasLayoutBlockSupport( blockName ) {
return (
hasBlockSupport( blockName, 'layout' ) ||
hasBlockSupport( blockName, '__experimentalLayout' )
);
}

/**
* Generates the utility classnames for the given block's layout attributes.
Expand Down Expand Up @@ -295,7 +302,7 @@ export function addAttribute( settings ) {
if ( 'type' in ( settings.attributes?.layout ?? {} ) ) {
return settings;
}
if ( hasBlockSupport( settings, layoutBlockSupportKey ) ) {
if ( hasLayoutBlockSupport( settings ) ) {
settings.attributes = {
...settings.attributes,
layout: {
Expand All @@ -317,10 +324,7 @@ export function addAttribute( settings ) {
export const withInspectorControls = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const { name: blockName } = props;
const supportLayout = hasBlockSupport(
blockName,
layoutBlockSupportKey
);
const supportLayout = hasLayoutBlockSupport( blockName );

const blockEditingMode = useBlockEditingMode();
return [
Expand All @@ -343,16 +347,13 @@ export const withInspectorControls = createHigherOrderComponent(
export const withLayoutStyles = createHigherOrderComponent(
( BlockListBlock ) => ( props ) => {
const { name, attributes } = props;
const hasLayoutBlockSupport = hasBlockSupport(
name,
layoutBlockSupportKey
);
const blockSupportsLayout = hasLayoutBlockSupport( name );
const disableLayoutStyles = useSelect( ( select ) => {
const { getSettings } = select( blockEditorStore );
return !! getSettings().disableLayoutStyles;
} );
const shouldRenderLayoutStyles =
hasLayoutBlockSupport && ! disableLayoutStyles;
blockSupportsLayout && ! disableLayoutStyles;
const id = useInstanceId( BlockListBlock );
const element = useContext( BlockList.__unstableElementContext );
const { layout } = attributes;
Expand All @@ -362,7 +363,7 @@ export const withLayoutStyles = createHigherOrderComponent(
layout?.inherit || layout?.contentSize || layout?.wideSize
? { ...layout, type: 'constrained' }
: layout || defaultBlockLayout || {};
const layoutClasses = hasLayoutBlockSupport
const layoutClasses = blockSupportsLayout
? useLayoutClasses( attributes, name )
: null;
// Higher specificity to override defaults from theme.json.
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/hooks/supports.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ const TEXT_TRANSFORM_SUPPORT_KEY = 'typography.__experimentalTextTransform';
* e.g. settings found in `block.json`.
*/
const LETTER_SPACING_SUPPORT_KEY = 'typography.__experimentalLetterSpacing';
const LAYOUT_SUPPORT_KEY = '__experimentalLayout';
const LAYOUT_SUPPORT_KEY = 'layout';
const TYPOGRAPHY_SUPPORT_KEYS = [
LINE_HEIGHT_SUPPORT_KEY,
FONT_SIZE_SUPPORT_KEY,
Expand Down
2 changes: 0 additions & 2 deletions packages/block-editor/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ export {
getSpacingClassesAndStyles as __experimentalGetSpacingClassesAndStyles,
getGapCSSValue as __experimentalGetGapCSSValue,
useCachedTruthy,
useLayoutClasses as __experimentaluseLayoutClasses,
useLayoutStyles as __experimentaluseLayoutStyles,
} from './hooks';
export * from './components';
export * from './elements';
Expand Down
5 changes: 5 additions & 0 deletions packages/block-editor/src/private-apis.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { useShouldContextualToolbarShow } from './utils/use-should-contextual-to
import { cleanEmptyObject } from './hooks/utils';
import { useBlockEditingMode } from './components/block-editing-mode';
import BlockQuickNavigation from './components/block-quick-navigation';
import { LayoutStyle } from './components/block-list/layout';
import { useLayoutClasses, useLayoutStyles } from './hooks';

/**
* Private @wordpress/block-editor APIs.
Expand All @@ -28,4 +30,7 @@ lock( privateApis, {
cleanEmptyObject,
useBlockEditingMode,
BlockQuickNavigation,
LayoutStyle,
useLayoutClasses,
useLayoutStyles,
} );
2 changes: 1 addition & 1 deletion packages/block-library/src/buttons/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"fontSize": true
}
},
"__experimentalLayout": {
"layout": {
"allowSwitching": false,
"allowInheriting": false,
"default": {
Expand Down
Loading