Skip to content

Commit

Permalink
Merge branch 'master' into rnmobile/audio-block-I-b
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-alexander committed Jan 18, 2021
2 parents 1a46994 + ea48942 commit f09c955
Show file tree
Hide file tree
Showing 162 changed files with 3,497 additions and 1,418 deletions.
3 changes: 3 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@
/lib @timothybjacobs @spacedmonkey
/lib/global-styles.php @timothybjabocs @spacedmonkey @nosolosw
/lib/experimental-default-theme.json @timothybjabocs @spacedmonkey @nosolosw
/lib/class-wp-theme-json.php @timothybjabocs @spacedmonkey @nosolosw
/lib/class-wp-theme-json-resolver.php @timothybjabocs @spacedmonkey @nosolosw
/phpunit/class-wp-theme-json-test.php @nosolosw

# Native (Unowned)
*.native.js @ghost
Expand Down
18 changes: 18 additions & 0 deletions .github/workflows/stale-issue-needs-info.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Close stale issues that requires info"
on:
schedule:
- cron: "30 1 * * *"

jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: 'Help us move this issue forward. Since it has no activity after 15 days of requesting more information, a bot is marking the issue as stale. Please add additional information as a comment or this issued will be closed in 5 days.'
close-issue-message: 'This issue was closed because more information was requested and there was no activity. If this is a bug report and still a problem, please supply the additional information requested and reopen the issue.'
days-before-stale: 15
days-before-close: 5
only-labels: '[Status] Needs More Info'
stale-issue-label: '[Status] Stale'
15 changes: 13 additions & 2 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

= 9.8.0-rc.1 =



### Enhancements

