Editor: stabilise layout and refactor definitions.
Marks the layout support stable and moves layout definitions from `theme.json` into `wp-includes/block-supports/layout.php`. Props andrewserong, poena, ramonopoly, peterwilsoncc. Fixes #58550. Built from https://develop.svn.wordpress.org/trunk@56055 git-svn-id: http://core.svn.wordpress.org/trunk@55567 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
c326f4855c
commit
2e2aea02c2
|
@ -6,16 +6,203 @@
|
|||
* @since 5.8.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* Returns layout definitions, keyed by layout type.
|
||||
*
|
||||
* Provides a common definition of slugs, classnames, base styles, and spacing styles for each layout type.
|
||||
* When making changes or additions to layout definitions, the corresponding JavaScript definitions should
|
||||
* also be updated.
|
||||
*
|
||||
* @since 6.3.0
|
||||
* @access private
|
||||
*
|
||||
* @return array[] Layout definitions.
|
||||
*/
|
||||
function wp_get_layout_definitions() {
|
||||
$layout_definitions = array(
|
||||
'default' => array(
|
||||
'name' => 'default',
|
||||
'slug' => 'flow',
|
||||
'className' => 'is-layout-flow',
|
||||
'baseStyles' => array(
|
||||
array(
|
||||
'selector' => ' > .alignleft',
|
||||
'rules' => array(
|
||||
'float' => 'left',
|
||||
'margin-inline-start' => '0',
|
||||
'margin-inline-end' => '2em',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > .alignright',
|
||||
'rules' => array(
|
||||
'float' => 'right',
|
||||
'margin-inline-start' => '2em',
|
||||
'margin-inline-end' => '0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > .aligncenter',
|
||||
'rules' => array(
|
||||
'margin-left' => 'auto !important',
|
||||
'margin-right' => 'auto !important',
|
||||
),
|
||||
),
|
||||
),
|
||||
'spacingStyles' => array(
|
||||
array(
|
||||
'selector' => ' > :first-child:first-child',
|
||||
'rules' => array(
|
||||
'margin-block-start' => '0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > :last-child:last-child',
|
||||
'rules' => array(
|
||||
'margin-block-end' => '0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > *',
|
||||
'rules' => array(
|
||||
'margin-block-start' => null,
|
||||
'margin-block-end' => '0',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'constrained' => array(
|
||||
'name' => 'constrained',
|
||||
'slug' => 'constrained',
|
||||
'className' => 'is-layout-constrained',
|
||||
'baseStyles' => array(
|
||||
array(
|
||||
'selector' => ' > .alignleft',
|
||||
'rules' => array(
|
||||
'float' => 'left',
|
||||
'margin-inline-start' => '0',
|
||||
'margin-inline-end' => '2em',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > .alignright',
|
||||
'rules' => array(
|
||||
'float' => 'right',
|
||||
'margin-inline-start' => '2em',
|
||||
'margin-inline-end' => '0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > .aligncenter',
|
||||
'rules' => array(
|
||||
'margin-left' => 'auto !important',
|
||||
'margin-right' => 'auto !important',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > :where(:not(.alignleft):not(.alignright):not(.alignfull))',
|
||||
'rules' => array(
|
||||
'max-width' => 'var(--wp--style--global--content-size)',
|
||||
'margin-left' => 'auto !important',
|
||||
'margin-right' => 'auto !important',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > .alignwide',
|
||||
'rules' => array(
|
||||
'max-width' => 'var(--wp--style--global--wide-size)',
|
||||
),
|
||||
),
|
||||
),
|
||||
'spacingStyles' => array(
|
||||
array(
|
||||
'selector' => ' > :first-child:first-child',
|
||||
'rules' => array(
|
||||
'margin-block-start' => '0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > :last-child:last-child',
|
||||
'rules' => array(
|
||||
'margin-block-end' => '0',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > *',
|
||||
'rules' => array(
|
||||
'margin-block-start' => null,
|
||||
'margin-block-end' => '0',
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'flex' => array(
|
||||
'name' => 'flex',
|
||||
'slug' => 'flex',
|
||||
'className' => 'is-layout-flex',
|
||||
'displayMode' => 'flex',
|
||||
'baseStyles' => array(
|
||||
array(
|
||||
'selector' => '',
|
||||
'rules' => array(
|
||||
'flex-wrap' => 'wrap',
|
||||
'align-items' => 'center',
|
||||
),
|
||||
),
|
||||
array(
|
||||
'selector' => ' > *',
|
||||
'rules' => array(
|
||||
'margin' => '0',
|
||||
),
|
||||
),
|
||||
),
|
||||
'spacingStyles' => array(
|
||||
array(
|
||||
'selector' => '',
|
||||
'rules' => array(
|
||||
'gap' => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
'grid' => array(
|
||||
'name' => 'grid',
|
||||
'slug' => 'grid',
|
||||
'className' => 'is-layout-grid',
|
||||
'displayMode' => 'grid',
|
||||
'baseStyles' => array(
|
||||
array(
|
||||
'selector' => ' > *',
|
||||
'rules' => array(
|
||||
'margin' => '0',
|
||||
),
|
||||
),
|
||||
),
|
||||
'spacingStyles' => array(
|
||||
array(
|
||||
'selector' => '',
|
||||
'rules' => array(
|
||||
'gap' => null,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
return $layout_definitions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers the layout block attribute for block types that support it.
|
||||
*
|
||||
* @since 5.8.0
|
||||
* @since 6.3.0 Check for layout support via the `layout` key with fallback to `__experimentalLayout`.
|
||||
* @access private
|
||||
*
|
||||
* @param WP_Block_Type $block_type Block Type.
|
||||
*/
|
||||
function wp_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();
|
||||
|
@ -352,6 +539,7 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
|
|||
*
|
||||
* @since 5.8.0
|
||||
* @since 6.3.0 Adds compound class to layout wrapper for global spacing styles.
|
||||
* @since 6.3.0 Check for layout support via the `layout` key with fallback to `__experimentalLayout`.
|
||||
* @access private
|
||||
*
|
||||
* @param string $block_content Rendered block content.
|
||||
|
@ -360,7 +548,7 @@ function wp_get_layout_style( $selector, $layout, $has_block_gap_support = false
|
|||
*/
|
||||
function wp_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 && ! $has_child_layout ) {
|
||||
|
@ -410,15 +598,11 @@ function wp_render_layout_support_flag( $block_content, $block ) {
|
|||
}
|
||||
|
||||
$global_settings = wp_get_global_settings();
|
||||
$global_layout_settings = _wp_array_get( $global_settings, array( 'layout' ), null );
|
||||
$used_layout = isset( $block['attrs']['layout'] ) ? $block['attrs']['layout'] : _wp_array_get( $block_type->supports, array( '__experimentalLayout', 'default' ), array() );
|
||||
|
||||
if ( isset( $used_layout['inherit'] ) && $used_layout['inherit'] && ! $global_layout_settings ) {
|
||||
return $block_content;
|
||||
}
|
||||
$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 = _wp_array_get( $global_layout_settings, array( 'definitions' ), array() );
|
||||
$layout_definitions = wp_get_layout_definitions();
|
||||
$container_class = wp_unique_id( 'wp-container-' );
|
||||
$layout_classname = '';
|
||||
|
||||
|
|
|
@ -338,7 +338,7 @@ class WP_Theme_JSON {
|
|||
* @since 6.1.0 Added `layout.definitions` and `useRootPaddingAwareAlignments`.
|
||||
* @since 6.2.0 Added `dimensions.minHeight`, 'shadow.presets', 'shadow.defaultPresets',
|
||||
* `position.fixed` and `position.sticky`.
|
||||
* @since 6.3.0 Added support for `typography.textColumns`.
|
||||
* @since 6.3.0 Added support for `typography.textColumns`, removed `layout.definitions`.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
|
@ -374,7 +374,6 @@ class WP_Theme_JSON {
|
|||
),
|
||||
'layout' => array(
|
||||
'contentSize' => null,
|
||||
'definitions' => null,
|
||||
'wideSize' => null,
|
||||
),
|
||||
'position' => array(
|
||||
|
@ -1277,7 +1276,7 @@ class WP_Theme_JSON {
|
|||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1286,7 +1285,7 @@ class WP_Theme_JSON {
|
|||
$has_block_gap_support = _wp_array_get( $this->theme_json, array( 'settings', 'spacing', 'blockGap' ) ) !== null;
|
||||
$has_fallback_gap_support = ! $has_block_gap_support; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback gap styles support.
|
||||
$node = _wp_array_get( $this->theme_json, $block_metadata['path'], array() );
|
||||
$layout_definitions = _wp_array_get( $this->theme_json, array( 'settings', 'layout', 'definitions' ), array() );
|
||||
$layout_definitions = wp_get_layout_definitions();
|
||||
$layout_selector_pattern = '/^[a-zA-Z0-9\-\.\ *+>:\(\)]*$/'; // Allow alphanumeric classnames, spaces, wildcard, sibling, child combinator and pseudo class selectors.
|
||||
|
||||
// Gap styles will only be output if the theme has block gap support, or supports a fallback gap.
|
||||
|
|
|
@ -189,177 +189,6 @@
|
|||
],
|
||||
"text": true
|
||||
},
|
||||
"layout": {
|
||||
"definitions": {
|
||||
"default": {
|
||||
"name": "default",
|
||||
"slug": "flow",
|
||||
"className": "is-layout-flow",
|
||||
"baseStyles": [
|
||||
{
|
||||
"selector": " > .alignleft",
|
||||
"rules": {
|
||||
"float": "left",
|
||||
"margin-inline-start": "0",
|
||||
"margin-inline-end": "2em"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > .alignright",
|
||||
"rules": {
|
||||
"float": "right",
|
||||
"margin-inline-start": "2em",
|
||||
"margin-inline-end": "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > .aligncenter",
|
||||
"rules": {
|
||||
"margin-left": "auto !important",
|
||||
"margin-right": "auto !important"
|
||||
}
|
||||
}
|
||||
],
|
||||
"spacingStyles": [
|
||||
{
|
||||
"selector": " > :first-child:first-child",
|
||||
"rules": {
|
||||
"margin-block-start": "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > :last-child:last-child",
|
||||
"rules": {
|
||||
"margin-block-end": "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > *",
|
||||
"rules": {
|
||||
"margin-block-start": null,
|
||||
"margin-block-end": "0"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"constrained": {
|
||||
"name": "constrained",
|
||||
"slug": "constrained",
|
||||
"className": "is-layout-constrained",
|
||||
"baseStyles": [
|
||||
{
|
||||
"selector": " > .alignleft",
|
||||
"rules": {
|
||||
"float": "left",
|
||||
"margin-inline-start": "0",
|
||||
"margin-inline-end": "2em"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > .alignright",
|
||||
"rules": {
|
||||
"float": "right",
|
||||
"margin-inline-start": "2em",
|
||||
"margin-inline-end": "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > .aligncenter",
|
||||
"rules": {
|
||||
"margin-left": "auto !important",
|
||||
"margin-right": "auto !important"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > :where(:not(.alignleft):not(.alignright):not(.alignfull))",
|
||||
"rules": {
|
||||
"max-width": "var(--wp--style--global--content-size)",
|
||||
"margin-left": "auto !important",
|
||||
"margin-right": "auto !important"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > .alignwide",
|
||||
"rules": {
|
||||
"max-width": "var(--wp--style--global--wide-size)"
|
||||
}
|
||||
}
|
||||
],
|
||||
"spacingStyles": [
|
||||
{
|
||||
"selector": " > :first-child:first-child",
|
||||
"rules": {
|
||||
"margin-block-start": "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > :last-child:last-child",
|
||||
"rules": {
|
||||
"margin-block-end": "0"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > *",
|
||||
"rules": {
|
||||
"margin-block-start": null,
|
||||
"margin-block-end": "0"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"flex": {
|
||||
"name": "flex",
|
||||
"slug": "flex",
|
||||
"className": "is-layout-flex",
|
||||
"displayMode": "flex",
|
||||
"baseStyles": [
|
||||
{
|
||||
"selector": "",
|
||||
"rules": {
|
||||
"flex-wrap": "wrap",
|
||||
"align-items": "center"
|
||||
}
|
||||
},
|
||||
{
|
||||
"selector": " > *",
|
||||
"rules": {
|
||||
"margin": "0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"spacingStyles": [
|
||||
{
|
||||
"selector": "",
|
||||
"rules": {
|
||||
"gap": null
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"grid": {
|
||||
"name": "grid",
|
||||
"slug": "grid",
|
||||
"className": "is-layout-grid",
|
||||
"displayMode": "grid",
|
||||
"baseStyles": [
|
||||
{
|
||||
"selector": " > *",
|
||||
"rules": {
|
||||
"margin": "0"
|
||||
}
|
||||
}
|
||||
],
|
||||
"spacingStyles": [
|
||||
{
|
||||
"selector": "",
|
||||
"rules": {
|
||||
"gap": null
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
"shadow": {
|
||||
"defaultPresets": true,
|
||||
"presets": [
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.3-alpha-56054';
|
||||
$wp_version = '6.3-alpha-56055';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
|
Loading…
Reference in New Issue