Skip to content

Commit

Permalink
Merge branch 'trunk' into update/checkbox-appearance-conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
jameskoster committed Feb 23, 2024
2 parents 109ddee + 6889c88 commit a05e5ea
Show file tree
Hide file tree
Showing 322 changed files with 3,296 additions and 1,121 deletions.
252 changes: 252 additions & 0 deletions changelog.txt

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1679,6 +1679,12 @@
"markdown_source": "../packages/interactivity/README.md",
"parent": "packages"
},
{
"title": "API Reference",
"slug": "packages-interactivity-api-reference",
"markdown_source": "../packages/interactivity/docs/api-reference.md",
"parent": "packages-interactivity"
},
{
"title": "@wordpress/interface",
"slug": "packages-interface",
Expand Down
4 changes: 2 additions & 2 deletions docs/reference-guides/data/data-core-block-editor.md
Original file line number Diff line number Diff line change
Expand Up @@ -1263,15 +1263,15 @@ Action that hides the insertion point.

### insertAfterBlock

Action that inserts an empty block after a given block.
Action that inserts a default block after a given block.

_Parameters_

- _clientId_ `string`:

### insertBeforeBlock

Action that inserts an empty block before a given block.
Action that inserts a default block before a given block.

_Parameters_

Expand Down
2 changes: 1 addition & 1 deletion gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Description: Printing since 1440. This is the development plugin for the block editor, site editor, and other future WordPress core functionality.
* Requires at least: 6.3
* Requires PHP: 7.0
* Version: 17.7.0
* Version: 17.8.0-rc.1
* Author: Gutenberg Team
* Text Domain: gutenberg
*
Expand Down
6 changes: 6 additions & 0 deletions lib/class-wp-theme-json-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -3807,12 +3807,18 @@ private static function resolve_custom_css_format( $tree ) {
* Replaces CSS variables with their values in place.
*
* @since 6.3.0
* @since 6.6.0 Check for empty style before processing.
*
* @param array $styles CSS declarations to convert.
* @param array $values key => value pairs to use for replacement.
* @return array
*/
private static function convert_variables_to_value( $styles, $values ) {
foreach ( $styles as $key => $style ) {
if ( empty( $style ) ) {
continue;
}

if ( is_array( $style ) ) {
$styles[ $key ] = self::convert_variables_to_value( $style, $values );
continue;
Expand Down
71 changes: 52 additions & 19 deletions lib/compat/wordpress-6.5/fonts/class-wp-font-collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ final class WP_Font_Collection {
*
* @since 6.5.0
*
* @param string $slug Font collection slug.
* @param array|string $data_or_file Font collection data array or a path/URL to a JSON file
* containing the font collection.
* See {@see wp_register_font_collection()} for the supported fields.
* @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
* and underscores. See sanitize_title().
* @param array $args Font collection data. See wp_register_font_collection() for information on accepted arguments.
*/
public function __construct( $slug, $data_or_file ) {
public function __construct( string $slug, array $args ) {
$this->slug = sanitize_title( $slug );
if ( $this->slug !== $slug ) {
_doing_it_wrong(
Expand All @@ -64,12 +63,17 @@ public function __construct( $slug, $data_or_file ) {
);
}

if ( is_array( $data_or_file ) ) {
$this->data = $this->sanitize_and_validate_data( $data_or_file );
} else {
$required_properties = array( 'name', 'font_families' );

if ( isset( $args['font_families'] ) && is_string( $args['font_families'] ) ) {
// JSON data is lazy loaded by ::get_data().
$this->src = $data_or_file;
$this->src = $args['font_families'];
unset( $args['font_families'] );

$required_properties = array( 'name' );
}

$this->data = $this->sanitize_and_validate_data( $args, $required_properties );
}

/**
Expand All @@ -80,8 +84,12 @@ public function __construct( $slug, $data_or_file ) {
* @return array|WP_Error An array containing the font collection data, or a WP_Error on failure.
*/
public function get_data() {
if ( is_wp_error( $this->data ) ) {
return $this->data;
}

// If the collection uses JSON data, load it and cache the data/error.
if ( $this->src && empty( $this->data ) ) {
if ( isset( $this->src ) ) {
$this->data = $this->load_from_json( $this->src );
}

Expand Down Expand Up @@ -118,7 +126,26 @@ private function load_from_json( $file_or_url ) {
return new WP_Error( 'font_collection_json_missing', $message );
}

return $url ? $this->load_from_url( $url ) : $this->load_from_file( $file );
$data = $url ? $this->load_from_url( $url ) : $this->load_from_file( $file );

if ( is_wp_error( $data ) ) {
return $data;
}

$data = array(
'name' => $this->data['name'],
'font_families' => $data['font_families'],
);

if ( isset( $this->data['description'] ) ) {
$data['description'] = $this->data['description'];
}

if ( isset( $this->data['categories'] ) ) {
$data['categories'] = $this->data['categories'];
}

return $data;
}

/**
Expand All @@ -136,7 +163,7 @@ private function load_from_file( $file ) {
return new WP_Error( 'font_collection_decode_error', __( 'Error decoding the font collection JSON file contents.', 'gutenberg' ) );
}

return $this->sanitize_and_validate_data( $data );
return $this->sanitize_and_validate_data( $data, array( 'font_families' ) );
}

/**
Expand All @@ -156,8 +183,14 @@ private function load_from_url( $url ) {
if ( false === $data ) {
$response = wp_safe_remote_get( $url );
if ( is_wp_error( $response ) || 200 !== wp_remote_retrieve_response_code( $response ) ) {
// translators: %s: Font collection URL.
return new WP_Error( 'font_collection_request_error', sprintf( __( 'Error fetching the font collection data from "%s".', 'gutenberg' ), $url ) );
return new WP_Error(
'font_collection_request_error',
sprintf(
// translators: %s: Font collection URL.
__( 'Error fetching the font collection data from "%s".', 'gutenberg' ),
$url
)
);
}

$data = json_decode( wp_remote_retrieve_body( $response ), true );
Expand All @@ -166,7 +199,7 @@ private function load_from_url( $url ) {
}

// Make sure the data is valid before storing it in a transient.
$data = $this->sanitize_and_validate_data( $data );
$data = $this->sanitize_and_validate_data( $data, array( 'font_families' ) );
if ( is_wp_error( $data ) ) {
return $data;
}
Expand All @@ -182,18 +215,18 @@ private function load_from_url( $url ) {
*
* @since 6.5.0
*
* @param array $data Font collection data to sanitize and validate.
* @param array $data Font collection data to sanitize and validate.
* @param array $required_properties Required properties that must exist in the passed data.
* @return array|WP_Error Sanitized data if valid, otherwise a WP_Error instance.
*/
private function sanitize_and_validate_data( $data ) {
private function sanitize_and_validate_data( $data, $required_properties = array() ) {
$schema = self::get_sanitization_schema();
$data = WP_Font_Utils::sanitize_from_schema( $data, $schema );

$required_properties = array( 'name', 'font_families' );
foreach ( $required_properties as $property ) {
if ( empty( $data[ $property ] ) ) {
$message = sprintf(
// translators: 1: Font collection slug, 2: Missing property name, e.g. "font_families".
// translators: 1: Font collection slug, 2: Missing property name, e.g. "font_families".
__( 'Font collection "%1$s" has missing or empty property: "%2$s".', 'gutenberg' ),
$this->slug,
$property
Expand Down
19 changes: 9 additions & 10 deletions lib/compat/wordpress-6.5/fonts/class-wp-font-library.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,19 @@ class WP_Font_Library {
*
* @since 6.5.0
*
* @param string $slug Font collection slug.
* @param array $data_or_file Font collection data array or a path/URL to a JSON file
* containing the font collection.
* See {@see wp_register_font_collection()} for the supported fields.
* @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
* and underscores. See sanitize_title().
* @param array $args Font collection data. See wp_register_font_collection() for information on accepted arguments.
* @return WP_Font_Collection|WP_Error A font collection if it was registered successfully,
* or WP_Error object on failure.
*/
public function register_font_collection( $slug, $data_or_file ) {
$new_collection = new WP_Font_Collection( $slug, $data_or_file );
public function register_font_collection( string $slug, array $args ) {
$new_collection = new WP_Font_Collection( $slug, $args );

if ( $this->is_collection_registered( $new_collection->slug ) ) {
$error_message = sprintf(
/* translators: %s: Font collection slug. */
__( 'Font collection with slug "%s" is already registered.', 'gutenberg' ),
__( 'Font collection with slug: "%s" is already registered.', 'gutenberg' ),
$new_collection->slug
);
_doing_it_wrong(
Expand All @@ -74,7 +73,7 @@ public function register_font_collection( $slug, $data_or_file ) {
* @param string $slug Font collection slug.
* @return bool True if the font collection was unregistered successfully and false otherwise.
*/
public function unregister_font_collection( $slug ) {
public function unregister_font_collection( string $slug ) {
if ( ! $this->is_collection_registered( $slug ) ) {
_doing_it_wrong(
__METHOD__,
Expand All @@ -96,7 +95,7 @@ public function unregister_font_collection( $slug ) {
* @param string $slug Font collection slug.
* @return bool True if the font collection is registered and false otherwise.
*/
private function is_collection_registered( $slug ) {
private function is_collection_registered( string $slug ) {
return array_key_exists( $slug, $this->collections );
}

Expand All @@ -119,7 +118,7 @@ public function get_font_collections() {
* @param string $slug Font collection slug.
* @return WP_Font_Collection|null Font collection object, or null if the font collection doesn't exist.
*/
public function get_font_collection( $slug ) {
public function get_font_collection( string $slug ) {
if ( $this->is_collection_registered( $slug ) ) {
return $this->collections[ $slug ];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function get_items( $request ) {
$response = rest_ensure_response( $items );

$response->header( 'X-WP-Total', (int) $total_items );
$response->header( 'X-WP-TotalPages', (int) $max_pages );
$response->header( 'X-WP-TotalPages', $max_pages );

$request_params = $request->get_query_params();
$collection_url = rest_url( $this->namespace . '/' . $this->rest_base );
Expand Down
61 changes: 46 additions & 15 deletions lib/compat/wordpress-6.5/fonts/fonts.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,28 +114,30 @@ function gutenberg_init_font_library() {

if ( ! function_exists( 'wp_register_font_collection' ) ) {
/**
* Registers a new Font Collection in the Font Library.
* Registers a new font collection in the font library.
*
* See {@link https://schemas.wp.org/trunk/font-collection.json} for the schema
* the font collection data must adhere to.
*
* @since 6.5.0
*
* @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
* @param string $slug Font collection slug. May only contain alphanumeric characters, dashes,
* and underscores. See sanitize_title().
* @param array|string $data_or_file {
* Font collection data array or a path/URL to a JSON file containing the font collection.
*
* @link https://schemas.wp.org/trunk/font-collection.json
* @param array $args {
* Font collection data.
*
* @type string $name Required. Name of the font collection shown in the Font Library.
* @type string $description Optional. A short descriptive summary of the font collection. Default empty.
* @type array $font_families Required. Array of font family definitions that are in the collection.
* @type array $categories Optional. Array of categories, each with a name and slug, that are used by the
* fonts in the collection. Default empty.
* @type string $name Required. Name of the font collection shown in the Font Library.
* @type string $description Optional. A short descriptive summary of the font collection. Default empty.
* @type array|string $font_families Required. Array of font family definitions that are in the collection,
* or a string containing the path or URL to a JSON file containing the font collection.
* @type array $categories Optional. Array of categories, each with a name and slug, that are used by the
* fonts in the collection. Default empty.
* }
* @return WP_Font_Collection|WP_Error A font collection if it was registered
* successfully, or WP_Error object on failure.
*/
function wp_register_font_collection( $slug, $data_or_file ) {
return WP_Font_Library::get_instance()->register_font_collection( $slug, $data_or_file );
function wp_register_font_collection( string $slug, array $args ) {
return WP_Font_Library::get_instance()->register_font_collection( $slug, $args );
}
}

Expand All @@ -148,7 +150,7 @@ function wp_register_font_collection( $slug, $data_or_file ) {
* @param string $slug Font collection slug.
* @return bool True if the font collection was unregistered successfully, else false.
*/
function wp_unregister_font_collection( $slug ) {
function wp_unregister_font_collection( string $slug ) {
return WP_Font_Library::get_instance()->unregister_font_collection( $slug );
}
}
Expand All @@ -157,7 +159,36 @@ function gutenberg_register_font_collections() {
if ( null !== WP_Font_Library::get_instance()->get_font_collection( 'google-fonts' ) ) {
return;
}
wp_register_font_collection( 'google-fonts', 'https://s.w.org/images/fonts/17.7/collections/google-fonts-with-preview.json' );
wp_register_font_collection(
'google-fonts',
array(
'name' => _x( 'Google Fonts', 'font collection name', 'gutenberg' ),
'description' => __( 'Install from Google Fonts. Fonts are copied to and served from your site.', 'gutenberg' ),
'font_families' => 'https://s.w.org/images/fonts/17.7/collections/google-fonts-with-preview.json',
'categories' => array(
array(
'name' => _x( 'Sans Serif', 'font category', 'gutenberg' ),
'slug' => 'sans-serif',
),
array(
'name' => _x( 'Display', 'font category', 'gutenberg' ),
'slug' => 'display',
),
array(
'name' => _x( 'Serif', 'font category', 'gutenberg' ),
'slug' => 'serif',
),
array(
'name' => _x( 'Handwriting', 'font category', 'gutenberg' ),
'slug' => 'handwriting',
),
array(
'name' => _x( 'Monospace', 'font category', 'gutenberg' ),
'slug' => 'monospace',
),
),
)
);
}
add_action( 'init', 'gutenberg_register_font_collections', 11 );

Expand Down
3 changes: 3 additions & 0 deletions lib/experimental/editor-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ function gutenberg_enable_experiments() {
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-color-randomizer', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableColorRandomizer = true', 'before' );
}
if ( $gutenberg_experiments && array_key_exists( 'gutenberg-grid-interactivity', $gutenberg_experiments ) ) {
wp_add_inline_script( 'wp-block-editor', 'window.__experimentalEnableGridInteractivity = true', 'before' );
}
if ( gutenberg_is_experiment_enabled( 'gutenberg-no-tinymce' ) ) {
wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' );
}
Expand Down
14 changes: 14 additions & 0 deletions lib/experiments-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-color-randomizer',
)
);

add_settings_field(
'gutenberg-form-blocks',
__( 'Form and input blocks ', 'gutenberg' ),
Expand All @@ -101,6 +102,19 @@ function gutenberg_initialize_experiments_settings() {
'id' => 'gutenberg-form-blocks',
)
);

add_settings_field(
'gutenberg-grid-interactivity',
__( 'Grid interactivty ', 'gutenberg' ),
'gutenberg_display_experiment_field',
'gutenberg-experiments',
'gutenberg_experiments_section',
array(
'label' => __( 'Test enhancements to the Grid block that let you move and resize items in the editor canvas.', 'gutenberg' ),
'id' => 'gutenberg-grid-interactivity',
)
);

add_settings_field(
'gutenberg-no-tinymce',
__( 'Disable TinyMCE and Classic block', 'gutenberg' ),
Expand Down
Loading

0 comments on commit a05e5ea

Please sign in to comment.