From 47041dc191f8240070915c1ef30424aa2083666a Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Fri, 22 Jan 2021 09:28:38 -0500 Subject: [PATCH] WIP: Check for Theme Support before adding styles When the Block Editor handles blocks that support color, if the color applied is a palette color the value of that color is still applied by way of a style attribute. This is done to provide backward compatability for themes that don't include the palette CSS in their editor stylesheet. However, for themes that DO provide those classes, and especially for those where the behavior isn't just "change the color" (i.e. Spearhead 'dark' mode) this logic breaks expected behavior. This is an attempt to allow a theme to express, by way of a theme supports flag, that those style attributes should NOT be applied to the block; the classes will suffice. --- packages/block-editor/src/hooks/color.js | 36 ++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/packages/block-editor/src/hooks/color.js b/packages/block-editor/src/hooks/color.js index 5490e045fbc056..8436b411f572ba 100644 --- a/packages/block-editor/src/hooks/color.js +++ b/packages/block-editor/src/hooks/color.js @@ -12,6 +12,7 @@ import { getBlockSupport } from '@wordpress/blocks'; import { __ } from '@wordpress/i18n'; import { useRef, useEffect, Platform } from '@wordpress/element'; import { createHigherOrderComponent } from '@wordpress/compose'; +import { useSelect } from '@wordpress/data'; /** * Internal dependencies @@ -363,6 +364,34 @@ export function ColorEdit( props ) { ); } +/* +I expect this should either go somewhere else, already exists somewhere else and that should be used instead, or should be done differently. +*/ +function hasThemeSupport( supportFlag ) { + return useSelect( ( select ) => { + const { getThemeSupports } = select( 'core' ); + const themeSupports = getThemeSupports(); + + //TODO: The value of themeSupports appears to be cached in a way that I can't bust. + //It is pre-loaded in a