From d544da886e07e5d38c2f909e8106838192fcc069 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Tue, 9 Jul 2024 16:46:31 +0100 Subject: [PATCH 1/4] Global Styles: Create new public function to make it easier to expose style variations from other themes --- ...class-wp-theme-json-resolver-gutenberg.php | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index a2153e639db3b..7a8738a18e88f 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -764,8 +764,18 @@ private static function style_variation_has_scope( $variation, $scope ) { * @return array */ public static function get_style_variations( $scope = 'theme' ) { + return static::get_style_variations_from_directory( get_stylesheet_directory() ); + } + + /** + * Returns the style variation files defined by the theme (parent and child). + * + * @since 6.7.0 + * + * @return array An array of style variation files. + */ + protected static function get_style_variation_files_from_current_theme() { $variation_files = array(); - $variations = array(); $base_directory = get_stylesheet_directory() . '/styles'; $template_directory = get_template_directory() . '/styles'; if ( is_dir( $base_directory ) ) { @@ -783,6 +793,29 @@ public static function get_style_variations( $scope = 'theme' ) { } $variation_files = array_merge( $variation_files, $variation_files_parent ); } + + return $variation_files; + } + + /** + * Returns the style variations in the given directory. + * + * @since 6.7.0 + * + * @param string $directory The directory to get the style variations from. + * @param string $scope The scope or type of style variation to retrieve e.g. theme, block etc. + * @return array + */ + public static function get_style_variations_from_directory( $directory, $scope = 'theme' ) { + $variation_files = array(); + $variations = array(); + if ( is_dir( $directory ) ) { + if ( $directory === get_stylesheet_directory() ) { + $variation_files = static::get_style_variation_files_from_current_theme(); + } else { + $variation_files = static::recursively_iterate_json( $base_directory ); + } + } ksort( $variation_files ); foreach ( $variation_files as $path => $file ) { $decoded_file = self::read_json_file( $path ); From 3ee41e8c5812d9efccfb101815059532dc73edcb Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Fri, 19 Jul 2024 13:39:23 +0100 Subject: [PATCH 2/4] pass scope --- lib/class-wp-theme-json-resolver-gutenberg.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index 7a8738a18e88f..ced75e5d4deb7 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -764,7 +764,7 @@ private static function style_variation_has_scope( $variation, $scope ) { * @return array */ public static function get_style_variations( $scope = 'theme' ) { - return static::get_style_variations_from_directory( get_stylesheet_directory() ); + return static::get_style_variations_from_directory( get_stylesheet_directory(), $scope ); } /** From 2c26d657c055b49f2eba1297e0ee8e055f41e60c Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Mon, 22 Jul 2024 09:18:04 +0100 Subject: [PATCH 3/4] fix PHPCS --- ...class-wp-theme-json-resolver-gutenberg.php | 8 +++---- .../src/components/inner-blocks/index.js | 22 ++++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/lib/class-wp-theme-json-resolver-gutenberg.php b/lib/class-wp-theme-json-resolver-gutenberg.php index ced75e5d4deb7..2231cb0f11538 100644 --- a/lib/class-wp-theme-json-resolver-gutenberg.php +++ b/lib/class-wp-theme-json-resolver-gutenberg.php @@ -807,13 +807,13 @@ protected static function get_style_variation_files_from_current_theme() { * @return array */ public static function get_style_variations_from_directory( $directory, $scope = 'theme' ) { - $variation_files = array(); - $variations = array(); + $variation_files = array(); + $variations = array(); if ( is_dir( $directory ) ) { - if ( $directory === get_stylesheet_directory() ) { + if ( get_stylesheet_directory() === $directory ) { $variation_files = static::get_style_variation_files_from_current_theme(); } else { - $variation_files = static::recursively_iterate_json( $base_directory ); + $variation_files = static::recursively_iterate_json( $directory ); } } ksort( $variation_files ); diff --git a/packages/block-editor/src/components/inner-blocks/index.js b/packages/block-editor/src/components/inner-blocks/index.js index 27e5064eeb632..720b58fb9a585 100644 --- a/packages/block-editor/src/components/inner-blocks/index.js +++ b/packages/block-editor/src/components/inner-blocks/index.js @@ -7,7 +7,13 @@ import clsx from 'clsx'; * WordPress dependencies */ import { useMergeRefs } from '@wordpress/compose'; -import { forwardRef, useMemo, memo } from '@wordpress/element'; +import { + forwardRef, + useMemo, + memo, + useState, + useEffect, +} from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { getBlockSupport, @@ -186,6 +192,7 @@ export function useInnerBlocksProps( props = {}, options = {} ) { __unstableDisableDropZone, dropZoneElement, } = options; + const { clientId, layout = null, @@ -262,15 +269,28 @@ export function useInnerBlocksProps( props = {}, options = {} ) { defaultLayout, } = selected; + const [ isReady, setIsReady ] = useState( false ); + // Defer the initial rendering to avoid the jumps due to the animation. + useEffect( () => { + const timeout = setTimeout( () => { + setIsReady( true ); + }, 5000 ); + return () => { + clearTimeout( timeout ); + }; + }, [] ); + const blockDropZoneRef = useBlockDropZone( { dropZoneElement, rootClientId: clientId, parentClientId, + isDropZoneDisabled, } ); const ref = useMergeRefs( [ props.ref, __unstableDisableDropZone || + ! isReady || isDropZoneDisabled || ( layout?.isManualPlacement && window.__experimentalEnableGridInteractivity ) From d4f91a8bec26c8b68ba7cdf7383627f785f50099 Mon Sep 17 00:00:00 2001 From: Ben Dwyer Date: Mon, 22 Jul 2024 09:47:27 +0100 Subject: [PATCH 4/4] remove disconnected changes --- .../src/components/inner-blocks/index.js | 22 +------------------ 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/packages/block-editor/src/components/inner-blocks/index.js b/packages/block-editor/src/components/inner-blocks/index.js index 720b58fb9a585..27e5064eeb632 100644 --- a/packages/block-editor/src/components/inner-blocks/index.js +++ b/packages/block-editor/src/components/inner-blocks/index.js @@ -7,13 +7,7 @@ import clsx from 'clsx'; * WordPress dependencies */ import { useMergeRefs } from '@wordpress/compose'; -import { - forwardRef, - useMemo, - memo, - useState, - useEffect, -} from '@wordpress/element'; +import { forwardRef, useMemo, memo } from '@wordpress/element'; import { useSelect } from '@wordpress/data'; import { getBlockSupport, @@ -192,7 +186,6 @@ export function useInnerBlocksProps( props = {}, options = {} ) { __unstableDisableDropZone, dropZoneElement, } = options; - const { clientId, layout = null, @@ -269,28 +262,15 @@ export function useInnerBlocksProps( props = {}, options = {} ) { defaultLayout, } = selected; - const [ isReady, setIsReady ] = useState( false ); - // Defer the initial rendering to avoid the jumps due to the animation. - useEffect( () => { - const timeout = setTimeout( () => { - setIsReady( true ); - }, 5000 ); - return () => { - clearTimeout( timeout ); - }; - }, [] ); - const blockDropZoneRef = useBlockDropZone( { dropZoneElement, rootClientId: clientId, parentClientId, - isDropZoneDisabled, } ); const ref = useMergeRefs( [ props.ref, __unstableDisableDropZone || - ! isReady || isDropZoneDisabled || ( layout?.isManualPlacement && window.__experimentalEnableGridInteractivity )