From 7c9af07eb582b97125d6478d6cb2c33c124716de Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 12:23:19 +0200 Subject: [PATCH 01/37] Rename block.json field to __experimentalBlockHooks --- lib/experimental/auto-inserting-blocks.php | 4 ++-- packages/blocks/src/api/registration.js | 2 +- packages/blocks/src/store/reducer.js | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 4790dc4166fa3..75f4bae7b23c6 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -97,10 +97,10 @@ function gutenberg_add_auto_insert_field_to_block_type_controller( $inserted_blo * @return array Updated settings array. */ function gutenberg_register_auto_inserted_blocks( $settings, $metadata ) { - if ( ! isset( $metadata['__experimentalAutoInsert'] ) ) { + if ( ! isset( $metadata['__experimentalBlockHooks'] ) ) { return $settings; } - $auto_insert = $metadata['__experimentalAutoInsert']; + $auto_insert = $metadata['__experimentalBlockHooks']; /** * Map the camelCased position string from block.json to the snake_cased block type position diff --git a/packages/blocks/src/api/registration.js b/packages/blocks/src/api/registration.js index 72c0a30db0205..44776ed7e4992 100644 --- a/packages/blocks/src/api/registration.js +++ b/packages/blocks/src/api/registration.js @@ -167,7 +167,7 @@ function getBlockSettingsFromMetadata( { textdomain, ...metadata } ) { 'styles', 'example', 'variations', - '__experimentalAutoInsert', + '__experimentalBlockHooks', ]; const settings = Object.fromEntries( diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index a8f114fea79c7..f18bdef99a84a 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -83,14 +83,14 @@ function bootstrappedBlockTypes( state = {}, action ) { // definitions and needs to be polyfilled. This can be removed when the // minimum supported WordPress is >= 6.4. if ( - serverDefinition.__experimentalAutoInsert === undefined && - blockType.__experimentalAutoInsert + serverDefinition.__experimentalBlockHooks === undefined && + blockType.__experimentalBlockHooks ) { newDefinition = { ...serverDefinition, ...newDefinition, - __experimentalAutoInsert: - blockType.__experimentalAutoInsert, + __experimentalBlockHooks: + blockType.__experimentalBlockHooks, }; } } else { From 8dd9ed6a317ebda6c4d9b5377a57d79ca04a9b88 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 12:32:54 +0200 Subject: [PATCH 02/37] Update comment --- packages/blocks/src/store/reducer.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/blocks/src/store/reducer.js b/packages/blocks/src/store/reducer.js index f18bdef99a84a..db01f06bb7db6 100644 --- a/packages/blocks/src/store/reducer.js +++ b/packages/blocks/src/store/reducer.js @@ -79,7 +79,7 @@ function bootstrappedBlockTypes( state = {}, action ) { }; } - // The `autoInsert` prop is not yet included in the server provided + // The `blockHooks` prop is not yet included in the server provided // definitions and needs to be polyfilled. This can be removed when the // minimum supported WordPress is >= 6.4. if ( From 4325befb50df46e9d5068ecd6b11b53c5a475cca Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 12:34:03 +0200 Subject: [PATCH 03/37] Rename window. flag for experiment --- lib/experimental/editor-settings.php | 2 +- packages/block-editor/src/hooks/auto-inserting-blocks.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index a9b7b18e75a5f..dcb5ae4ff96b3 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -32,7 +32,7 @@ function gutenberg_enable_experiments() { } if ( $gutenberg_experiments && array_key_exists( 'gutenberg-auto-inserting-blocks', $gutenberg_experiments ) ) { - wp_add_inline_script( 'wp-block-editor', 'window.__experimentalAutoInsertingBlocks = true', 'before' ); + wp_add_inline_script( 'wp-block-editor', 'window.__experimentalBlockHooks = true', 'before' ); } } diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index 5b3adfbdde8b9..22c8e1f19157b 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -262,7 +262,7 @@ export const withAutoInsertingBlocks = createHigherOrderComponent( 'withAutoInsertingBlocks' ); -if ( window?.__experimentalAutoInsertingBlocks ) { +if ( window?.__experimentalBlockHooks ) { addFilter( 'editor.BlockEdit', 'core/auto-inserting-blocks/with-inspector-control', From 7b2e49805380002e0b4d58bc19594bc86ee49609 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 12:34:45 +0200 Subject: [PATCH 04/37] Rename Gutenberg experiment --- lib/compat/wordpress-6.3/rest-api.php | 2 +- .../class-gutenberg-rest-block-patterns-controller.php | 2 +- lib/experimental/editor-settings.php | 2 +- lib/experimental/rest-api.php | 2 +- lib/experiments-page.php | 4 ++-- lib/load.php | 4 ++-- packages/block-library/src/pattern/index.php | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/compat/wordpress-6.3/rest-api.php b/lib/compat/wordpress-6.3/rest-api.php index 130da6ed774d8..c4f42e288de77 100644 --- a/lib/compat/wordpress-6.3/rest-api.php +++ b/lib/compat/wordpress-6.3/rest-api.php @@ -87,7 +87,7 @@ function add_modified_wp_template_schema() { // If the Auto-inserting Blocks experiment is enabled, we load the block patterns // controller in lib/experimental/rest-api.php instead. -if ( ! gutenberg_is_experiment_enabled( 'gutenberg-auto-inserting-blocks' ) ) { +if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { /** * Registers the block patterns REST API routes. */ diff --git a/lib/experimental/class-gutenberg-rest-block-patterns-controller.php b/lib/experimental/class-gutenberg-rest-block-patterns-controller.php index 1ac567959b146..e4ac5581910e0 100644 --- a/lib/experimental/class-gutenberg-rest-block-patterns-controller.php +++ b/lib/experimental/class-gutenberg-rest-block-patterns-controller.php @@ -26,7 +26,7 @@ class Gutenberg_REST_Block_Patterns_Controller extends Gutenberg_REST_Block_Patt */ public function prepare_item_for_response( $item, $request ) { $response = parent::prepare_item_for_response( $item, $request ); - if ( ! gutenberg_is_experiment_enabled( 'gutenberg-auto-inserting-blocks' ) ) { + if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { return $response; } diff --git a/lib/experimental/editor-settings.php b/lib/experimental/editor-settings.php index dcb5ae4ff96b3..eb36b5b49b8e9 100644 --- a/lib/experimental/editor-settings.php +++ b/lib/experimental/editor-settings.php @@ -31,7 +31,7 @@ function gutenberg_enable_experiments() { wp_add_inline_script( 'wp-block-library', 'window.__experimentalDisableTinymce = true', 'before' ); } - if ( $gutenberg_experiments && array_key_exists( 'gutenberg-auto-inserting-blocks', $gutenberg_experiments ) ) { + if ( $gutenberg_experiments && array_key_exists( 'gutenberg-block-hooks', $gutenberg_experiments ) ) { wp_add_inline_script( 'wp-block-editor', 'window.__experimentalBlockHooks = true', 'before' ); } } diff --git a/lib/experimental/rest-api.php b/lib/experimental/rest-api.php index 8e548600b3875..f8c5a3041d312 100644 --- a/lib/experimental/rest-api.php +++ b/lib/experimental/rest-api.php @@ -10,7 +10,7 @@ die( 'Silence is golden.' ); } -if ( gutenberg_is_experiment_enabled( 'gutenberg-auto-inserting-blocks' ) ) { +if ( gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { /** * Registers the block patterns REST API routes. */ diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 74b2ad01672f7..0b78cbea39b6b 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -104,14 +104,14 @@ function gutenberg_initialize_experiments_settings() { ); add_settings_field( - 'gutenberg-auto-inserting-blocks', + 'gutenberg-block-hooks', __( 'Auto-inserting blocks', 'gutenberg' ), 'gutenberg_display_experiment_field', 'gutenberg-experiments', 'gutenberg_experiments_section', array( 'label' => __( 'Test Auto-inserting blocks', 'gutenberg' ), - 'id' => 'gutenberg-auto-inserting-blocks', + 'id' => 'gutenberg-block-hooks', ) ); diff --git a/lib/load.php b/lib/load.php index ef8da334debe6..5b4b03838846d 100644 --- a/lib/load.php +++ b/lib/load.php @@ -63,7 +63,7 @@ function gutenberg_is_experiment_enabled( $name ) { require_once __DIR__ . '/experimental/class-wp-rest-customizer-nonces.php'; } require_once __DIR__ . '/experimental/class-gutenberg-rest-template-revision-count.php'; - if ( gutenberg_is_experiment_enabled( 'gutenberg-auto-inserting-blocks' ) ) { + if ( gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { require_once __DIR__ . '/experimental/class-gutenberg-rest-block-patterns-controller.php'; } require_once __DIR__ . '/experimental/rest-api.php'; @@ -110,7 +110,7 @@ function gutenberg_is_experiment_enabled( $name ) { require __DIR__ . '/experimental/disable-tinymce.php'; } -if ( gutenberg_is_experiment_enabled( 'gutenberg-auto-inserting-blocks' ) ) { +if ( gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { require __DIR__ . '/experimental/auto-inserting-blocks.php'; } require __DIR__ . '/experimental/interactivity-api/class-wp-interactivity-store.php'; diff --git a/packages/block-library/src/pattern/index.php b/packages/block-library/src/pattern/index.php index 97a8c3ddc663f..50687220992e2 100644 --- a/packages/block-library/src/pattern/index.php +++ b/packages/block-library/src/pattern/index.php @@ -44,7 +44,7 @@ function render_block_core_pattern( $attributes ) { $content = _inject_theme_attribute_in_block_template_content( $pattern['content'] ); $gutenberg_experiments = get_option( 'gutenberg-experiments' ); - if ( $gutenberg_experiments && ! empty( $gutenberg_experiments['gutenberg-auto-inserting-blocks'] ) ) { + if ( $gutenberg_experiments && ! empty( $gutenberg_experiments['gutenberg-block-hooks'] ) ) { // TODO: In the long run, we'd likely want to have a filter in the `WP_Block_Patterns_Registry` class // instead to allow us plugging in code like this. $blocks = parse_blocks( $content ); From 24e51190f120300c240863bc5fdd184b6ff82c83 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 12:36:41 +0200 Subject: [PATCH 05/37] Update GB experiment title and label --- lib/experiments-page.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 0b78cbea39b6b..653ebb92e350e 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -105,12 +105,12 @@ function gutenberg_initialize_experiments_settings() { add_settings_field( 'gutenberg-block-hooks', - __( 'Auto-inserting blocks', 'gutenberg' ), + __( 'Block hooks', 'gutenberg' ), 'gutenberg_display_experiment_field', 'gutenberg-experiments', 'gutenberg_experiments_section', array( - 'label' => __( 'Test Auto-inserting blocks', 'gutenberg' ), + 'label' => __( 'Block hooks allow automatically inserting a blocks in a position relative to another.', 'gutenberg' ), 'id' => 'gutenberg-block-hooks', ) ); From 33b84b2e438f0d06d22eb768ce39cd88b5e05952 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 14:26:00 +0200 Subject: [PATCH 06/37] Change classname --- packages/block-editor/src/hooks/auto-inserting-blocks.js | 2 +- packages/block-editor/src/hooks/auto-inserting-blocks.scss | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index 22c8e1f19157b..f2149b7664dc4 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -183,7 +183,7 @@ function AutoInsertingBlocksControl( props ) { return ( diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.scss b/packages/block-editor/src/hooks/auto-inserting-blocks.scss index 8c43c3673053e..dc05d6e6947bb 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.scss +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.scss @@ -1,4 +1,4 @@ -.block-editor-hooks__auto-inserting-blocks { +.block-editor-hooks__block-hooks { /** * Since we're displaying the block icon alongside the block name, * we need to right-align the toggle. From a2ea218e2387ac537e17439086efdcccc1da0a76 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 14:34:23 +0200 Subject: [PATCH 07/37] Rename component --- packages/block-editor/src/hooks/auto-inserting-blocks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index f2149b7664dc4..f5b2a5274e47a 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -21,7 +21,7 @@ import { store as blockEditorStore } from '../store'; const EMPTY_OBJECT = {}; -function AutoInsertingBlocksControl( props ) { +function BlocksHooksControl( props ) { const blockTypes = useSelect( ( select ) => select( blocksStore ).getBlockTypes(), [] @@ -251,7 +251,7 @@ export const withAutoInsertingBlocks = createHigherOrderComponent( return ( <> { blockEdit } - From 5fb320293423677dbf083fd3ee117ecab50c7881 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 14:36:35 +0200 Subject: [PATCH 08/37] Rename two variables --- .../src/hooks/auto-inserting-blocks.js | 123 +++++++++--------- 1 file changed, 59 insertions(+), 64 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index f5b2a5274e47a..70cc2d3d08f30 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -27,7 +27,7 @@ function BlocksHooksControl( props ) { [] ); - const autoInsertedBlocksForCurrentBlock = useMemo( + const hookedBlocksForCurrentBlock = useMemo( () => blockTypes?.filter( ( { autoInsert } ) => @@ -51,79 +51,75 @@ function BlocksHooksControl( props ) { [ props.clientId ] ); - const autoInsertedBlockClientIds = useSelect( + const hookedBlockClientIds = useSelect( ( select ) => { const { getBlock, getGlobalBlockCount } = select( blockEditorStore ); - const _autoInsertedBlockClientIds = - autoInsertedBlocksForCurrentBlock.reduce( - ( clientIds, block ) => { - // If the block doesn't exist anywhere in the block tree, - // we know that we have to display the toggle for it, and set - // it to disabled. - if ( getGlobalBlockCount( block.name ) === 0 ) { - return clientIds; - } + const _hookedBlockClientIds = hookedBlocksForCurrentBlock.reduce( + ( clientIds, block ) => { + // If the block doesn't exist anywhere in the block tree, + // we know that we have to display the toggle for it, and set + // it to disabled. + if ( getGlobalBlockCount( block.name ) === 0 ) { + return clientIds; + } - const relativePosition = - block?.autoInsert?.[ props.blockName ]; - let candidates; + const relativePosition = + block?.autoInsert?.[ props.blockName ]; + let candidates; - switch ( relativePosition ) { - case 'before': - case 'after': - // Any of the current block's siblings (with the right block type) qualifies - // as an auto-inserted block (inserted `before` or `after` the current one), - // as the block might've been auto-inserted and then moved around a bit by the user. - candidates = - getBlock( rootClientId )?.innerBlocks; - break; + switch ( relativePosition ) { + case 'before': + case 'after': + // Any of the current block's siblings (with the right block type) qualifies + // as an auto-inserted block (inserted `before` or `after` the current one), + // as the block might've been auto-inserted and then moved around a bit by the user. + candidates = getBlock( rootClientId )?.innerBlocks; + break; - case 'first_child': - case 'last_child': - // Any of the current block's child blocks (with the right block type) qualifies - // as an auto-inserted first or last child block, as the block might've been - // auto-inserted and then moved around a bit by the user. - candidates = getBlock( - props.clientId - ).innerBlocks; - break; - } + case 'first_child': + case 'last_child': + // Any of the current block's child blocks (with the right block type) qualifies + // as an auto-inserted first or last child block, as the block might've been + // auto-inserted and then moved around a bit by the user. + candidates = getBlock( props.clientId ).innerBlocks; + break; + } - const autoInsertedBlock = candidates?.find( - ( { name } ) => name === block.name - ); - - // If the block exists in the designated location, we consider it auto-inserted - // and show the toggle as enabled. - if ( autoInsertedBlock ) { - return { - ...clientIds, - [ block.name ]: autoInsertedBlock.clientId, - }; - } + const autoInsertedBlock = candidates?.find( + ( { name } ) => name === block.name + ); - // If no auto-inserted block was found in any of its designated locations, - // but it exists elsewhere in the block tree, we consider it manually inserted. - // In this case, we take note and will remove the corresponding toggle from the - // block inspector panel. + // If the block exists in the designated location, we consider it auto-inserted + // and show the toggle as enabled. + if ( autoInsertedBlock ) { return { ...clientIds, - [ block.name ]: false, + [ block.name ]: autoInsertedBlock.clientId, }; - }, - {} - ); + } + + // If no auto-inserted block was found in any of its designated locations, + // but it exists elsewhere in the block tree, we consider it manually inserted. + // In this case, we take note and will remove the corresponding toggle from the + // block inspector panel. + return { + ...clientIds, + [ block.name ]: false, + }; + }, + {} + ); - if ( Object.values( _autoInsertedBlockClientIds ).length > 0 ) { - return _autoInsertedBlockClientIds; + if ( Object.values( _hookedBlockClientIds ).length > 0 ) { + return _hookedBlockClientIds; } return EMPTY_OBJECT; }, [ - autoInsertedBlocksForCurrentBlock, + hookedBlocksForCurrentBlock, props.blockName, props.clientId, rootClientId, @@ -133,17 +129,17 @@ function BlocksHooksControl( props ) { const { insertBlock, removeBlock } = useDispatch( blockEditorStore ); // Remove toggle if block isn't present in the designated location but elsewhere in the block tree. - const autoInsertedBlocksForCurrentBlockIfNotPresentElsewhere = - autoInsertedBlocksForCurrentBlock?.filter( - ( block ) => autoInsertedBlockClientIds?.[ block.name ] !== false + const hookedBlocksForCurrentBlockIfNotPresentElsewhere = + hookedBlocksForCurrentBlock?.filter( + ( block ) => hookedBlockClientIds?.[ block.name ] !== false ); - if ( ! autoInsertedBlocksForCurrentBlockIfNotPresentElsewhere.length ) { + if ( ! hookedBlocksForCurrentBlockIfNotPresentElsewhere.length ) { return null; } // Group by block namespace (i.e. prefix before the slash). - const groupedAutoInsertedBlocks = autoInsertedBlocksForCurrentBlock.reduce( + const groupedAutoInsertedBlocks = hookedBlocksForCurrentBlock.reduce( ( groups, block ) => { const [ namespace ] = block.name.split( '/' ); if ( ! groups[ namespace ] ) { @@ -194,8 +190,7 @@ function BlocksHooksControl( props ) { { groupedAutoInsertedBlocks[ vendor ].map( ( block ) => { const checked = - block.name in - autoInsertedBlockClientIds; + block.name in hookedBlockClientIds; return ( Date: Mon, 4 Sep 2023 15:01:00 +0200 Subject: [PATCH 09/37] Rename more variables --- .../src/hooks/auto-inserting-blocks.js | 88 +++++++++---------- 1 file changed, 42 insertions(+), 46 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index 70cc2d3d08f30..a05a2e31a7033 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -87,16 +87,16 @@ function BlocksHooksControl( props ) { break; } - const autoInsertedBlock = candidates?.find( + const hookedBlock = candidates?.find( ( { name } ) => name === block.name ); // If the block exists in the designated location, we consider it auto-inserted // and show the toggle as enabled. - if ( autoInsertedBlock ) { + if ( hookedBlock ) { return { ...clientIds, - [ block.name ]: autoInsertedBlock.clientId, + [ block.name ]: hookedBlock.clientId, }; } @@ -139,7 +139,7 @@ function BlocksHooksControl( props ) { } // Group by block namespace (i.e. prefix before the slash). - const groupedAutoInsertedBlocks = hookedBlocksForCurrentBlock.reduce( + const groupedHookedBlocks = hookedBlocksForCurrentBlock.reduce( ( groups, block ) => { const [ namespace ] = block.name.split( '/' ); if ( ! groups[ namespace ] ) { @@ -183,54 +183,50 @@ function BlocksHooksControl( props ) { title={ __( 'Plugins' ) } initialOpen={ true } > - { Object.keys( groupedAutoInsertedBlocks ).map( ( vendor ) => { + { Object.keys( groupedHookedBlocks ).map( ( vendor ) => { return (

{ vendor }

- { groupedAutoInsertedBlocks[ vendor ].map( - ( block ) => { - const checked = - block.name in hookedBlockClientIds; + { groupedHookedBlocks[ vendor ].map( ( block ) => { + const checked = + block.name in hookedBlockClientIds; - return ( - - - { block.title } - + return ( + + + { block.title } + + } + onChange={ () => { + if ( ! checked ) { + // Create and insert block. + const relativePosition = + block.autoInsert[ + props.blockName + ]; + insertBlockIntoDesignatedLocation( + createBlock( block.name ), + relativePosition + ); + return; } - onChange={ () => { - if ( ! checked ) { - // Create and insert block. - const relativePosition = - block.autoInsert[ - props.blockName - ]; - insertBlockIntoDesignatedLocation( - createBlock( - block.name - ), - relativePosition - ); - return; - } - // Remove block. - const clientId = - hookedBlockClientIds[ - block.name - ]; - removeBlock( clientId, false ); - } } - /> - ); - } - ) } + // Remove block. + const clientId = + hookedBlockClientIds[ + block.name + ]; + removeBlock( clientId, false ); + } } + /> + ); + } ) }
); } ) } From 2bcf64438a898d192d07b71dd062a50ad88c965a Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 15:03:34 +0200 Subject: [PATCH 10/37] Comment wording --- packages/block-editor/src/hooks/auto-inserting-blocks.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index a05a2e31a7033..a82a7efd3aef8 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -91,7 +91,7 @@ function BlocksHooksControl( props ) { ( { name } ) => name === block.name ); - // If the block exists in the designated location, we consider it auto-inserted + // If the block exists in the designated location, we consider it hooked // and show the toggle as enabled. if ( hookedBlock ) { return { @@ -100,7 +100,7 @@ function BlocksHooksControl( props ) { }; } - // If no auto-inserted block was found in any of its designated locations, + // If no hooked block was found in any of its designated locations, // but it exists elsewhere in the block tree, we consider it manually inserted. // In this case, we take note and will remove the corresponding toggle from the // block inspector panel. From 8e7193ef37c6bb42ee2e779fcff21c09d0a147af Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 15:04:39 +0200 Subject: [PATCH 11/37] Change hooked blocks block hook name :dizzy: --- packages/block-editor/src/hooks/auto-inserting-blocks.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index a82a7efd3aef8..72570411ab6cd 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -256,7 +256,7 @@ export const withAutoInsertingBlocks = createHigherOrderComponent( if ( window?.__experimentalBlockHooks ) { addFilter( 'editor.BlockEdit', - 'core/auto-inserting-blocks/with-inspector-control', + 'core/hooked-blocks/with-inspector-control', withAutoInsertingBlocks ); } From 282909a5b32f776ae9861499fee2a7b82d680c11 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 15:05:22 +0200 Subject: [PATCH 12/37] Change HOC name --- .../src/hooks/auto-inserting-blocks.js | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index 72570411ab6cd..d68edc93ed809 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -235,28 +235,25 @@ function BlocksHooksControl( props ) { ); } -export const withAutoInsertingBlocks = createHigherOrderComponent( - ( BlockEdit ) => { - return ( props ) => { - const blockEdit = ; - return ( - <> - { blockEdit } - - - ); - }; - }, - 'withAutoInsertingBlocks' -); +export const withHookedBlocks = createHigherOrderComponent( ( BlockEdit ) => { + return ( props ) => { + const blockEdit = ; + return ( + <> + { blockEdit } + + + ); + }; +}, 'withHookedBlocks' ); if ( window?.__experimentalBlockHooks ) { addFilter( 'editor.BlockEdit', 'core/hooked-blocks/with-inspector-control', - withAutoInsertingBlocks + withHookedBlocks ); } From 6fa67bea3d7ca2e2ff4cf86c14d54ee33c4bfdc5 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 15:15:32 +0200 Subject: [PATCH 13/37] s/gutenberg_register_auto_inserted_block/gutenberg_add_hooked_block/g --- lib/experimental/auto-inserting-blocks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 75f4bae7b23c6..03b0d58e57715 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -133,7 +133,7 @@ function gutenberg_register_auto_inserted_blocks( $settings, $metadata ) { $mapped_position = $property_mappings[ $position ]; - gutenberg_register_auto_inserted_block( $inserted_block_name, $mapped_position, $anchor_block_name ); + gutenberg_add_hooked_block( $inserted_block_name, $mapped_position, $anchor_block_name ); $settings['auto_insert'][ $anchor_block_name ] = $mapped_position; } @@ -163,7 +163,7 @@ function gutenberg_register_auto_inserted_blocks( $settings, $metadata ) { $exposed_settings = array_intersect_key( $settings, $fields_to_pick ); - // TODO: Make work for blocks registered via direct call to gutenberg_register_auto_inserted_block(). + // TODO: Make work for blocks registered via direct call to gutenberg_add_hooked_block(). wp_add_inline_script( 'wp-blocks', 'wp.blocks.unstable__bootstrapServerSideBlockDefinitions(' . wp_json_encode( array( $inserted_block_name => $exposed_settings ) ) . ');' @@ -190,7 +190,7 @@ function gutenberg_register_auto_inserted_blocks( $settings, $metadata ) { * @param string $anchor_block The name of the block to insert the auto-inserted block next to. * @return void */ -function gutenberg_register_auto_inserted_block( $inserted_block, $position, $anchor_block ) { +function gutenberg_add_hooked_block( $inserted_block, $position, $anchor_block ) { $inserted_block_array = array( 'blockName' => $inserted_block, 'attrs' => array(), From ac87ee2f09e51b1ef7a155376fa1c8ca1d0f1f5b Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 15:16:12 +0200 Subject: [PATCH 14/37] s/gutenberg_register_auto_inserted_blocks/gutenberg_add_hooked_blocks/g --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 03b0d58e57715..6bf8a7938f18d 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -96,7 +96,7 @@ function gutenberg_add_auto_insert_field_to_block_type_controller( $inserted_blo * @param array $metadata Metadata provided for registering a block type. * @return array Updated settings array. */ -function gutenberg_register_auto_inserted_blocks( $settings, $metadata ) { +function gutenberg_add_hooked_blocks( $settings, $metadata ) { if ( ! isset( $metadata['__experimentalBlockHooks'] ) ) { return $settings; } @@ -171,7 +171,7 @@ function gutenberg_register_auto_inserted_blocks( $settings, $metadata ) { return $settings; } -add_filter( 'block_type_metadata_settings', 'gutenberg_register_auto_inserted_blocks', 10, 2 ); +add_filter( 'block_type_metadata_settings', 'gutenberg_add_hooked_blocks', 10, 2 ); /** * Register block for auto-insertion into the frontend and REST API. From 0d2cf6a7983b83c0dc9b4655de586eae0c9c0f60 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 15:57:45 +0200 Subject: [PATCH 15/37] s/gutenberg_auto_insert_block/gutenberg_insert_hooked_block/g --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 6bf8a7938f18d..77869c8e787f5 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -21,7 +21,7 @@ * @param string $anchor_block_type The auto-inserted block will be inserted next to instances of this block type. * @return callable A function that accepts a block's content and returns the content with the inserted block. */ -function gutenberg_auto_insert_block( $inserted_block, $relative_position, $anchor_block_type ) { +function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $anchor_block_type ) { return function( $block ) use ( $inserted_block, $relative_position, $anchor_block_type ) { if ( $anchor_block_type === $block['blockName'] ) { if ( 'first_child' === $relative_position ) { @@ -199,7 +199,7 @@ function gutenberg_add_hooked_block( $inserted_block, $position, $anchor_block ) 'innerBlocks' => array(), ); - $inserter = gutenberg_auto_insert_block( $inserted_block_array, $position, $anchor_block ); + $inserter = gutenberg_insert_hooked_block( $inserted_block_array, $position, $anchor_block ); add_filter( 'gutenberg_serialize_block', $inserter, 10, 1 ); /* From 130b5d80d4379322f578813b3e63e37aca7fdf9e Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 16:05:51 +0200 Subject: [PATCH 16/37] Change blocks controller field name --- lib/experimental/auto-inserting-blocks.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 77869c8e787f5..0a54c277c30c3 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -65,25 +65,25 @@ function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $an } /** - * Add auto-insertion information to a block type's controller. + * Add block hooks information to a block type's controller. * * @param array $inserted_block_type The type of block to insert. * @param string $position The position relative to the anchor block. * Can be 'before', 'after', 'first_child', or 'last_child'. - * @param string $anchor_block_type The auto-inserted block will be inserted next to instances of this block type. - * @return callable A filter for the `rest_prepare_block_type` hook that adds an `auto_insert` field to the network response. + * @param string $anchor_block_type The hooked block will be inserted next to instances of this block type. + * @return callable A filter for the `rest_prepare_block_type` hook that adds a `block_hooks` field to the network response. */ -function gutenberg_add_auto_insert_field_to_block_type_controller( $inserted_block_type, $position, $anchor_block_type ) { +function gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_block_type, $position, $anchor_block_type ) { return function( $response, $block_type ) use ( $inserted_block_type, $position, $anchor_block_type ) { if ( $block_type->name !== $inserted_block_type ) { return $response; } $data = $response->get_data(); - if ( ! isset( $data['auto_insert'] ) ) { - $data['auto_insert'] = array(); + if ( ! isset( $data['block_hooks'] ) ) { + $data['block_hooks'] = array(); } - $data['auto_insert'][ $anchor_block_type ] = $position; + $data['block_hooks'][ $anchor_block_type ] = $position; $response->set_data( $data ); return $response; }; @@ -205,12 +205,12 @@ function gutenberg_add_hooked_block( $inserted_block, $position, $anchor_block ) /* * The block-types REST API controller uses objects of the `WP_Block_Type` class, which are * in turn created upon block type registration. However, that class does not contain - * an `auto_insert` property (and is not easily extensible), so we have to use a different + * a `block_hooks` property (and is not easily extensible), so we have to use a different * mechanism to communicate to the controller which blocks have been registered for * auto-insertion. We're doing so here (i.e. upon block registration), by adding a filter to * the controller's response. */ - $controller_extender = gutenberg_add_auto_insert_field_to_block_type_controller( $inserted_block, $position, $anchor_block ); + $controller_extender = gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_block, $position, $anchor_block ); add_filter( 'rest_prepare_block_type', $controller_extender, 10, 2 ); } @@ -325,14 +325,14 @@ function gutenberg_serialize_blocks( $blocks ) { } /** - * Register the `auto_insert` field for the block-types REST API controller. + * Register the `block_hooks` field for the block-types REST API controller. * * @return void */ function gutenberg_register_auto_insert_rest_field() { register_rest_field( 'block-type', - 'auto_insert', + 'block_hooks', array( 'schema' => array( 'description' => __( 'This block is automatically inserted near any occurence of the block types used as keys of this map, into a relative position given by the corresponding value.', 'gutenberg' ), From bad8e9bc30fed3cbc0be2f9318d653d7b95e249a Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 16:34:00 +0200 Subject: [PATCH 17/37] Change server block settings field name --- lib/experimental/auto-inserting-blocks.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 0a54c277c30c3..fdc6aec387017 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -135,7 +135,7 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { gutenberg_add_hooked_block( $inserted_block_name, $mapped_position, $anchor_block_name ); - $settings['auto_insert'][ $anchor_block_name ] = $mapped_position; + $settings['block_hooks'][ $anchor_block_name ] = $mapped_position; } // Copied from `get_block_editor_server_block_settings()`. @@ -158,8 +158,8 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { 'example' => 'example', 'variations' => 'variations', ); - // Add `auto_insert` to the list of fields to pick. - $fields_to_pick['auto_insert'] = 'autoInsert'; + // Add `block_hooks` to the list of fields to pick. + $fields_to_pick['block_hooks'] = 'blockHooks'; $exposed_settings = array_intersect_key( $settings, $fields_to_pick ); From da434a21dbb89da719cfbe56e564461bc43ebe80 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 16:49:59 +0200 Subject: [PATCH 18/37] s/gutenberg_register_auto_insert_rest_field/gutenberg_register_block_hooks_rest_field/g --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index fdc6aec387017..1d7685fc7403f 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -329,7 +329,7 @@ function gutenberg_serialize_blocks( $blocks ) { * * @return void */ -function gutenberg_register_auto_insert_rest_field() { +function gutenberg_register_block_hooks_rest_field() { register_rest_field( 'block-type', 'block_hooks', @@ -346,4 +346,4 @@ function gutenberg_register_auto_insert_rest_field() { ) ); } -add_action( 'rest_api_init', 'gutenberg_register_auto_insert_rest_field' ); +add_action( 'rest_api_init', 'gutenberg_register_block_hooks_rest_field' ); From 2773ff8b010007328d1353beb6a2a0fca9066eed Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 16:51:01 +0200 Subject: [PATCH 19/37] Change variable name --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 1d7685fc7403f..4bc42ad303bcc 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -100,7 +100,7 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { if ( ! isset( $metadata['__experimentalBlockHooks'] ) ) { return $settings; } - $auto_insert = $metadata['__experimentalBlockHooks']; + $block_hooks = $metadata['__experimentalBlockHooks']; /** * Map the camelCased position string from block.json to the snake_cased block type position @@ -116,7 +116,7 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { ); $inserted_block_name = $metadata['name']; - foreach ( $auto_insert as $anchor_block_name => $position ) { + foreach ( $block_hooks as $anchor_block_name => $position ) { // Avoid infinite recursion (auto-inserting next to or into self). if ( $inserted_block_name === $anchor_block_name ) { _doing_it_wrong( From 5943b7e616b728c020baf70a517aea65e6a42bd2 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 16:52:19 +0200 Subject: [PATCH 20/37] Update _doing_it_wrong message --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 4bc42ad303bcc..7a1d9df3d3d45 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -117,11 +117,11 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { $inserted_block_name = $metadata['name']; foreach ( $block_hooks as $anchor_block_name => $position ) { - // Avoid infinite recursion (auto-inserting next to or into self). + // Avoid infinite recursion (hooking to itself). if ( $inserted_block_name === $anchor_block_name ) { _doing_it_wrong( __METHOD__, - __( 'Cannot auto-insert block next to itself.', 'gutenberg' ), + __( 'Cannot hook block to itself.', 'gutenberg' ), '6.4.0' ); continue; From 2d1d80832241f416a70c40065d5a8d8b2b06e9c7 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:16:48 +0200 Subject: [PATCH 21/37] Update PHPDoc for gutenberg_add_hooked_block --- lib/experimental/auto-inserting-blocks.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 7a1d9df3d3d45..80f11105d6062 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -174,20 +174,22 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { add_filter( 'block_type_metadata_settings', 'gutenberg_add_hooked_blocks', 10, 2 ); /** - * Register block for auto-insertion into the frontend and REST API. + * Add a block to a given block hook. * - * Register a block for auto-insertion into the frontend and into the markup + * A block hook is specified by a block type and a relative position. The hooked block + * will be automatically inserted in the given position next to the "anchor" block + * whenever the latter is encountered. This applies both to the frontend and to the markup * returned by the templates and patterns REST API endpoints. * - * This is currently done by filtering parsed blocks as obtained from a block template - * template part, or pattern and injecting the auto-inserted block where applicable. + * This is currently done by filtering parsed blocks as obtained from a block template, + * template part, or pattern, and injecting the hooked block where applicable. * - * @todo In the long run, we'd likely want some sort of registry for auto-inserted blocks. + * @todo In the long run, we'd likely want some sort of registry for hooked blocks. * * @param string $inserted_block The name of the block to insert. - * @param string $position The desired position of the auto-inserted block, relative to its anchor block. + * @param string $position The desired position of the hooked block, relative to its anchor block. * Can be 'before', 'after', 'first_child', or 'last_child'. - * @param string $anchor_block The name of the block to insert the auto-inserted block next to. + * @param string $anchor_block The name of the block to insert the hooked block next to. * @return void */ function gutenberg_add_hooked_block( $inserted_block, $position, $anchor_block ) { From a48ddcaf8addde8cb92d30958afe862992fa3b84 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:17:01 +0200 Subject: [PATCH 22/37] Update file's PHPDoc --- lib/experimental/auto-inserting-blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 80f11105d6062..3f1c07c549949 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -1,6 +1,6 @@ Date: Mon, 4 Sep 2023 17:18:17 +0200 Subject: [PATCH 23/37] Update arg and var names in gutenberg_add_hooked_block --- lib/experimental/auto-inserting-blocks.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 3f1c07c549949..8e709aab49344 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -186,22 +186,22 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { * * @todo In the long run, we'd likely want some sort of registry for hooked blocks. * - * @param string $inserted_block The name of the block to insert. - * @param string $position The desired position of the hooked block, relative to its anchor block. - * Can be 'before', 'after', 'first_child', or 'last_child'. - * @param string $anchor_block The name of the block to insert the hooked block next to. + * @param string $hooked_block The name of the block to insert. + * @param string $position The desired position of the hooked block, relative to its anchor block. + * Can be 'before', 'after', 'first_child', or 'last_child'. + * @param string $anchor_block The name of the block to insert the hooked block next to. * @return void */ -function gutenberg_add_hooked_block( $inserted_block, $position, $anchor_block ) { - $inserted_block_array = array( - 'blockName' => $inserted_block, +function gutenberg_add_hooked_block( $hooked_block, $position, $anchor_block ) { + $hooked_block_array = array( + 'blockName' => $hooked_block, 'attrs' => array(), 'innerHTML' => '', 'innerContent' => array(), 'innerBlocks' => array(), ); - $inserter = gutenberg_insert_hooked_block( $inserted_block_array, $position, $anchor_block ); + $inserter = gutenberg_insert_hooked_block( $hooked_block_array, $position, $anchor_block ); add_filter( 'gutenberg_serialize_block', $inserter, 10, 1 ); /* @@ -212,7 +212,7 @@ function gutenberg_add_hooked_block( $inserted_block, $position, $anchor_block ) * auto-insertion. We're doing so here (i.e. upon block registration), by adding a filter to * the controller's response. */ - $controller_extender = gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_block, $position, $anchor_block ); + $controller_extender = gutenberg_add_block_hooks_field_to_block_type_controller( $hooked_block, $position, $anchor_block ); add_filter( 'rest_prepare_block_type', $controller_extender, 10, 2 ); } From 8173a092cb8b1bbb4a18d5c1ff51ef623c0c5a58 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:20:24 +0200 Subject: [PATCH 24/37] Update PHPDoc for gutenberg_add_hooked_blocks --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 8e709aab49344..81426016422f9 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -90,7 +90,7 @@ function gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_blo } /** - * Register blocks for auto-insertion, based on their block.json metadata. + * Register hooked blocks for automatic insertion, based on their block.json metadata. * * @param array $settings Array of determined settings for registering a block type. * @param array $metadata Metadata provided for registering a block type. @@ -104,7 +104,7 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { /** * Map the camelCased position string from block.json to the snake_cased block type position - * used in the auto-inserting block registration function. + * used in the hooked block registration function. * * @var array */ From bce1ad5cd5bfb25edcc612a2898570bd559df0cf Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:21:34 +0200 Subject: [PATCH 25/37] Tweak PHPDoc for gutenberg_add_hooked_block --- lib/experimental/auto-inserting-blocks.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 81426016422f9..57a58e19fecee 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -174,7 +174,7 @@ function gutenberg_add_hooked_blocks( $settings, $metadata ) { add_filter( 'block_type_metadata_settings', 'gutenberg_add_hooked_blocks', 10, 2 ); /** - * Add a block to a given block hook. + * Register a hooked block for automatic insertion into a given block hook. * * A block hook is specified by a block type and a relative position. The hooked block * will be automatically inserted in the given position next to the "anchor" block From 0d1667aae1cb12c1f12e1a2e2901b57a74fd7270 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:22:38 +0200 Subject: [PATCH 26/37] More updates to gutenberg_add_hooked_block inline PHPDoc --- lib/experimental/auto-inserting-blocks.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 57a58e19fecee..6b03ab92e0460 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -208,8 +208,8 @@ function gutenberg_add_hooked_block( $hooked_block, $position, $anchor_block ) { * The block-types REST API controller uses objects of the `WP_Block_Type` class, which are * in turn created upon block type registration. However, that class does not contain * a `block_hooks` property (and is not easily extensible), so we have to use a different - * mechanism to communicate to the controller which blocks have been registered for - * auto-insertion. We're doing so here (i.e. upon block registration), by adding a filter to + * mechanism to communicate to the controller which hooked blocks have been registered for + * automatic insertion. We're doing so here (i.e. upon block registration), by adding a filter to * the controller's response. */ $controller_extender = gutenberg_add_block_hooks_field_to_block_type_controller( $hooked_block, $position, $anchor_block ); From b7a83eced08e668026e068a75dd1f3a5aebfd0c6 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:26:05 +0200 Subject: [PATCH 27/37] Update PHPDoc for gutenberg_insert_hooked_block --- lib/experimental/auto-inserting-blocks.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 6b03ab92e0460..2cc6c5cf3a9a3 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -8,17 +8,20 @@ /** * Return a function that auto-inserts a block next to a given "anchor" block. * + * This is a helper function used in the implementation of block hooks. + * It is not meant for public use. + * * The auto-inserted block can be inserted before or after the anchor block, * or as the first or last child of the anchor block. * - * Note that the returned function mutates the auto-inserted block's designated - * parent block by inserting into the parent's `innerBlocks` array, and by - * updating the parent's `innerContent` array accordingly. + * Note that the returned function mutates the automatically inserted block's + * designated parent block by inserting into the parent's `innerBlocks` array, + * and by updating the parent's `innerContent` array accordingly. * * @param array $inserted_block The block to insert. * @param string $relative_position The position relative to the given block. * Can be 'before', 'after', 'first_child', or 'last_child'. - * @param string $anchor_block_type The auto-inserted block will be inserted next to instances of this block type. + * @param string $anchor_block_type The automatically inserted block will be inserted next to instances of this block type. * @return callable A function that accepts a block's content and returns the content with the inserted block. */ function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $anchor_block_type ) { From d8663a0519d03af78d0ac78f396eff1a7864ec8e Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:26:58 +0200 Subject: [PATCH 28/37] Move helper functions below public API functions --- lib/experimental/auto-inserting-blocks.php | 174 ++++++++++----------- 1 file changed, 87 insertions(+), 87 deletions(-) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/auto-inserting-blocks.php index 2cc6c5cf3a9a3..abe85ee3b9ace 100644 --- a/lib/experimental/auto-inserting-blocks.php +++ b/lib/experimental/auto-inserting-blocks.php @@ -5,93 +5,6 @@ * @package gutenberg */ -/** - * Return a function that auto-inserts a block next to a given "anchor" block. - * - * This is a helper function used in the implementation of block hooks. - * It is not meant for public use. - * - * The auto-inserted block can be inserted before or after the anchor block, - * or as the first or last child of the anchor block. - * - * Note that the returned function mutates the automatically inserted block's - * designated parent block by inserting into the parent's `innerBlocks` array, - * and by updating the parent's `innerContent` array accordingly. - * - * @param array $inserted_block The block to insert. - * @param string $relative_position The position relative to the given block. - * Can be 'before', 'after', 'first_child', or 'last_child'. - * @param string $anchor_block_type The automatically inserted block will be inserted next to instances of this block type. - * @return callable A function that accepts a block's content and returns the content with the inserted block. - */ -function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $anchor_block_type ) { - return function( $block ) use ( $inserted_block, $relative_position, $anchor_block_type ) { - if ( $anchor_block_type === $block['blockName'] ) { - if ( 'first_child' === $relative_position ) { - array_unshift( $block['innerBlocks'], $inserted_block ); - // Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`) - // when rendering blocks, we also need to prepend a value (`null`, to mark a block - // location) to that array. - array_unshift( $block['innerContent'], null ); - } elseif ( 'last_child' === $relative_position ) { - array_push( $block['innerBlocks'], $inserted_block ); - // Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`) - // when rendering blocks, we also need to prepend a value (`null`, to mark a block - // location) to that array. - array_push( $block['innerContent'], null ); - } - return $block; - } - - $anchor_block_index = array_search( $anchor_block_type, array_column( $block['innerBlocks'], 'blockName' ), true ); - if ( false !== $anchor_block_index && ( 'after' === $relative_position || 'before' === $relative_position ) ) { - if ( 'after' === $relative_position ) { - $anchor_block_index++; - } - array_splice( $block['innerBlocks'], $anchor_block_index, 0, array( $inserted_block ) ); - - // Find matching `innerContent` chunk index. - $chunk_index = 0; - while ( $anchor_block_index > 0 ) { - if ( ! is_string( $block['innerContent'][ $chunk_index ] ) ) { - $anchor_block_index--; - } - $chunk_index++; - } - // Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`) - // when rendering blocks, we also need to insert a value (`null`, to mark a block - // location) into that array. - array_splice( $block['innerContent'], $chunk_index, 0, array( null ) ); - } - return $block; - }; -} - -/** - * Add block hooks information to a block type's controller. - * - * @param array $inserted_block_type The type of block to insert. - * @param string $position The position relative to the anchor block. - * Can be 'before', 'after', 'first_child', or 'last_child'. - * @param string $anchor_block_type The hooked block will be inserted next to instances of this block type. - * @return callable A filter for the `rest_prepare_block_type` hook that adds a `block_hooks` field to the network response. - */ -function gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_block_type, $position, $anchor_block_type ) { - return function( $response, $block_type ) use ( $inserted_block_type, $position, $anchor_block_type ) { - if ( $block_type->name !== $inserted_block_type ) { - return $response; - } - - $data = $response->get_data(); - if ( ! isset( $data['block_hooks'] ) ) { - $data['block_hooks'] = array(); - } - $data['block_hooks'][ $anchor_block_type ] = $position; - $response->set_data( $data ); - return $response; - }; -} - /** * Register hooked blocks for automatic insertion, based on their block.json metadata. * @@ -219,6 +132,93 @@ function gutenberg_add_hooked_block( $hooked_block, $position, $anchor_block ) { add_filter( 'rest_prepare_block_type', $controller_extender, 10, 2 ); } +/** + * Return a function that auto-inserts a block next to a given "anchor" block. + * + * This is a helper function used in the implementation of block hooks. + * It is not meant for public use. + * + * The auto-inserted block can be inserted before or after the anchor block, + * or as the first or last child of the anchor block. + * + * Note that the returned function mutates the automatically inserted block's + * designated parent block by inserting into the parent's `innerBlocks` array, + * and by updating the parent's `innerContent` array accordingly. + * + * @param array $inserted_block The block to insert. + * @param string $relative_position The position relative to the given block. + * Can be 'before', 'after', 'first_child', or 'last_child'. + * @param string $anchor_block_type The automatically inserted block will be inserted next to instances of this block type. + * @return callable A function that accepts a block's content and returns the content with the inserted block. + */ +function gutenberg_insert_hooked_block( $inserted_block, $relative_position, $anchor_block_type ) { + return function( $block ) use ( $inserted_block, $relative_position, $anchor_block_type ) { + if ( $anchor_block_type === $block['blockName'] ) { + if ( 'first_child' === $relative_position ) { + array_unshift( $block['innerBlocks'], $inserted_block ); + // Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`) + // when rendering blocks, we also need to prepend a value (`null`, to mark a block + // location) to that array. + array_unshift( $block['innerContent'], null ); + } elseif ( 'last_child' === $relative_position ) { + array_push( $block['innerBlocks'], $inserted_block ); + // Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`) + // when rendering blocks, we also need to prepend a value (`null`, to mark a block + // location) to that array. + array_push( $block['innerContent'], null ); + } + return $block; + } + + $anchor_block_index = array_search( $anchor_block_type, array_column( $block['innerBlocks'], 'blockName' ), true ); + if ( false !== $anchor_block_index && ( 'after' === $relative_position || 'before' === $relative_position ) ) { + if ( 'after' === $relative_position ) { + $anchor_block_index++; + } + array_splice( $block['innerBlocks'], $anchor_block_index, 0, array( $inserted_block ) ); + + // Find matching `innerContent` chunk index. + $chunk_index = 0; + while ( $anchor_block_index > 0 ) { + if ( ! is_string( $block['innerContent'][ $chunk_index ] ) ) { + $anchor_block_index--; + } + $chunk_index++; + } + // Since WP_Block::render() iterates over `inner_content` (rather than `inner_blocks`) + // when rendering blocks, we also need to insert a value (`null`, to mark a block + // location) into that array. + array_splice( $block['innerContent'], $chunk_index, 0, array( null ) ); + } + return $block; + }; +} + +/** + * Add block hooks information to a block type's controller. + * + * @param array $inserted_block_type The type of block to insert. + * @param string $position The position relative to the anchor block. + * Can be 'before', 'after', 'first_child', or 'last_child'. + * @param string $anchor_block_type The hooked block will be inserted next to instances of this block type. + * @return callable A filter for the `rest_prepare_block_type` hook that adds a `block_hooks` field to the network response. + */ +function gutenberg_add_block_hooks_field_to_block_type_controller( $inserted_block_type, $position, $anchor_block_type ) { + return function( $response, $block_type ) use ( $inserted_block_type, $position, $anchor_block_type ) { + if ( $block_type->name !== $inserted_block_type ) { + return $response; + } + + $data = $response->get_data(); + if ( ! isset( $data['block_hooks'] ) ) { + $data['block_hooks'] = array(); + } + $data['block_hooks'][ $anchor_block_type ] = $position; + $response->set_data( $data ); + return $response; + }; +} + /** * Parse and reserialize block templates to allow running filters. * From 540b966a6f5581f70dbd9c3d1d5517afeb49d461 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:46:07 +0200 Subject: [PATCH 29/37] Change PHP file name --- lib/experimental/{auto-inserting-blocks.php => block-hooks.php} | 0 lib/load.php | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename lib/experimental/{auto-inserting-blocks.php => block-hooks.php} (100%) diff --git a/lib/experimental/auto-inserting-blocks.php b/lib/experimental/block-hooks.php similarity index 100% rename from lib/experimental/auto-inserting-blocks.php rename to lib/experimental/block-hooks.php diff --git a/lib/load.php b/lib/load.php index 5b4b03838846d..51a6500396650 100644 --- a/lib/load.php +++ b/lib/load.php @@ -111,7 +111,7 @@ function gutenberg_is_experiment_enabled( $name ) { } if ( gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { - require __DIR__ . '/experimental/auto-inserting-blocks.php'; + require __DIR__ . '/experimental/block-hooks.php'; } require __DIR__ . '/experimental/interactivity-api/class-wp-interactivity-store.php'; require __DIR__ . '/experimental/interactivity-api/store.php'; From 3fa0ceb8c90046363f8fb9b8a7e867d1b4f6de38 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:48:13 +0200 Subject: [PATCH 30/37] Rename block property --- packages/block-editor/src/hooks/auto-inserting-blocks.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index d68edc93ed809..b270fd46bc449 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -30,8 +30,8 @@ function BlocksHooksControl( props ) { const hookedBlocksForCurrentBlock = useMemo( () => blockTypes?.filter( - ( { autoInsert } ) => - autoInsert && props.blockName in autoInsert + ( { blockHooks } ) => + blockHooks && props.blockName in blockHooks ), [ blockTypes, props.blockName ] ); @@ -66,7 +66,7 @@ function BlocksHooksControl( props ) { } const relativePosition = - block?.autoInsert?.[ props.blockName ]; + block?.blockHooks?.[ props.blockName ]; let candidates; switch ( relativePosition ) { @@ -207,7 +207,7 @@ function BlocksHooksControl( props ) { if ( ! checked ) { // Create and insert block. const relativePosition = - block.autoInsert[ + block.blockHooks[ props.blockName ]; insertBlockIntoDesignatedLocation( From 59c70557efd402602056c82dfa20bcef3ebc7ab9 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:49:33 +0200 Subject: [PATCH 31/37] Comment wording --- packages/block-editor/src/hooks/auto-inserting-blocks.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/auto-inserting-blocks.js index b270fd46bc449..b79edfc020b63 100644 --- a/packages/block-editor/src/hooks/auto-inserting-blocks.js +++ b/packages/block-editor/src/hooks/auto-inserting-blocks.js @@ -73,16 +73,16 @@ function BlocksHooksControl( props ) { case 'before': case 'after': // Any of the current block's siblings (with the right block type) qualifies - // as an auto-inserted block (inserted `before` or `after` the current one), - // as the block might've been auto-inserted and then moved around a bit by the user. + // as a hooked block (inserted `before` or `after` the current one), as the block + // might've been automatically inserted and then moved around a bit by the user. candidates = getBlock( rootClientId )?.innerBlocks; break; case 'first_child': case 'last_child': // Any of the current block's child blocks (with the right block type) qualifies - // as an auto-inserted first or last child block, as the block might've been - // auto-inserted and then moved around a bit by the user. + // as a hooked first or last child block, as the block might've been automatically + // inserted and then moved around a bit by the user. candidates = getBlock( props.clientId ).innerBlocks; break; } From e14313e214443f82cc468f06bf367d25bebcc977 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:50:22 +0200 Subject: [PATCH 32/37] Rename JS file --- .../src/hooks/{auto-inserting-blocks.js => block-hooks.js} | 0 packages/block-editor/src/hooks/index.js | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/block-editor/src/hooks/{auto-inserting-blocks.js => block-hooks.js} (100%) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.js b/packages/block-editor/src/hooks/block-hooks.js similarity index 100% rename from packages/block-editor/src/hooks/auto-inserting-blocks.js rename to packages/block-editor/src/hooks/block-hooks.js diff --git a/packages/block-editor/src/hooks/index.js b/packages/block-editor/src/hooks/index.js index 9907fbed89c52..0f6d52cc2c00d 100644 --- a/packages/block-editor/src/hooks/index.js +++ b/packages/block-editor/src/hooks/index.js @@ -22,7 +22,7 @@ import './metadata'; import './metadata-name'; import './behaviors'; import './custom-fields'; -import './auto-inserting-blocks'; +import './block-hooks'; import './block-rename-ui'; export { useCustomSides } from './dimensions'; From 4d05faf1ed73b7fd5059467b5cc331213881ab94 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:51:38 +0200 Subject: [PATCH 33/37] Rename SCSS file --- .../src/hooks/{auto-inserting-blocks.scss => block-hooks.scss} | 0 packages/block-editor/src/style.scss | 2 +- 2 files changed, 1 insertion(+), 1 deletion(-) rename packages/block-editor/src/hooks/{auto-inserting-blocks.scss => block-hooks.scss} (100%) diff --git a/packages/block-editor/src/hooks/auto-inserting-blocks.scss b/packages/block-editor/src/hooks/block-hooks.scss similarity index 100% rename from packages/block-editor/src/hooks/auto-inserting-blocks.scss rename to packages/block-editor/src/hooks/block-hooks.scss diff --git a/packages/block-editor/src/style.scss b/packages/block-editor/src/style.scss index e3e65469b4c54..cdb4bb2a07abf 100644 --- a/packages/block-editor/src/style.scss +++ b/packages/block-editor/src/style.scss @@ -46,7 +46,7 @@ @import "./components/url-input/style.scss"; @import "./components/url-popover/style.scss"; @import "./hooks/anchor.scss"; -@import "./hooks/auto-inserting-blocks.scss"; +@import "./hooks/block-hooks.scss"; @import "./hooks/border.scss"; @import "./hooks/color.scss"; @import "./hooks/dimensions.scss"; From 09f793818d9809ba416ece66be0da9890e2111b3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 17:57:11 +0200 Subject: [PATCH 34/37] Update comment --- lib/compat/wordpress-6.3/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.3/rest-api.php b/lib/compat/wordpress-6.3/rest-api.php index c4f42e288de77..73e8f0da61526 100644 --- a/lib/compat/wordpress-6.3/rest-api.php +++ b/lib/compat/wordpress-6.3/rest-api.php @@ -85,7 +85,7 @@ function add_modified_wp_template_schema() { } add_filter( 'rest_api_init', 'add_modified_wp_template_schema' ); -// If the Auto-inserting Blocks experiment is enabled, we load the block patterns +// If the Blocks Hooks experiment is enabled, we load the block patterns // controller in lib/experimental/rest-api.php instead. if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { /** From f6302a25cbe3c17d9c42630dea2475180c1ee9d3 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 18:51:45 +0200 Subject: [PATCH 35/37] Typo --- lib/compat/wordpress-6.3/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/compat/wordpress-6.3/rest-api.php b/lib/compat/wordpress-6.3/rest-api.php index 73e8f0da61526..041398eda24b4 100644 --- a/lib/compat/wordpress-6.3/rest-api.php +++ b/lib/compat/wordpress-6.3/rest-api.php @@ -85,7 +85,7 @@ function add_modified_wp_template_schema() { } add_filter( 'rest_api_init', 'add_modified_wp_template_schema' ); -// If the Blocks Hooks experiment is enabled, we load the block patterns +// If the Block Hooks experiment is enabled, we load the block patterns // controller in lib/experimental/rest-api.php instead. if ( ! gutenberg_is_experiment_enabled( 'gutenberg-block-hooks' ) ) { /** From c3622d6f4df6bf2328469f1d049397b51de355af Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 18:52:43 +0200 Subject: [PATCH 36/37] Another typo --- lib/experiments-page.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/experiments-page.php b/lib/experiments-page.php index 653ebb92e350e..6a022963807e3 100644 --- a/lib/experiments-page.php +++ b/lib/experiments-page.php @@ -110,7 +110,7 @@ function gutenberg_initialize_experiments_settings() { 'gutenberg-experiments', 'gutenberg_experiments_section', array( - 'label' => __( 'Block hooks allow automatically inserting a blocks in a position relative to another.', 'gutenberg' ), + 'label' => __( 'Block hooks allow automatically inserting a block in a position relative to another.', 'gutenberg' ), 'id' => 'gutenberg-block-hooks', ) ); From ca5331b21c9ab3bf132ac8f82c6d9f04a3b97805 Mon Sep 17 00:00:00 2001 From: Bernie Reiter Date: Mon, 4 Sep 2023 18:55:30 +0200 Subject: [PATCH 37/37] Streamline names in JS file --- packages/block-editor/src/hooks/block-hooks.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/block-editor/src/hooks/block-hooks.js b/packages/block-editor/src/hooks/block-hooks.js index b79edfc020b63..678f8ee06d971 100644 --- a/packages/block-editor/src/hooks/block-hooks.js +++ b/packages/block-editor/src/hooks/block-hooks.js @@ -21,7 +21,7 @@ import { store as blockEditorStore } from '../store'; const EMPTY_OBJECT = {}; -function BlocksHooksControl( props ) { +function BlockHooksControl( props ) { const blockTypes = useSelect( ( select ) => select( blocksStore ).getBlockTypes(), [] @@ -235,25 +235,25 @@ function BlocksHooksControl( props ) { ); } -export const withHookedBlocks = createHigherOrderComponent( ( BlockEdit ) => { +export const withBlockHooks = createHigherOrderComponent( ( BlockEdit ) => { return ( props ) => { const blockEdit = ; return ( <> { blockEdit } - ); }; -}, 'withHookedBlocks' ); +}, 'withBlockHooks' ); if ( window?.__experimentalBlockHooks ) { addFilter( 'editor.BlockEdit', - 'core/hooked-blocks/with-inspector-control', - withHookedBlocks + 'core/block-hooks/with-inspector-control', + withBlockHooks ); }