- Try: Transparent spacer. ([28103](https://github.com/WordPress/gutenberg/pull/28103))
Expand Down Expand Up @@ -131,6 +129,19 @@
- Add srcset for cover image. ([25171](https://github.com/WordPress/gutenberg/pull/25171))


= 9.7.4 =

### Bug Fixes

- Fix isRTL check by loading the ltr string explicitely.


= 9.7.3 =

### Bug Fixes

- Prevent mangle of translation functions to fix RTL locales.


= 9.7.2 =

Expand Down
6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1469,6 +1469,12 @@
"markdown_source": "../packages/core-data/README.md",
"parent": "packages"
},
{
"title": "@wordpress/create-block-tutorial-template",
"slug": "packages-create-block-tutorial-template",
"markdown_source": "../packages/create-block-tutorial-template/README.md",
"parent": "packages"
},
{
"title": "@wordpress/create-block",
"slug": "packages-create-block",
Expand Down
2 changes: 1 addition & 1 deletion lib/class-wp-theme-json-resolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ private static function get_user_origin() {
$config = $decoded_data;
}
}
self::$user = new WP_Theme_JSON( $config, true );
self::$user = new WP_Theme_JSON( $config );

return self::$user;
}
Expand Down
109 changes: 47 additions & 62 deletions lib/class-wp-theme-json.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,10 +293,9 @@ class WP_Theme_JSON {
/**
* Constructor.
*
* @param array $contexts A structure that follows the theme.json schema.
* @param boolean $should_escape_styles Whether the incoming styles should be escaped.
* @param array $contexts A structure that follows the theme.json schema.
*/
public function __construct( $contexts = array(), $should_escape_styles = false ) {
public function __construct( $contexts = array() ) {
$this->contexts = array();

if ( ! is_array( $contexts ) ) {
Expand All @@ -317,10 +316,10 @@ public function __construct( $contexts = array(), $should_escape_styles = false
// Process styles subtree.
$this->process_key( 'styles', $context, self::SCHEMA );
if ( isset( $context['styles'] ) ) {
$this->process_key( 'border', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'color', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'spacing', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'typography', $context['styles'], self::SCHEMA['styles'], $should_escape_styles );
$this->process_key( 'border', $context['styles'], self::SCHEMA['styles'] );
$this->process_key( 'color', $context['styles'], self::SCHEMA['styles'] );
$this->process_key( 'spacing', $context['styles'], self::SCHEMA['styles'] );
$this->process_key( 'typography', $context['styles'], self::SCHEMA['styles'] );

if ( empty( $context['styles'] ) ) {
unset( $context['styles'] );
Expand All @@ -346,43 +345,62 @@ public function __construct( $contexts = array(), $should_escape_styles = false
}
}

/**
* Returns the kebab-cased name of a given property.
*
* @param string $property Property name to convert.
* @return string kebab-cased name of the property
*/
private static function to_kebab_case( $property ) {
$mappings = self::get_case_mappings();
return $mappings['to_kebab_case'][ $property ];
}

/**
* Returns the property name of a kebab-cased property.
*
* @param string $property Property name to convert in kebab-case.
* @return string Name of the property
*/
private static function to_property( $property ) {
$mappings = self::get_case_mappings();
return $mappings['to_property'][ $property ];
}

/**
* Returns a mapping on metadata properties to avoid having to constantly
* transforms properties between camel case and kebab.
*
* @return array Containing three mappings
* "to_kebab_case" mapping properties in camel case to
* properties in kebab case e.g: "paddingTop" to "padding-top".
* "to_camel_case" mapping properties in kebab case to
* properties in camel case e.g: "padding-top" to "paddingTop".
* "to_property" mapping properties in kebab case to
* the main properties in camel case e.g: "padding-top" to "padding".
*/
private static function get_properties_metadata_case_mappings() {
static $properties_metadata_case_mappings;
if ( null === $properties_metadata_case_mappings ) {
$properties_metadata_case_mappings = array(
private static function get_case_mappings() {
static $case_mappings;
if ( null === $case_mappings ) {
$case_mappings = array(
'to_kebab_case' => array(),
'to_camel_case' => array(),
'to_property' => array(),
);
foreach ( self::PROPERTIES_METADATA as $key => $metadata ) {
$kebab_case = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $key ) );
$properties_metadata_case_mappings['to_kebab_case'][ $key ] = $kebab_case;
$properties_metadata_case_mappings['to_camel_case'][ $kebab_case ] = $key;
$properties_metadata_case_mappings['to_property'][ $kebab_case ] = $key;

$case_mappings['to_kebab_case'][ $key ] = $kebab_case;
$case_mappings['to_property'][ $kebab_case ] = $key;
if ( self::has_properties( $metadata ) ) {
foreach ( $metadata['properties'] as $property ) {
$camel_case = $key . ucfirst( $property );
$kebab_case = strtolower( preg_replace( '/(?<!^)[A-Z]/', '-$0', $camel_case ) );
$properties_metadata_case_mappings['to_kebab_case'][ $camel_case ] = $kebab_case;
$properties_metadata_case_mappings['to_camel_case'][ $kebab_case ] = $camel_case;
$properties_metadata_case_mappings['to_property'][ $kebab_case ] = $key;

$case_mappings['to_kebab_case'][ $camel_case ] = $kebab_case;
$case_mappings['to_property'][ $kebab_case ] = $key;
}
}
}
}
return $properties_metadata_case_mappings;
return $case_mappings;
}

/**
Expand Down Expand Up @@ -504,12 +522,11 @@ private static function get_blocks_metadata() {
* This function modifies the given input by removing
* the nodes that aren't valid per the schema.
*
* @param string $key Key of the subtree to normalize.
* @param array $input Whole tree to normalize.
* @param array $schema Schema to use for normalization.
* @param boolean $should_escape Whether the subproperties should be escaped.
* @param string $key Key of the subtree to normalize.
* @param array $input Whole tree to normalize.
* @param array $schema Schema to use for normalization.
*/
private static function process_key( $key, &$input, $schema, $should_escape = false ) {
private static function process_key( $key, &$input, $schema ) {
if ( ! isset( $input[ $key ] ) ) {
return;
}
Expand All @@ -529,36 +546,6 @@ private static function process_key( $key, &$input, $schema, $should_escape = fa
$schema[ $key ]
);

if ( $should_escape ) {
$subtree = $input[ $key ];
foreach ( $subtree as $property => $value ) {
$name = 'background-color';
if ( 'gradient' === $property ) {
$name = 'background';
}

if ( is_array( $value ) ) {
$result = array();
foreach ( $value as $subproperty => $subvalue ) {
$result_subproperty = safecss_filter_attr( "$name: $subvalue" );
if ( '' !== $result_subproperty ) {
$result[ $subproperty ] = $result_subproperty;
}
}

if ( empty( $result ) ) {
unset( $input[ $key ][ $property ] );
}
} else {
$result = safecss_filter_attr( "$name: $value" );

if ( '' === $result ) {
unset( $input[ $key ][ $property ] );
}
}
}
}

if ( 0 === count( $input[ $key ] ) ) {
unset( $input[ $key ] );
}
Expand Down Expand Up @@ -708,8 +695,7 @@ private static function compute_style_properties( &$declarations, $context, $con
if ( empty( $context['styles'] ) ) {
return;
}
$metadata_mappings = self::get_properties_metadata_case_mappings();
$properties = array();
$properties = array();
foreach ( self::PROPERTIES_METADATA as $name => $metadata ) {
if ( ! in_array( $name, $context_supports, true ) ) {
continue;
Expand All @@ -735,7 +721,7 @@ private static function compute_style_properties( &$declarations, $context, $con
foreach ( $properties as $prop ) {
$value = self::get_property_value( $context['styles'], $prop['value'] );
if ( ! empty( $value ) ) {
$kebab_cased_name = $metadata_mappings['to_kebab_case'][ $prop['name'] ];
$kebab_cased_name = self::to_kebab_case( $prop['name'] );
$declarations[] = array(
'name' => $kebab_cased_name,
'value' => $value,
Expand Down Expand Up @@ -1058,8 +1044,7 @@ public function merge( $theme_json ) {
* Removes insecure data from theme.json.
*/
public function remove_insecure_properties() {
$blocks_metadata = self::get_blocks_metadata();
$metadata_mappings = self::get_properties_metadata_case_mappings();
$blocks_metadata = self::get_blocks_metadata();
foreach ( $this->contexts as $context_name => &$context ) {
// Escape the context key.
if ( empty( $blocks_metadata[ $context_name ] ) ) {
Expand All @@ -1081,7 +1066,7 @@ public function remove_insecure_properties() {
if ( null === $escaped_styles ) {
$escaped_styles = array();
}
$property = $metadata_mappings['to_property'][ $declaration['name'] ];
$property = self::to_property( $declaration['name'] );
$path = self::PROPERTIES_METADATA[ $property ]['value'];
if ( self::has_properties( self::PROPERTIES_METADATA[ $property ] ) ) {
$declaration_divided = explode( '-', $declaration['name'] );
Expand Down
7 changes: 6 additions & 1 deletion lib/client-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ function gutenberg_override_script( $scripts, $handle, $src, $deps = array(), $v
if ( 'wp-i18n' !== $handle && 'wp-polyfill' !== $handle ) {
$scripts->set_translations( $handle, 'default' );
}
if ( 'wp-i18n' === $handle ) {
$ltr = 'rtl' === _x( 'ltr', 'text direction', 'default' ) ? 'rtl' : 'ltr';
$output = sprintf( "wp.i18n.setLocaleData( { 'text direction\u0004ltr': [ '%s' ] }, 'default' );", $ltr );
$scripts->add_inline_script( 'wp-i18n', $output, 'after' );
}
}

/**
Expand Down Expand Up @@ -311,7 +316,7 @@ function gutenberg_register_packages_styles( $styles ) {
$styles,
'wp-block-editor',
gutenberg_url( 'build/block-editor/style.css' ),
array( 'wp-components', 'wp-editor-font' ),
array( 'wp-components' ),
filemtime( gutenberg_dir_path() . 'build/editor/style.css' )
);
$styles->add_data( 'wp-block-editor', 'rtl', 'replace' );
Expand Down
45 changes: 43 additions & 2 deletions lib/full-site-editing/block-templates.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,42 @@ function _gutenberg_get_template_files( $template_type ) {
return $template_files;
}

/**
* Parses wp_template content and injects the current theme's
* stylesheet as a theme attribute into each wp_template_part
*
* @param string $template_content serialized wp_template content.
* @param string $theme the active theme's stylesheet.
*
* @return string Updated wp_template content.
*/
function _inject_theme_attribute_in_content( $template_content, $theme ) {
$has_updated_content = false;
$new_content = '';
$template_blocks = parse_blocks( $template_content );

foreach ( $template_blocks as $key => $block ) {
if (
'core/template-part' === $block['blockName'] &&
! isset( $block['attrs']['theme'] ) &&
wp_get_theme()->get_stylesheet() === $theme
) {
$template_blocks[ $key ]['attrs']['theme'] = $theme;
$has_updated_content = true;
}
}

if ( $has_updated_content ) {
foreach ( $template_blocks as $block ) {
$new_content .= serialize_block( $block );
}

return $new_content;
} else {
return $template_content;
}
}

/**
* Build a unified template object based on a theme file.
*
Expand All @@ -115,12 +151,17 @@ function _gutenberg_get_template_files( $template_type ) {
*/
function _gutenberg_build_template_result_from_file( $template_file, $template_type ) {
$default_template_types = gutenberg_get_default_template_types();
$template_content = file_get_contents( $template_file['path'] );
$theme = wp_get_theme()->get_stylesheet();

if ( 'wp_template' === $template_type ) {
$template_content = _inject_theme_attribute_in_content( $template_content, $theme );
}

$theme = wp_get_theme()->get_stylesheet();
$template = new WP_Block_Template();
$template->id = $theme . '//' . $template_file['slug'];
$template->theme = $theme;
$template->content = file_get_contents( $template_file['path'] );
$template->content = $template_content;
$template->slug = $template_file['slug'];
$template->is_custom = false;
$template->type = $template_type;
Expand Down
4 changes: 2 additions & 2 deletions lib/full-site-editing/default-template-types.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function gutenberg_get_default_template_types() {
),
'singular' => array(
'title' => _x( 'Singular', 'Template name', 'gutenberg' ),
'description' => __( 'Used when a single entry is queried. This template will be overridden the Single, Post, and Page templates where appropriate', 'gutenberg' ),
'description' => __( 'Used when a single entry is queried. This template will be overridden by the Single, Post, and Page templates where appropriate', 'gutenberg' ),
),
'single' => array(
'title' => _x( 'Single', 'Template name', 'gutenberg' ),
Expand All @@ -43,7 +43,7 @@ function gutenberg_get_default_template_types() {
),
'archive' => array(
'title' => _x( 'Archive', 'Template name', 'gutenberg' ),
'description' => __( 'Used when multiple entries are queried. This template will be overridden the Category, Author, and Date templates where appropriate', 'gutenberg' ),
'description' => __( 'Used when multiple entries are queried. This template will be overridden by the Category, Author, and Date templates where appropriate', 'gutenberg' ),
),
'author' => array(
'title' => _x( 'Author Archive', 'Template name', 'gutenberg' ),
Expand Down
Loading

0 comments on commit f09c955

Please sign in to comment.