From 5b83ef707ea8bc9ebf1643330d93728bc2cbbdeb Mon Sep 17 00:00:00 2001 From: Luigi Teschio Date: Fri, 25 Oct 2024 14:48:30 +0200 Subject: [PATCH] fix logic --- lib/compat/wordpress-6.8/template-parts.php | 2 +- .../src/template-part/edit/utils/hooks.js | 9 ++------- packages/editor/src/store/selectors.js | 19 ++++++++++--------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/lib/compat/wordpress-6.8/template-parts.php b/lib/compat/wordpress-6.8/template-parts.php index 1f126d1bdd98ee..7f7fb32a0e6a5e 100644 --- a/lib/compat/wordpress-6.8/template-parts.php +++ b/lib/compat/wordpress-6.8/template-parts.php @@ -31,7 +31,7 @@ function gutenberg_add_default_template_types_to_index( WP_REST_Response $respon $indexed_template_types[] = $template_type; } - $response->data['defaultTemplateTypes'] = indexed_template_types(); + $response->data['defaultTemplateTypes'] = $indexed_template_types; return $response; } diff --git a/packages/block-library/src/template-part/edit/utils/hooks.js b/packages/block-library/src/template-part/edit/utils/hooks.js index 39daa4080c8160..a8ed6b673675a6 100644 --- a/packages/block-library/src/template-part/edit/utils/hooks.js +++ b/packages/block-library/src/template-part/edit/utils/hooks.js @@ -136,14 +136,9 @@ export function useCreateTemplatePartFromBlocks( area, setAttributes ) { export function useTemplatePartArea( area ) { return useSelect( ( select ) => { - // FIXME: @wordpress/block-library should not depend on @wordpress/editor. - // Blocks can be loaded into a *non-post* block editor. - /* eslint-disable @wordpress/data-no-store-string-literals */ const definedAreas = - select( - 'core/editor' - ).__experimentalGetDefaultTemplatePartAreas(); - /* eslint-enable @wordpress/data-no-store-string-literals */ + select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) + ?.defaultTemplatePartAreas || []; const selectedArea = definedAreas.find( ( definedArea ) => definedArea.area === area diff --git a/packages/editor/src/store/selectors.js b/packages/editor/src/store/selectors.js index 3aa1c4daca96e7..b3ad5e73928357 100644 --- a/packages/editor/src/store/selectors.js +++ b/packages/editor/src/store/selectors.js @@ -1716,15 +1716,16 @@ export const __experimentalGetDefaultTemplateTypes = createRegistrySelector( * @return {Array} The template part areas. */ export const __experimentalGetDefaultTemplatePartAreas = createRegistrySelector( - ( select ) => () => { - const areas = - select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) - ?.defaultTemplatePartAreas ?? []; - - return areas.map( ( item ) => { - return { ...item, icon: getTemplatePartIcon( item.icon ) }; - } ); - } + ( select ) => + createSelector( () => { + const areas = + select( coreStore ).getEntityRecord( 'root', '__unstableBase' ) + ?.defaultTemplatePartAreas || []; + + return areas.map( ( item ) => { + return { ...item, icon: getTemplatePartIcon( item.icon ) }; + } ); + } ) ); /**