Skip to content

Commit

Permalink
Merge branch 'trunk' of github.com:WordPress/gutenberg into enhanceme…
Browse files Browse the repository at this point in the history
…nt/resolution-option-for-featured-image-media-text-block
  • Loading branch information
akasunil committed Dec 3, 2024
2 parents 3e9bc8c + 680fef5 commit 91dd5e1
Show file tree
Hide file tree
Showing 84 changed files with 872 additions and 430 deletions.
1 change: 1 addition & 0 deletions backport-changelog/6.8/7687.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
https://github.com/WordPress/wordpress-develop/pull/7687

* https://github.com/WordPress/gutenberg/pull/66488
* https://github.com/WordPress/gutenberg/pull/67497
3 changes: 3 additions & 0 deletions backport-changelog/6.8/7695.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
https://github.com/WordPress/wordpress-develop/pull/7695

* https://github.com/WordPress/gutenberg/pull/66631
* https://github.com/WordPress/gutenberg/pull/67465
* https://github.com/WordPress/gutenberg/pull/66579
* https://github.com/WordPress/gutenberg/pull/66654
23 changes: 21 additions & 2 deletions lib/compat/wordpress-6.8/preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,26 @@
*/
function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
if ( 'core/edit-site' === $context->name ) {
if ( ! empty( $_GET['postId'] ) ) {
$route_for_post = rest_get_route_for_post( $_GET['postId'] );
$post = null;
if ( isset( $_GET['postId'] ) && is_numeric( $_GET['postId'] ) ) {
$post = get_post( (int) $_GET['postId'] );
}
if ( isset( $_GET['p'] ) && preg_match( '/^\/page\/(\d+)$/', $_GET['p'], $matches ) ) {
$post = get_post( (int) $matches[1] );
}

if ( $post ) {
$route_for_post = rest_get_route_for_post( $post );
if ( $route_for_post ) {
$paths[] = add_query_arg( 'context', 'edit', $route_for_post );
if ( 'page' === $post->post_type ) {
$paths[] = add_query_arg(
'slug',
// @see https://github.com/WordPress/gutenberg/blob/489f6067c623926bce7151a76755bb68d8e22ea7/packages/edit-site/src/components/sync-state-with-url/use-init-edited-entity-from-url.js#L139-L140
'page-' . $post->post_name,
'/wp/v2/templates/lookup'
);
}
}
}

Expand Down Expand Up @@ -70,6 +86,9 @@ function gutenberg_block_editor_preload_paths_6_8( $paths, $context ) {
*/
$context = current_user_can( 'edit_theme_options' ) ? 'edit' : 'view';
$paths[] = "/wp/v2/global-styles/$global_styles_id?context=$context";

// Used by getBlockPatternCategories in useBlockEditorSettings.
$paths[] = '/wp/v2/block-patterns/categories';
}
return $paths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ exports[`AlignmentUI should allow custom alignment controls to be specified 1`]
align="custom-left"
aria-label="My custom left"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -35,7 +35,7 @@ exports[`AlignmentUI should allow custom alignment controls to be specified 1`]
align="custom-right"
aria-label="My custom right"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down Expand Up @@ -100,7 +100,7 @@ exports[`AlignmentUI should match snapshot when controls are visible 1`] = `
align="left"
aria-label="Align text left"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -123,7 +123,7 @@ exports[`AlignmentUI should match snapshot when controls are visible 1`] = `
align="center"
aria-label="Align text center"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -146,7 +146,7 @@ exports[`AlignmentUI should match snapshot when controls are visible 1`] = `
align="right"
aria-label="Align text right"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="None"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -64,7 +64,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="Align left"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -86,7 +86,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="Align center"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -108,7 +108,7 @@ exports[`BlockAlignmentUI should match snapshot when controls are visible 1`] =
<button
aria-label="Align right"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down
12 changes: 10 additions & 2 deletions packages/block-editor/src/components/block-edit/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import { useContext, useMemo } from '@wordpress/element';
* Internal dependencies
*/
import BlockContext from '../block-context';
import { withBlockBindingsSupport } from './with-block-bindings-support';
import { canBindBlock } from '../../utils/block-bindings';

/**
* Default value used for blocks which do not define their own context needs,
Expand Down Expand Up @@ -47,6 +49,8 @@ const Edit = ( props ) => {

const EditWithFilters = withFilters( 'editor.BlockEdit' )( Edit );

const EditWithFiltersAndBindings = withBlockBindingsSupport( EditWithFilters );

const EditWithGeneratedProps = ( props ) => {
const { attributes = {}, name } = props;
const blockType = getBlockType( name );
Expand All @@ -67,8 +71,12 @@ const EditWithGeneratedProps = ( props ) => {
return null;
}

const EditComponent = canBindBlock( name )
? EditWithFiltersAndBindings
: EditWithFilters;

if ( blockType.apiVersion > 1 ) {
return <EditWithFilters { ...props } context={ context } />;
return <EditComponent { ...props } context={ context } />;
}

// Generate a class name for the block's editable form.
Expand All @@ -82,7 +90,7 @@ const EditWithGeneratedProps = ( props ) => {
);

return (
<EditWithFilters
<EditComponent
{ ...props }
context={ context }
className={ className }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,19 @@ import { store as blocksStore } from '@wordpress/blocks';
import { createHigherOrderComponent } from '@wordpress/compose';
import { useRegistry, useSelect } from '@wordpress/data';
import { useCallback, useMemo, useContext } from '@wordpress/element';
import { addFilter } from '@wordpress/hooks';

/**
* Internal dependencies
*/
import isURLLike from '../components/link-control/is-url-like';
import { unlock } from '../lock-unlock';
import BlockContext from '../components/block-context';
import isURLLike from '../link-control/is-url-like';
import { unlock } from '../../lock-unlock';
import BlockContext from '../block-context';
import {
BLOCK_BINDINGS_ALLOWED_BLOCKS,
canBindAttribute,
} from '../../utils/block-bindings';

/** @typedef {import('@wordpress/compose').WPHigherOrderComponent} WPHigherOrderComponent */
/** @typedef {import('@wordpress/blocks').WPBlockSettings} WPBlockSettings */

/**
* Given a binding of block attributes, returns a higher order component that
* overrides its `attributes` and `setAttributes` props to sync any changes needed.
*
* @return {WPHigherOrderComponent} Higher-order component.
*/

const BLOCK_BINDINGS_ALLOWED_BLOCKS = {
'core/paragraph': [ 'content' ],
'core/heading': [ 'content' ],
'core/image': [ 'id', 'url', 'title', 'alt' ],
'core/button': [ 'url', 'text', 'linkTarget', 'rel' ],
};

const DEFAULT_ATTRIBUTE = '__default';

Expand Down Expand Up @@ -67,36 +55,12 @@ function replacePatternOverrideDefaultBindings( blockName, bindings ) {
}

/**
* Based on the given block name,
* check if it is possible to bind the block.
*
* @param {string} blockName - The block name.
* @return {boolean} Whether it is possible to bind the block to sources.
*/
export function canBindBlock( blockName ) {
return blockName in BLOCK_BINDINGS_ALLOWED_BLOCKS;
}

/**
* Based on the given block name and attribute name,
* check if it is possible to bind the block attribute.
* Given a binding of block attributes, returns a higher order component that
* overrides its `attributes` and `setAttributes` props to sync any changes needed.
*
* @param {string} blockName - The block name.
* @param {string} attributeName - The attribute name.
* @return {boolean} Whether it is possible to bind the block attribute.
* @return {WPHigherOrderComponent} Higher-order component.
*/
export function canBindAttribute( blockName, attributeName ) {
return (
canBindBlock( blockName ) &&
BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ].includes( attributeName )
);
}

export function getBindableAttributes( blockName ) {
return BLOCK_BINDINGS_ALLOWED_BLOCKS[ blockName ];
}

export const withBlockBindingSupport = createHigherOrderComponent(
export const withBlockBindingsSupport = createHigherOrderComponent(
( BlockEdit ) => ( props ) => {
const registry = useRegistry();
const blockContext = useContext( BlockContext );
Expand All @@ -108,9 +72,9 @@ export const withBlockBindingSupport = createHigherOrderComponent(
() =>
replacePatternOverrideDefaultBindings(
name,
props.attributes.metadata?.bindings
props.attributes?.metadata?.bindings
),
[ props.attributes.metadata?.bindings, name ]
[ props.attributes?.metadata?.bindings, name ]
);

// While this hook doesn't directly call any selectors, `useSelect` is
Expand Down Expand Up @@ -196,7 +160,7 @@ export const withBlockBindingSupport = createHigherOrderComponent(

const hasParentPattern = !! updatedContext[ 'pattern/overrides' ];
const hasPatternOverridesDefaultBinding =
props.attributes.metadata?.bindings?.[ DEFAULT_ATTRIBUTE ]
props.attributes?.metadata?.bindings?.[ DEFAULT_ATTRIBUTE ]
?.source === 'core/pattern-overrides';

const _setAttributes = useCallback(
Expand Down Expand Up @@ -283,40 +247,13 @@ export const withBlockBindingSupport = createHigherOrderComponent(
);

return (
<>
<BlockEdit
{ ...props }
attributes={ { ...props.attributes, ...boundAttributes } }
setAttributes={ _setAttributes }
context={ { ...context, ...updatedContext } }
/>
</>
<BlockEdit
{ ...props }
attributes={ { ...props.attributes, ...boundAttributes } }
setAttributes={ _setAttributes }
context={ { ...context, ...updatedContext } }
/>
);
},
'withBlockBindingSupport'
);

/**
* Filters a registered block's settings to enhance a block's `edit` component
* to upgrade bound attributes.
*
* @param {WPBlockSettings} settings - Registered block settings.
* @param {string} name - Block name.
* @return {WPBlockSettings} Filtered block settings.
*/
function shimAttributeSource( settings, name ) {
if ( ! canBindBlock( name ) ) {
return settings;
}

return {
...settings,
edit: withBlockBindingSupport( settings.edit ),
};
}

addFilter(
'blocks.registerBlockType',
'core/editor/custom-sources-backwards-compatibility/shim-attribute-source',
shimAttributeSource
);
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { useBlockRefProvider } from './use-block-refs';
import { useIntersectionObserver } from './use-intersection-observer';
import { useScrollIntoView } from './use-scroll-into-view';
import { useFlashEditableBlocks } from '../../use-flash-editable-blocks';
import { canBindBlock } from '../../../hooks/use-bindings-attributes';
import { canBindBlock } from '../../../utils/block-bindings';
import { useFirefoxDraggableCompatibility } from './use-firefox-draggable-compatibility';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ function BlockPopoverInbetween( {
? nextRect.left - previousRect.right
: 0;
}

// Avoid a negative width which happens when the next rect
// is on the next line.
width = Math.max( width, 0 );
}

return new window.DOMRect( left, top, width, height );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`BlockVerticalAlignmentUI should match snapshot when controls are visibl
<button
aria-label="Align top"
aria-pressed="true"
class="components-button components-toolbar__control is-pressed has-icon"
class="components-button components-toolbar__control is-compact is-pressed has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -64,7 +64,7 @@ exports[`BlockVerticalAlignmentUI should match snapshot when controls are visibl
<button
aria-label="Align middle"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand All @@ -86,7 +86,7 @@ exports[`BlockVerticalAlignmentUI should match snapshot when controls are visibl
<button
aria-label="Align bottom"
aria-pressed="false"
class="components-button components-toolbar__control has-icon"
class="components-button components-toolbar__control is-compact has-icon"
data-toolbar-item="true"
type="button"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ export default function FontAppearanceControl( props ) {
{ ...otherProps }
className="components-font-appearance-control"
__next40pxDefaultSize={ __next40pxDefaultSize }
__shouldNotWarnDeprecated36pxSize
label={ label }
describedBy={ getDescribedBy() }
options={ selectOptions }
Expand Down
1 change: 1 addition & 0 deletions packages/block-editor/src/components/font-family/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export default function FontFamilyControl( {
return (
<CustomSelectControl
__next40pxDefaultSize={ __next40pxDefaultSize }
__shouldNotWarnDeprecated36pxSize
label={ __( 'Font' ) }
value={ value }
onChange={ ( { selectedItem } ) => onChange( selectedItem.key ) }
Expand Down
Loading

0 comments on commit 91dd5e1

Please sign in to comment.