Skip to content

Commit

Permalink
prep build 09/20
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Sep 20, 2023
2 parents a3681bd + 1873738 commit 219cf64
Show file tree
Hide file tree
Showing 343 changed files with 90,257 additions and 28,157 deletions.
471 changes: 471 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/getting-started/devenv/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ To contribute to the Gutenberg project itself, refer to the additional documenta
A block development environment includes the tools you need on your computer to successfully develop for the Block Editor. The three essential requirements are:

1. [Code editor](#code-editor)
2. [Node.js development tools](#nodejs-development-tools)
2. [Node.js development tools](#node-js-development-tools)
3. [Local WordPress environment (site)](#local-wordpress-environment)

## Code editor
Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/devenv/get-started-with-wp-env.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ wp-env start

Once the script completes, you can access the local environment at: `http://localhost:8888`. Log into the WordPress dashboard using username `admin` and password `password`.

<div class="callout-tip">
<div class="callout callout-tip">
Some projects, like Gutenberg, include their own specific <code>wp-env</code> configurations, and the documentation might prompt you to run <code>npm run start wp-env</code> instead.
</div>

Expand Down
2 changes: 1 addition & 1 deletion docs/getting-started/devenv/get-started-with-wp-now.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

The [@wp-now/wp-now](https://www.npmjs.com/package/@wordpress/env) package (`wp-now`) is a lightweight tool powered by [WordPress Playground](https://developer.wordpress.org/playground/) that streamlines setting up a local WordPress environment.

Before following this guide, install [Node.js development tools](/docs/getting-started/devenv#nodejs-development-tools) if you have not already done so. It's recommended that you use the latest version of `node`. `wp-now` requires at least `node` v18 and v20 if you intend to use its [Blueprints](https://github.com/WordPress/playground-tools/tree/trunk/packages/wp-now#using-blueprints) feature.
Before following this guide, install [Node.js development tools](/docs/getting-started/devenv#node-js-development-tools) if you have not already done so. It's recommended that you use the latest version of `node`. `wp-now` requires at least `node` v18 and v20 if you intend to use its [Blueprints](https://github.com/WordPress/playground-tools/tree/trunk/packages/wp-now#using-blueprints) feature.

## Quick start

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Node.js development environment

When developing for the Block Editor, you will need [Node.js](https://nodejs.org/en) development tools along with a code editor and a local WordPress environment (see [Block Development Environment](README.md)). Node.js (`node`) is an open-source runtime environment that allows you to execute JavaScript code from the terminal (also known as a command-line interface, CLI, or shell)
When developing for the Block Editor, you will need [Node.js](https://nodejs.org/en) development tools along with a code editor and a local WordPress environment (see [Block Development Environment](/docs/getting-started/devenv/README.md)). Node.js (`node`) is an open-source runtime environment that allows you to execute JavaScript code from the terminal (also known as a command-line interface, CLI, or shell)

Installing `node` will automatically include the Node Package Manager (`npm`) and the Node Package eXecute (`npx`), two tools you will frequently use in block and plugin development.

Expand Down
2 changes: 1 addition & 1 deletion docs/how-to-guides/themes/theme-json.md
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ You can use `ref: "styles.color.background"` to re-use the style for a block:
```JSON
{
"color": {
"text": { ref: "styles.color.background" }
"text": { "ref": "styles.color.background" }
}
}
```
Expand Down
6 changes: 3 additions & 3 deletions lib/block-supports/background.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ function gutenberg_render_background_support( $block_content, $block ) {
return $block_content;
}

$background_image_source = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundImage', 'source' ), null );
$background_image_url = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundImage', 'url' ), null );
$background_size = _wp_array_get( $block_attributes, array( 'style', 'background', 'backgroundSize' ), 'cover' );
$background_image_source = $block_attributes['style']['background']['backgroundImage']['source'] ?? null;
$background_image_url = $block_attributes['style']['background']['backgroundImage']['url'] ?? null;
$background_size = $block_attributes['style']['background']['backgroundSize'] ?? 'cover';

$background_block_styles = array();

Expand Down
14 changes: 7 additions & 7 deletions lib/block-supports/border.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' )
) {
$preset_border_color = array_key_exists( 'borderColor', $block_attributes ) ? "var:preset|color|{$block_attributes['borderColor']}" : null;
$custom_border_color = _wp_array_get( $block_attributes, array( 'style', 'border', 'color' ), null );
$custom_border_color = $block_attributes['style']['border']['color'] ?? null;
$border_block_styles['color'] = $preset_border_color ? $preset_border_color : $custom_border_color;
}

// Generate styles for individual border sides.
if ( $has_border_color_support || $has_border_width_support ) {
foreach ( array( 'top', 'right', 'bottom', 'left' ) as $side ) {
$border = _wp_array_get( $block_attributes, array( 'style', 'border', $side ), null );
$border = $block_attributes['style']['border'][ $side ] ?? null;
$border_side_values = array(
'width' => isset( $border['width'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'width' ) ? $border['width'] : null,
'color' => isset( $border['color'] ) && ! wp_should_skip_block_supports_serialization( $block_type, '__experimentalBorder', 'color' ) ? $border['color'] : null,
Expand Down Expand Up @@ -142,11 +142,11 @@ function gutenberg_apply_border_support( $block_type, $block_attributes ) {
*/
function gutenberg_has_border_feature_support( $block_type, $feature, $default_value = false ) {
// Check if all border support features have been opted into via `"__experimentalBorder": true`.
if (
property_exists( $block_type, 'supports' ) &&
( true === _wp_array_get( $block_type->supports, array( '__experimentalBorder' ), $default_value ) )
) {
return true;
if ( property_exists( $block_type, 'supports' ) ) {
$block_type_supports_border = $block_type->supports['__experimentalBorder'] ?? $default_value;
if ( true === $block_type_supports_border ) {
return true;
}
}

// Check if the specific feature has been opted into individually
Expand Down
39 changes: 25 additions & 14 deletions lib/block-supports/colors.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@
* @param WP_Block_Type $block_type Block Type.
*/
function gutenberg_register_colors_support( $block_type ) {
$color_support = property_exists( $block_type, 'supports' ) ? _wp_array_get( $block_type->supports, array( 'color' ), false ) : false;
$has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
$has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
$has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
$has_link_colors_support = _wp_array_get( $color_support, array( 'link' ), false );
$has_button_colors_support = _wp_array_get( $color_support, array( 'button' ), false );
$has_heading_colors_support = _wp_array_get( $color_support, array( 'heading' ), false );
$color_support = false;
if ( property_exists( $block_type, 'supports' ) ) {
$color_support = $block_type->supports['color'] ?? false;
}
$has_text_colors_support = true === $color_support ||
( isset( $color_support['text'] ) && $color_support['text'] ) ||
( is_array( $color_support ) && ! isset( $color_support['text'] ) );
$has_background_colors_support = true === $color_support ||
( isset( $color_support['background'] ) && $color_support['background'] ) ||
( is_array( $color_support ) && ! isset( $color_support['background'] ) );
$has_gradients_support = $color_support['gradients'] ?? false;
$has_link_colors_support = $color_support['link'] ?? false;
$has_button_colors_support = $color_support['button'] ?? false;
$has_heading_colors_support = $color_support['heading'] ?? false;
$has_color_support = $has_text_colors_support ||
$has_background_colors_support ||
$has_gradients_support ||
Expand Down Expand Up @@ -65,7 +72,7 @@ function gutenberg_register_colors_support( $block_type ) {
* @return array Colors CSS classes and inline styles.
*/
function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
$color_support = _wp_array_get( $block_type->supports, array( 'color' ), false );
$color_support = $block_type->supports['color'] ?? false;

if (
is_array( $color_support ) &&
Expand All @@ -74,31 +81,35 @@ function gutenberg_apply_colors_support( $block_type, $block_attributes ) {
return array();
}

$has_text_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'text' ), true ) );
$has_background_colors_support = true === $color_support || ( is_array( $color_support ) && _wp_array_get( $color_support, array( 'background' ), true ) );
$has_gradients_support = _wp_array_get( $color_support, array( 'gradients' ), false );
$has_text_colors_support = true === $color_support ||
( isset( $color_support['text'] ) && $color_support['text'] ) ||
( is_array( $color_support ) && ! isset( $color_support['text'] ) );
$has_background_colors_support = true === $color_support ||
( isset( $color_support['background'] ) && $color_support['background'] ) ||
( is_array( $color_support ) && ! isset( $color_support['background'] ) );
$has_gradients_support = $color_support['gradients'] ?? false;
$color_block_styles = array();

// Text colors.
// Check support for text colors.
if ( $has_text_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'text' ) ) {
$preset_text_color = array_key_exists( 'textColor', $block_attributes ) ? "var:preset|color|{$block_attributes['textColor']}" : null;
$custom_text_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'text' ), null );
$custom_text_color = $block_attributes['style']['color']['text'] ?? null;
$color_block_styles['text'] = $preset_text_color ? $preset_text_color : $custom_text_color;
}

// Background colors.
if ( $has_background_colors_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'background' ) ) {
$preset_background_color = array_key_exists( 'backgroundColor', $block_attributes ) ? "var:preset|color|{$block_attributes['backgroundColor']}" : null;
$custom_background_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'background' ), null );
$custom_background_color = $block_attributes['style']['color']['background'] ?? null;
$color_block_styles['background'] = $preset_background_color ? $preset_background_color : $custom_background_color;
}

// Gradients.

if ( $has_gradients_support && ! wp_should_skip_block_supports_serialization( $block_type, 'color', 'gradients' ) ) {
$preset_gradient_color = array_key_exists( 'gradient', $block_attributes ) ? "var:preset|gradient|{$block_attributes['gradient']}" : null;
$custom_gradient_color = _wp_array_get( $block_attributes, array( 'style', 'color', 'gradient' ), null );
$custom_gradient_color = $block_attributes['style']['color']['gradient'] ?? null;
$color_block_styles['gradient'] = $preset_gradient_color ? $preset_gradient_color : $custom_gradient_color;
}

Expand Down
7 changes: 5 additions & 2 deletions lib/block-supports/dimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ function gutenberg_apply_dimensions_support( $block_type, $block_attributes ) {

$skip_min_height = wp_should_skip_block_supports_serialization( $block_type, 'dimensions', 'minHeight' );
$dimensions_block_styles = array();
$dimensions_block_styles['minHeight'] = $has_min_height_support && ! $skip_min_height ? _wp_array_get( $block_styles, array( 'dimensions', 'minHeight' ), null ) : null;
$styles = gutenberg_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );
$dimensions_block_styles['minHeight'] = null;
if ( $has_min_height_support && ! $skip_min_height ) {
$dimensions_block_styles['minHeight'] = $block_styles['dimensions']['minHeight'] ?? null;
}
$styles = gutenberg_style_engine_get_styles( array( 'dimensions' => $dimensions_block_styles ) );

if ( ! empty( $styles['css'] ) ) {
$attributes['style'] = $styles['css'];
Expand Down
33 changes: 21 additions & 12 deletions lib/block-supports/layout.php
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function gutenberg_register_layout_support( $block_type ) {
* @return string CSS styles on success. Else, empty string.
*/
function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support = false, $gap_value = null, $should_skip_gap_serialization = false, $fallback_gap_value = '0.5em', $block_spacing = null ) {
$layout_type = isset( $layout['type'] ) ? $layout['type'] : 'default';
$layout_type = $layout['type'] ?? 'default';
$layout_styles = array();

if ( 'default' === $layout_type ) {
Expand Down Expand Up @@ -401,7 +401,10 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
$gap_sides = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' );

foreach ( $gap_sides as $gap_side ) {
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
$process_value = $gap_value;
if ( is_array( $gap_value ) ) {
$process_value = $gap_value[ $gap_side ] ?? $fallback_gap_value;
}
// Get spacing CSS variable from preset value if provided.
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
$index_to_splice = strrpos( $process_value, '|' ) + 1;
Expand Down Expand Up @@ -482,7 +485,10 @@ function gutenberg_get_layout_style( $selector, $layout, $has_block_gap_support
$gap_sides = is_array( $gap_value ) ? array( 'top', 'left' ) : array( 'top' );

foreach ( $gap_sides as $gap_side ) {
$process_value = is_string( $gap_value ) ? $gap_value : _wp_array_get( $gap_value, array( $gap_side ), $fallback_gap_value );
$process_value = $gap_value;
if ( is_array( $gap_value ) ) {
$process_value = $gap_value[ $gap_side ] ?? $fallback_gap_value;
}
// Get spacing CSS variable from preset value if provided.
if ( is_string( $process_value ) && str_contains( $process_value, 'var:preset|spacing|' ) ) {
$index_to_splice = strrpos( $process_value, '|' ) + 1;
Expand Down Expand Up @@ -594,8 +600,11 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
}

$global_settings = gutenberg_get_global_settings();
$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;
$fallback_layout = $block_type->supports['layout']['default'] ?? array();
if ( empty( $fallback_layout ) ) {
$fallback_layout = $block_type->supports['__experimentalLayout']['default'] ?? array();
}
$used_layout = $block['attrs']['layout'] ?? $fallback_layout;

$class_names = array();
$layout_definitions = gutenberg_get_layout_definitions();
Expand All @@ -606,7 +615,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$used_layout['type'] = 'constrained';
}

$root_padding_aware_alignments = _wp_array_get( $global_settings, array( 'useRootPaddingAwareAlignments' ), false );
$root_padding_aware_alignments = $global_settings['useRootPaddingAwareAlignments'] ?? false;

if ( $root_padding_aware_alignments && isset( $used_layout['type'] ) && 'constrained' === $used_layout['type'] ) {
$class_names[] = 'has-global-padding';
Expand All @@ -632,9 +641,9 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {

// Get classname for layout type.
if ( isset( $used_layout['type'] ) ) {
$layout_classname = _wp_array_get( $layout_definitions, array( $used_layout['type'], 'className' ), '' );
$layout_classname = $layout_definitions[ $used_layout['type'] ]['className'] ?? '';
} else {
$layout_classname = _wp_array_get( $layout_definitions, array( 'default', 'className' ), '' );
$layout_classname = $layout_definitions['default']['className'] ?? '';
}

if ( $layout_classname && is_string( $layout_classname ) ) {
Expand All @@ -647,7 +656,7 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
*/
if ( ! current_theme_supports( 'disable-layout-styles' ) ) {

$gap_value = _wp_array_get( $block, array( 'attrs', 'style', 'spacing', 'blockGap' ) );
$gap_value = $block['attrs']['style']['spacing']['blockGap'] ?? null;

/*
* Skip if gap value contains unsupported characters.
Expand All @@ -662,16 +671,16 @@ function gutenberg_render_layout_support_flag( $block_content, $block ) {
$gap_value = $gap_value && preg_match( '%[\\\(&=}]|/\*%', $gap_value ) ? null : $gap_value;
}

$fallback_gap_value = _wp_array_get( $block_type->supports, array( 'spacing', 'blockGap', '__experimentalDefault' ), '0.5em' );
$block_spacing = _wp_array_get( $block, array( 'attrs', 'style', 'spacing' ), null );
$fallback_gap_value = $block_type->supports['spacing']['blockGap']['__experimentalDefault'] ?? '0.5em';
$block_spacing = $block['attrs']['style']['spacing'] ?? null;

/*
* If a block's block.json skips serialization for spacing or spacing.blockGap,
* don't apply the user-defined value to the styles.
*/
$should_skip_gap_serialization = wp_should_skip_block_supports_serialization( $block_type, 'spacing', 'blockGap' );

$block_gap = _wp_array_get( $global_settings, array( 'spacing', 'blockGap' ), null );
$block_gap = $global_settings['spacing']['blockGap'] ?? null;
$has_block_gap_support = isset( $block_gap );

$style = gutenberg_get_layout_style(
Expand Down
10 changes: 5 additions & 5 deletions lib/block-supports/position.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ function gutenberg_render_position_support( $block_content, $block ) {
}

$global_settings = gutenberg_get_global_settings();
$theme_has_sticky_support = _wp_array_get( $global_settings, array( 'position', 'sticky' ), false );
$theme_has_fixed_support = _wp_array_get( $global_settings, array( 'position', 'fixed' ), false );
$theme_has_sticky_support = $global_settings['position']['sticky'] ?? false;
$theme_has_fixed_support = $global_settings['position']['fixed'] ?? false;

// Only allow output for position types that the theme supports.
$allowed_position_types = array();
Expand All @@ -56,11 +56,11 @@ function gutenberg_render_position_support( $block_content, $block ) {
$allowed_position_types[] = 'fixed';
}

$style_attribute = _wp_array_get( $block, array( 'attrs', 'style' ), null );
$style_attribute = $block['attrs']['style'] ?? null;
$class_name = wp_unique_id( 'wp-container-' );
$selector = ".$class_name";
$position_styles = array();
$position_type = _wp_array_get( $style_attribute, array( 'position', 'type' ), '' );
$position_type = $style_attribute['position']['type'] ?? '';
$wrapper_classes = array();

if (
Expand All @@ -71,7 +71,7 @@ function gutenberg_render_position_support( $block_content, $block ) {
$sides = array( 'top', 'right', 'bottom', 'left' );

foreach ( $sides as $side ) {
$side_value = _wp_array_get( $style_attribute, array( 'position', $side ) );
$side_value = $style_attribute['position'][ $side ] ?? null;
if ( null !== $side_value ) {
/*
* For fixed or sticky top positions,
Expand Down
Loading

0 comments on commit 219cf64

Please sign in to comment.