diff --git a/lib/block-supports/pattern.php b/lib/block-supports/pattern.php index 2f7717091ff50..7c344d669e1f9 100644 --- a/lib/block-supports/pattern.php +++ b/lib/block-supports/pattern.php @@ -13,7 +13,8 @@ * @param WP_Block_Type $block_type Block Type. */ function gutenberg_register_pattern_support( $block_type ) { - $pattern_support = 'core/paragraph' === $block_type->name ? true : false; + global $block_bindings_allowed_blocks; + $pattern_support = array_key_exists( $block_type->name, $block_bindings_allowed_blocks ); if ( $pattern_support ) { if ( ! $block_type->uses_context ) { diff --git a/package-lock.json b/package-lock.json index b74f66298d787..85e61fb71c594 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54123,6 +54123,7 @@ "@wordpress/interactivity": "file:../interactivity", "@wordpress/keycodes": "file:../keycodes", "@wordpress/notices": "file:../notices", + "@wordpress/patterns": "file:../patterns", "@wordpress/primitives": "file:../primitives", "@wordpress/private-apis": "file:../private-apis", "@wordpress/reusable-blocks": "file:../reusable-blocks", @@ -69271,6 +69272,7 @@ "@wordpress/interactivity": "file:../interactivity", "@wordpress/keycodes": "file:../keycodes", "@wordpress/notices": "file:../notices", + "@wordpress/patterns": "file:../patterns", "@wordpress/primitives": "file:../primitives", "@wordpress/private-apis": "file:../private-apis", "@wordpress/reusable-blocks": "file:../reusable-blocks", diff --git a/packages/block-library/package.json b/packages/block-library/package.json index 49cbc29415718..12f4e23d9da4d 100644 --- a/packages/block-library/package.json +++ b/packages/block-library/package.json @@ -53,6 +53,7 @@ "@wordpress/interactivity": "file:../interactivity", "@wordpress/keycodes": "file:../keycodes", "@wordpress/notices": "file:../notices", + "@wordpress/patterns": "file:../patterns", "@wordpress/primitives": "file:../primitives", "@wordpress/private-apis": "file:../private-apis", "@wordpress/reusable-blocks": "file:../reusable-blocks", diff --git a/packages/block-library/src/block/edit.js b/packages/block-library/src/block/edit.js index 6331d33c27a7b..9d03accb1204c 100644 --- a/packages/block-library/src/block/edit.js +++ b/packages/block-library/src/block/edit.js @@ -27,6 +27,7 @@ import { store as blockEditorStore, BlockControls, } from '@wordpress/block-editor'; +import { privateApis as patternsPrivateApis } from '@wordpress/patterns'; import { parse, cloneBlock } from '@wordpress/blocks'; /** @@ -35,10 +36,13 @@ import { parse, cloneBlock } from '@wordpress/blocks'; import { unlock } from '../lock-unlock'; const { useLayoutClasses } = unlock( blockEditorPrivateApis ); +const { PARTIAL_SYNCING_SUPPORTED_BLOCKS } = unlock( patternsPrivateApis ); function isPartiallySynced( block ) { return ( - 'core/paragraph' === block.name && + Object.keys( PARTIAL_SYNCING_SUPPORTED_BLOCKS ).includes( + block.name + ) && !! block.attributes.metadata?.bindings && Object.values( block.attributes.metadata.bindings ).some( ( binding ) => binding.source.name === 'pattern_attributes' @@ -100,7 +104,7 @@ function applyInitialOverrides( blocks, overrides = {}, defaultValues ) { defaultValues[ blockId ] ??= {}; defaultValues[ blockId ][ attributeKey ] = block.attributes[ attributeKey ]; - if ( overrides[ blockId ] ) { + if ( overrides[ blockId ]?.[ attributeKey ] !== undefined ) { newAttributes[ attributeKey ] = overrides[ blockId ][ attributeKey ]; } @@ -130,6 +134,8 @@ function getOverridesFromBlocks( blocks, defaultValues ) { defaultValues[ blockId ][ attributeKey ] ) { overrides[ blockId ] ??= {}; + // TODO: We need a way to represent `undefined` in the serialized overrides. + // Also see: https://github.com/WordPress/gutenberg/pull/57249#discussion_r1452987871 overrides[ blockId ][ attributeKey ] = block.attributes[ attributeKey ]; } diff --git a/packages/patterns/src/constants.js b/packages/patterns/src/constants.js index 3e533d834fd75..4a9f769658b2e 100644 --- a/packages/patterns/src/constants.js +++ b/packages/patterns/src/constants.js @@ -23,4 +23,9 @@ export const PATTERN_SYNC_TYPES = { // TODO: This should not be hardcoded. Maybe there should be a config and/or an UI. export const PARTIAL_SYNCING_SUPPORTED_BLOCKS = { 'core/paragraph': { content: __( 'Content' ) }, + 'core/heading': { content: __( 'Content' ) }, + 'core/button': { + text: __( 'Text' ), + url: __( 'URL' ), + }, };