From ec668b8358f398b14d832a7f80bbb73a0436a0d2 Mon Sep 17 00:00:00 2001 From: ramon Date: Fri, 2 Aug 2024 11:22:27 +1000 Subject: [PATCH] Wipes out theme utils - looks like we don't need them Do all ref and URI resolution in getStylesDeclarations() --- .../global-styles/background-panel.js | 22 +++------- .../test/theme-file-uri-utils.js | 41 ------------------- .../global-styles/theme-file-uri-utils.js | 18 -------- 3 files changed, 5 insertions(+), 76 deletions(-) delete mode 100644 packages/block-editor/src/components/global-styles/test/theme-file-uri-utils.js delete mode 100644 packages/block-editor/src/components/global-styles/theme-file-uri-utils.js diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js index 08ed251da4899..4be3382f854cd 100644 --- a/packages/block-editor/src/components/global-styles/background-panel.js +++ b/packages/block-editor/src/components/global-styles/background-panel.js @@ -43,11 +43,11 @@ import { isBlobURL } from '@wordpress/blob'; /** * Internal dependencies */ -import { useToolsPanelDropdownMenuProps, getResolvedRefValue } from './utils'; +import { useToolsPanelDropdownMenuProps, getResolvedValue } from './utils'; import { setImmutably } from '../../utils/object'; import MediaReplaceFlow from '../media-replace-flow'; import { store as blockEditorStore } from '../../store'; -import { getResolvedThemeFilePath } from './theme-file-uri-utils'; + import { globalStylesDataKey, globalStylesLinksDataKey, @@ -680,7 +680,6 @@ export default function BackgroundPanel( { defaultControls = DEFAULT_CONTROLS, defaultValues = {}, headerLabel = __( 'Background image' ), - themeFileURIs, } ) { const { globalStyles, _links } = useSelect( ( select ) => { const { getSettings } = select( blockEditorStore ); @@ -691,8 +690,6 @@ export default function BackgroundPanel( { }; }, [] ); - themeFileURIs = themeFileURIs || _links?.[ 'wp:theme-file' ]; - /* * Resolve any inherited "ref" pointers. * Should the block editor need inherited values @@ -709,26 +706,17 @@ export default function BackgroundPanel( { Object.entries( inheritedValue?.background ).forEach( ( [ key, backgroundValue ] ) => { - resolvedValues.background[ key ] = getResolvedRefValue( + resolvedValues.background[ key ] = getResolvedValue( backgroundValue, { styles: globalStyles, + _links, } ); - if ( - 'backgroundImage' === key && - resolvedValues.background[ key ]?.url - ) { - resolvedValues.background[ key ].url = - getResolvedThemeFilePath( - resolvedValues.background[ key ].url, - themeFileURIs - ); - } } ); return resolvedValues; - }, [ globalStyles, inheritedValue ] ); + }, [ globalStyles, _links, inheritedValue ] ); const resetAllFilter = useCallback( ( previousValue ) => { return { diff --git a/packages/block-editor/src/components/global-styles/test/theme-file-uri-utils.js b/packages/block-editor/src/components/global-styles/test/theme-file-uri-utils.js deleted file mode 100644 index e239bb0941ea9..0000000000000 --- a/packages/block-editor/src/components/global-styles/test/theme-file-uri-utils.js +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Internal dependencies - */ -import { getResolvedThemeFilePath } from '../theme-file-uri-utils'; - -const themeFileURIs = [ - { - name: 'file:./assets/image.jpg', - href: 'https://wordpress.org/assets/image.jpg', - target: 'styles.background.backgroundImage.url', - }, - { - name: 'file:./assets/other/image.jpg', - href: 'https://wordpress.org/assets/other/image.jpg', - target: "styles.blocks.['core/group].background.backgroundImage.url", - }, -]; - -describe( 'getResolvedThemeFilePath()', () => { - it.each( [ - [ - 'file:./assets/image.jpg', - 'https://wordpress.org/assets/image.jpg', - 'Should return absolute URL if found in themeFileURIs', - ], - [ - 'file:./misc/image.jpg', - 'file:./misc/image.jpg', - 'Should return value if not found in themeFileURIs', - ], - [ - 'https://wordpress.org/assets/image.jpg', - 'https://wordpress.org/assets/image.jpg', - 'Should not match absolute URLs', - ], - ] )( 'Given file %s and return value %s: %s', ( file, returnedValue ) => { - expect( - getResolvedThemeFilePath( file, themeFileURIs ) === returnedValue - ).toBe( true ); - } ); -} ); diff --git a/packages/block-editor/src/components/global-styles/theme-file-uri-utils.js b/packages/block-editor/src/components/global-styles/theme-file-uri-utils.js deleted file mode 100644 index 96b3e2e4cb68b..0000000000000 --- a/packages/block-editor/src/components/global-styles/theme-file-uri-utils.js +++ /dev/null @@ -1,18 +0,0 @@ -/** - * Looks up a theme file URI based on a relative path. - * - * @param {string} file A relative path. - * @param {Array} themeFileURIs A collection of absolute theme file URIs and their corresponding file paths. - * @return {string?} A resolved theme file URI, if one is found in the themeFileURIs collection. - */ -export function getResolvedThemeFilePath( file, themeFileURIs = [] ) { - const uri = themeFileURIs.find( - ( themeFileUri ) => themeFileUri.name === file - ); - - if ( ! uri?.href ) { - return file; - } - - return uri?.href; -}