Skip to content

Commit

Permalink
prep build 6/18
Browse files Browse the repository at this point in the history
  • Loading branch information
bph committed Jun 18, 2024
2 parents 0f9c653 + c6e7ddb commit 02c1cb4
Show file tree
Hide file tree
Showing 59 changed files with 476 additions and 439 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/check-backport-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: Verify Core Backport Changlog
on:
pull_request:
types: [opened, synchronize, labeled, unlabeled]
branches:
- trunk
paths:
- 'lib/**'
- '!lib/load.php'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/check-components-changelog.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ name: OPTIONAL - Verify @wordpress/components CHANGELOG update
on:
pull_request:
types: [opened, synchronize]
branches:
- trunk
paths:
- 'packages/components/**'
- '!packages/components/src/**/stories/**'
Expand Down
3 changes: 3 additions & 0 deletions backport-changelog/6.6/6844.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
https://github.com/WordPress/wordpress-develop/pull/6844

* https://github.com/WordPress/gutenberg/pull/62640
11 changes: 11 additions & 0 deletions bin/cherry-pick.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,25 @@ async function fetchPRs() {
* @return {Promise<Object>} Parsed response JSON.
*/
async function GitHubFetch( path ) {
const token = getGitHubAuthToken();
const response = await fetch( 'https://api.github.com' + path, {
headers: {
Accept: 'application/vnd.github.v3+json',
Authorization: `Bearer ${ token }`,
},
} );
return await response.json();
}

/**
* Retrieves the GitHub authentication token using `gh auth token`.
*
* @return {string} The GitHub authentication token.
*/
function getGitHubAuthToken() {
return cli( 'gh', [ 'auth', 'token' ] );
}

/**
* Attempts to cherry-pick given PRs using `git` CLI command.
*
Expand Down
2 changes: 1 addition & 1 deletion docs/contributors/code/coding-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ do so by opting-in to `@wordpress/private-apis`:
import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';
export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/block-editor' // Name of the package calling __dangerousOptInToUnstableAPIsOnlyForCoreModules,
// (not the name of the package whose APIs you want to access)
);
Expand Down
2 changes: 1 addition & 1 deletion docs/reference-guides/block-api/block-edit-save.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ When saving your block, you want to save the attributes in the same format speci

## Examples

Here are a couple examples of using attributes, edit, and save all together. For a full working example, see the [Introducing Attributes and Editable Fields](/docs/how-to-guides/block-tutorial/introducing-attributes-and-editable-fields.md) section of the Block Tutorial.
Here are a couple examples of using attributes, edit, and save all together.

### Saving Attributes to Child Elements

Expand Down
59 changes: 0 additions & 59 deletions lib/block-supports/block-style-variations.php
Original file line number Diff line number Diff line change
Expand Up @@ -475,62 +475,3 @@ function gutenberg_register_block_style_variations_from_theme_json_data( $variat
}
}
}

/**
* Register shared block style variations defined by the theme.
*
* These can come in three forms:
* - the theme's theme.json
* - the theme's partials (standalone files in `/styles` that only define block style variations)
* - the user's theme.json (for example, theme style variations the user selected)
*
* @access private
*/
function gutenberg_register_block_style_variations_from_theme() {
/*
* Skip any registration of styles if no theme.json or variation partials are present.
*
* Given the possibility of hybrid themes, this check can't rely on if the theme
* is a block theme or not. Instead:
* - If there is a primary theme.json, continue.
* - If there is a partials directory, continue.
* - The only variations to be registered from the global styles user origin,
* are those that have been copied in from the selected theme style variation.
* For a theme style variation to be selected it would have to have a partial
* theme.json file covered by the previous check.
*/
$has_partials_directory = is_dir( get_stylesheet_directory() . '/styles' ) || is_dir( get_template_directory() . '/styles' );
if ( ! wp_theme_has_theme_json() && ! $has_partials_directory ) {
return;
}

// Partials from `/styles`.
$variations_partials = WP_Theme_JSON_Resolver_Gutenberg::get_style_variations( 'block' );
gutenberg_register_block_style_variations_from_theme_json_data( $variations_partials );

/*
* Pull the data from the specific origin instead of the merged data.
* This is because, for 6.6, we only support registering block style variations
* for the 'theme' and 'custom' origins but not for 'default' (core theme.json)
* or 'custom' (theme.json in a block).
*
* When/If we add support for every origin, we should switch to using the public API
* instead, e.g.: wp_get_global_styles( array( 'blocks', 'variations' ) ).
*/

// theme.json of the theme.
$theme_json_theme = WP_Theme_JSON_Resolver_Gutenberg::get_theme_data();
$variations_theme = $theme_json_theme->get_data()['styles']['blocks']['variations'] ?? array();
gutenberg_register_block_style_variations_from_theme_json_data( $variations_theme );

// User data linked for this theme.
$theme_json_user = WP_Theme_JSON_Resolver_Gutenberg::get_user_data();
$variations_user = $theme_json_user->get_data()['styles']['blocks']['variations'] ?? array();
gutenberg_register_block_style_variations_from_theme_json_data( $variations_user );
}

// Remove core init action registering variations.
if ( function_exists( 'wp_register_block_style_variations_from_theme' ) ) {
remove_action( 'init', 'wp_register_block_style_variations_from_theme' );
}
add_action( 'init', 'gutenberg_register_block_style_variations_from_theme' );
22 changes: 6 additions & 16 deletions lib/class-wp-rest-global-styles-controller-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -331,22 +331,12 @@ protected function prepare_item_for_database( $request ) {
$config['styles'] = $existing_config['styles'];
}

/*
* If the incoming request is going to create a new variation
* that is not yet registered, we register it here.
* This is because the variations are registered on init,
* but we want this endpoint to return the new variation immediately:
* if we don't register it, it'll be stripped out of the response
* just in this request (subsequent ones will be ok).
* Take the variations defined in styles.blocks.variations from the incoming request
* that are not part of the $existing_config.
*/
if ( isset( $request['styles']['blocks']['variations'] ) ) {
$existing_variations = isset( $existing_config['styles']['blocks']['variations'] ) ? $existing_config['styles']['blocks']['variations'] : array();
$new_variations = array_diff_key( $request['styles']['blocks']['variations'], $existing_variations );
if ( ! empty( $new_variations ) ) {
gutenberg_register_block_style_variations_from_theme_json_data( $new_variations );
}
// Register theme-defined variations.
WP_Theme_JSON_Resolver_Gutenberg::get_theme_data();

// Register user-defined variations.
if ( isset( $request['styles']['blocks']['variations'] ) && ! empty( $config['styles']['blocks']['variations'] ) ) {
gutenberg_register_block_style_variations_from_theme_json_data( $config['styles']['blocks']['variations'] );
}

if ( isset( $request['settings'] ) ) {
Expand Down
14 changes: 13 additions & 1 deletion lib/class-wp-theme-json-resolver-gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,14 @@ public static function get_theme_data( $deprecated = array(), $options = array()
$theme_json_data = array( 'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA );
}

// Register variations defined by the theme.
$variations = $theme_json_data['styles']['blocks']['variations'] ?? array();
gutenberg_register_block_style_variations_from_theme_json_data( $variations );

// Register variations defined by theme partials (theme.json files in the styles directory).
$variations = static::get_style_variations( 'block' );
gutenberg_register_block_style_variations_from_theme_json_data( $variations );

/**
* Filters the data provided by the theme for global styles and settings.
*
Expand Down Expand Up @@ -539,6 +547,10 @@ public static function get_user_data() {
}
}

// Register variations defined by the user.
$variations = $config['styles']['blocks']['variations'] ?? array();
gutenberg_register_block_style_variations_from_theme_json_data( $variations );

/** This filter is documented in wp-includes/class-wp-theme-json-resolver.php */
$theme_json = apply_filters( 'wp_theme_json_data_user', new WP_Theme_JSON_Data_Gutenberg( $config, 'custom' ) );
static::$user = $theme_json->get_theme_json();
Expand Down Expand Up @@ -761,7 +773,7 @@ public static function get_style_variations( $scope = 'theme' ) {
}
ksort( $variation_files );
foreach ( $variation_files as $path => $file ) {
$decoded_file = wp_json_file_decode( $path, array( 'associative' => true ) );
$decoded_file = self::read_json_file( $path );
if ( is_array( $decoded_file ) && static::style_variation_has_scope( $decoded_file, $scope ) ) {
$translated = static::translate( $decoded_file, wp_get_theme()->get( 'TextDomain' ) );
$variation = ( new WP_Theme_JSON_Gutenberg( $translated ) )->get_raw_data();
Expand Down
2 changes: 2 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/block-directory/src/lock-unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/block-directory'
);
25 changes: 21 additions & 4 deletions packages/block-editor/src/hooks/block-style-variation.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@ import { useStyleOverride } from './utils';
import { store as blockEditorStore } from '../store';
import { globalStylesDataKey } from '../store/private-keys';

const VARIATION_PREFIX = 'is-style-';

function getVariationMatches( className ) {
if ( ! className ) {
return [];
}
return className.split( /\s+/ ).reduce( ( matches, name ) => {
if ( name.startsWith( VARIATION_PREFIX ) ) {
const match = name.slice( VARIATION_PREFIX.length );
if ( match !== 'default' ) {
matches.push( match );
}
}
return matches;
}, [] );
}

/**
* Get the first block style variation that has been registered from the class string.
*
Expand All @@ -28,14 +45,13 @@ import { globalStylesDataKey } from '../store/private-keys';
function getVariationNameFromClass( className, registeredStyles = [] ) {
// The global flag affects how capturing groups work in JS. So the regex
// below will only return full CSS classes not just the variation name.
const matches = className?.match( /\bis-style-(?!default)(\S+)\b/g );
const matches = getVariationMatches( className );

if ( ! matches ) {
return null;
}

for ( const variationClass of matches ) {
const variation = variationClass.substring( 9 ); // Remove 'is-style-' prefix.
for ( const variation of matches ) {
if ( registeredStyles.some( ( style ) => style.name === variation ) ) {
return variation;
}
Expand Down Expand Up @@ -94,7 +110,7 @@ function useBlockProps( { name, className, clientId } ) {

const registeredStyles = getBlockStyles( name );
const variation = getVariationNameFromClass( className, registeredStyles );
const variationClass = `is-style-${ variation }-${ clientId }`;
const variationClass = `${ VARIATION_PREFIX }${ variation }-${ clientId }`;

const { settings, styles } = useBlockStyleVariation(
name,
Expand Down Expand Up @@ -153,5 +169,6 @@ function useBlockProps( { name, className, clientId } ) {
export default {
hasSupport: () => true,
attributeKeys: [ 'className' ],
isMatch: ( { className } ) => getVariationMatches( className ).length > 0,
useBlockProps,
};
4 changes: 3 additions & 1 deletion packages/block-editor/src/hooks/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export function createBlockListBlockFilter( features ) {
hasSupport,
attributeKeys = [],
useBlockProps,
isMatch,
} = feature;

const neededProps = {};
Expand All @@ -595,7 +596,8 @@ export function createBlockListBlockFilter( features ) {
// Skip rendering if none of the needed attributes are
// set.
! Object.keys( neededProps ).length ||
! hasSupport( props.name )
! hasSupport( props.name ) ||
( isMatch && ! isMatch( neededProps ) )
) {
return null;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/lock-unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/block-editor'
);
2 changes: 1 addition & 1 deletion packages/block-library/src/lock-unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/block-library'
);
6 changes: 4 additions & 2 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,9 +519,11 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
';
}

$overlay_inline_styles = esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) );

return sprintf(
'<button aria-haspopup="dialog" %3$s class="%6$s" %10$s>%8$s</button>
<div class="%5$s" style="%7$s" id="%1$s" %11$s>
<div class="%5$s" %7$s id="%1$s" %11$s>
<div class="wp-block-navigation__responsive-close" tabindex="-1">
<div class="wp-block-navigation__responsive-dialog" %12$s>
<button %4$s class="wp-block-navigation__responsive-container-close" %13$s>%9$s</button>
Expand All @@ -537,7 +539,7 @@ private static function get_responsive_container_markup( $attributes, $inner_blo
$toggle_aria_label_close,
esc_attr( implode( ' ', $responsive_container_classes ) ),
esc_attr( implode( ' ', $open_button_classes ) ),
esc_attr( safecss_filter_attr( $colors['overlay_inline_styles'] ) ),
( ! empty( $overlay_inline_styles ) ) ? "style=\"$overlay_inline_styles\"" : '',
$toggle_button_content,
$toggle_close_button_content,
$open_button_directives,
Expand Down
20 changes: 0 additions & 20 deletions packages/block-library/src/social-link/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,11 @@ import clsx from 'clsx';
/**
* WordPress dependencies
*/
import { DELETE, BACKSPACE } from '@wordpress/keycodes';
import { useDispatch } from '@wordpress/data';

import {
InspectorControls,
URLPopover,
URLInput,
useBlockProps,
store as blockEditorStore,
} from '@wordpress/block-editor';
import { useState } from '@wordpress/element';
import {
Expand All @@ -36,9 +32,7 @@ const SocialLinkURLPopover = ( {
setAttributes,
setPopover,
popoverAnchor,
clientId,
} ) => {
const { removeBlock } = useDispatch( blockEditorStore );
return (
<URLPopover
anchor={ popoverAnchor }
Expand All @@ -62,18 +56,6 @@ const SocialLinkURLPopover = ( {
label={ __( 'Enter social link' ) }
hideLabelFromVision
disableSuggestions
onKeyDown={ ( event ) => {
if (
!! url ||
event.defaultPrevented ||
! [ BACKSPACE, DELETE ].includes(
event.keyCode
)
) {
return;
}
removeBlock( clientId );
} }
/>
</div>
<Button
Expand All @@ -91,7 +73,6 @@ const SocialLinkEdit = ( {
context,
isSelected,
setAttributes,
clientId,
} ) => {
const { url, service, label = '', rel } = attributes;
const {
Expand Down Expand Up @@ -178,7 +159,6 @@ const SocialLinkEdit = ( {
setAttributes={ setAttributes }
setPopover={ setPopover }
popoverAnchor={ popoverAnchor }
clientId={ clientId }
/>
) }
</li>
Expand Down
2 changes: 1 addition & 1 deletion packages/blocks/src/lock-unlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/pri

export const { lock, unlock } =
__dangerousOptInToUnstableAPIsOnlyForCoreModules(
'I know using unstable features means my theme or plugin will inevitably break in the next version of WordPress.',
'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',
'@wordpress/blocks'
);
Loading

0 comments on commit 02c1cb4

Please sign in to comment.