Skip to content

Commit f2a5323

Browse files
ajlendeajlendeyouknowriadt-hamanoMaggieCabrera
committed
Revert #55219 fix/block-settings-origins (#58951)
Co-authored-by: ajlende <ajlende@git.wordpress.org> Co-authored-by: youknowriad <youknowriad@git.wordpress.org> Co-authored-by: t-hamano <wildworks@git.wordpress.org> Co-authored-by: MaggieCabrera <onemaggie@git.wordpress.org> Co-authored-by: getdave <get_dave@git.wordpress.org> Co-authored-by: scruffian <scruffian@git.wordpress.org> Co-authored-by: andrewserong <andrewserong@git.wordpress.org> Co-authored-by: matiasbenedetto <mmaattiiaass@git.wordpress.org> Co-authored-by: carolinan <poena@git.wordpress.org> Co-authored-by: justintadlock <greenshady@git.wordpress.org> Co-authored-by: annezazu <annezazu@git.wordpress.org> Co-authored-by: widoz <wido@git.wordpress.org> Co-authored-by: colorful-tones <colorful-tones@git.wordpress.org> Co-authored-by: iamtakashi <iamtakashi@git.wordpress.org> Co-authored-by: juanfra <juanfra@git.wordpress.org> Co-authored-by: hanneslsm <hanneslsm@git.wordpress.org> Co-authored-by: richtabor <richtabor@git.wordpress.org>
1 parent 1289886 commit f2a5323

File tree

6 files changed

+60
-27
lines changed

6 files changed

+60
-27
lines changed

packages/block-editor/src/components/global-styles/border-panel.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { __ } from '@wordpress/i18n';
1919
import BorderRadiusControl from '../border-radius-control';
2020
import { useColorsPerOrigin } from './hooks';
2121
import { getValueFromVariable, TOOLSPANEL_DROPDOWNMENU_PROPS } from './utils';
22-
import { mergeOrigins } from '../../store/get-block-settings';
22+
import { overrideOrigins } from '../../store/get-block-settings';
2323
import { setImmutably } from '../../utils/object';
2424
import { getBorderPanelLabel } from '../../hooks/border';
2525
import { ShadowPopover } from './shadow-panel-components';
@@ -154,12 +154,12 @@ export default function BorderPanel( {
154154

155155
// Shadow
156156
const shadow = decodeValue( inheritedValue?.shadow );
157-
const shadowPresets = settings?.shadow?.presets;
158-
const mergedShadowPresets = shadowPresets
159-
? mergeOrigins( shadowPresets )
157+
const shadowPresets = settings?.shadow?.presets ?? {};
158+
const overriddenShadowPresets = shadowPresets
159+
? overrideOrigins( shadowPresets )
160160
: [];
161161
const setShadow = ( newValue ) => {
162-
const slug = mergedShadowPresets?.find(
162+
const slug = overriddenShadowPresets?.find(
163163
( { shadow: shadowName } ) => shadowName === newValue
164164
)?.slug;
165165

packages/block-editor/src/components/global-styles/typography-panel.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { useCallback } from '@wordpress/element';
1313
/**
1414
* Internal dependencies
1515
*/
16-
import { mergeOrigins, hasMergedOrigins } from '../../store/get-block-settings';
16+
import {
17+
mergeOrigins,
18+
overrideOrigins,
19+
hasOriginValue,
20+
} from '../../store/get-block-settings';
1721
import FontFamilyControl from '../font-family';
1822
import FontAppearanceControl from '../font-appearance-control';
1923
import LineHeightControl from '../line-height-control';
@@ -53,13 +57,13 @@ export function useHasTypographyPanel( settings ) {
5357

5458
function useHasFontSizeControl( settings ) {
5559
return (
56-
hasMergedOrigins( settings?.typography?.fontSizes ) ||
60+
hasOriginValue( settings?.typography?.fontSizes ) ||
5761
settings?.typography?.customFontSize
5862
);
5963
}
6064

6165
function useHasFontFamilyControl( settings ) {
62-
return hasMergedOrigins( settings?.typography?.fontFamilies );
66+
return hasOriginValue( settings?.typography?.fontFamilies );
6367
}
6468

6569
function useHasLineHeightControl( settings ) {
@@ -101,10 +105,10 @@ function useHasTextColumnsControl( settings ) {
101105
}
102106

103107
function getUniqueFontSizesBySlug( settings ) {
104-
const fontSizes = settings?.typography?.fontSizes;
105-
const mergedFontSizes = fontSizes ? mergeOrigins( fontSizes ) : [];
108+
const fontSizes = settings?.typography?.fontSizes ?? {};
109+
const overriddenFontSizes = fontSizes ? overrideOrigins( fontSizes ) : [];
106110
const uniqueSizes = [];
107-
for ( const currentSize of mergedFontSizes ) {
111+
for ( const currentSize of overriddenFontSizes ) {
108112
if ( ! uniqueSizes.some( ( { slug } ) => slug === currentSize.slug ) ) {
109113
uniqueSizes.push( currentSize );
110114
}
@@ -162,7 +166,7 @@ export default function TypographyPanel( {
162166

163167
// Font Family
164168
const hasFontFamilyEnabled = useHasFontFamilyControl( settings );
165-
const fontFamilies = settings?.typography?.fontFamilies;
169+
const fontFamilies = settings?.typography?.fontFamilies ?? {};
166170
const mergedFontFamilies = fontFamilies ? mergeOrigins( fontFamilies ) : [];
167171
const fontFamily = decodeValue( inheritedValue?.typography?.fontFamily );
168172
const setFontFamily = ( newValue ) => {

packages/block-editor/src/hooks/utils.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -176,8 +176,12 @@ export function useBlockSettings( name, parentLayout ) {
176176
const [
177177
backgroundImage,
178178
backgroundSize,
179-
fontFamilies,
180-
fontSizes,
179+
customFontFamilies,
180+
defaultFontFamilies,
181+
themeFontFamilies,
182+
customFontSizes,
183+
defaultFontSizes,
184+
themeFontSizes,
181185
customFontSize,
182186
fontStyle,
183187
fontWeight,
@@ -223,8 +227,12 @@ export function useBlockSettings( name, parentLayout ) {
223227
] = useSettings(
224228
'background.backgroundImage',
225229
'background.backgroundSize',
226-
'typography.fontFamilies',
227-
'typography.fontSizes',
230+
'typography.fontFamilies.custom',
231+
'typography.fontFamilies.default',
232+
'typography.fontFamilies.theme',
233+
'typography.fontSizes.custom',
234+
'typography.fontSizes.default',
235+
'typography.fontSizes.theme',
228236
'typography.customFontSize',
229237
'typography.fontStyle',
230238
'typography.fontWeight',
@@ -305,10 +313,14 @@ export function useBlockSettings( name, parentLayout ) {
305313
},
306314
typography: {
307315
fontFamilies: {
308-
custom: fontFamilies,
316+
custom: customFontFamilies,
317+
default: defaultFontFamilies,
318+
theme: themeFontFamilies,
309319
},
310320
fontSizes: {
311-
custom: fontSizes,
321+
custom: customFontSizes,
322+
default: defaultFontSizes,
323+
theme: themeFontSizes,
312324
},
313325
customFontSize,
314326
fontStyle,
@@ -346,8 +358,12 @@ export function useBlockSettings( name, parentLayout ) {
346358
}, [
347359
backgroundImage,
348360
backgroundSize,
349-
fontFamilies,
350-
fontSizes,
361+
customFontFamilies,
362+
defaultFontFamilies,
363+
themeFontFamilies,
364+
customFontSizes,
365+
defaultFontSizes,
366+
themeFontSizes,
351367
customFontSize,
352368
fontStyle,
353369
fontWeight,

packages/block-editor/src/store/get-block-settings.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* WordPress dependencies
33
*/
44
import {
5-
__EXPERIMENTAL_PATHS_WITH_MERGE as PATHS_WITH_MERGE,
5+
__EXPERIMENTAL_PATHS_WITH_OVERRIDE as PATHS_WITH_OVERRIDE,
66
hasBlockSupport,
77
} from '@wordpress/blocks';
88
import { applyFilters } from '@wordpress/hooks';
@@ -111,6 +111,17 @@ export function mergeOrigins( value ) {
111111
}
112112
const mergeCache = new WeakMap();
113113

114+
/**
115+
* For settings like `color.palette`, which have a value that is an object
116+
* with `default`, `theme`, `custom`, with field values that are arrays of
117+
* items, returns the one with the highest priority among these three arrays.
118+
* @param {Object} value Object to extract from
119+
* @return {Array} Array of items extracted from the three origins
120+
*/
121+
export function overrideOrigins( value ) {
122+
return value.custom ?? value.theme ?? value.default;
123+
}
124+
114125
/**
115126
* For settings like `color.palette`, which have a value that is an object
116127
* with `default`, `theme`, `custom`, with field values that are arrays of
@@ -119,7 +130,7 @@ const mergeCache = new WeakMap();
119130
* @param {Object} value Object to check
120131
* @return {boolean} Whether the object has values in any of the three origins
121132
*/
122-
export function hasMergedOrigins( value ) {
133+
export function hasOriginValue( value ) {
123134
return [ 'default', 'theme', 'custom' ].some(
124135
( key ) => value?.[ key ]?.length
125136
);
@@ -203,8 +214,8 @@ export function getBlockSettings( state, clientId, ...paths ) {
203214

204215
// Return if the setting was found in either the block instance or the store.
205216
if ( result !== undefined ) {
206-
if ( PATHS_WITH_MERGE[ normalizedPath ] ) {
207-
return mergeOrigins( result );
217+
if ( PATHS_WITH_OVERRIDE[ normalizedPath ] ) {
218+
return overrideOrigins( result );
208219
}
209220
return result;
210221
}

packages/blocks/src/api/constants.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,13 @@ export const __EXPERIMENTAL_ELEMENTS = {
271271
cite: 'cite',
272272
};
273273

274-
export const __EXPERIMENTAL_PATHS_WITH_MERGE = {
274+
// These paths may have three origins, custom, theme, and default,
275+
// and are expected to override other origins with custom, theme,
276+
// and default priority.
277+
export const __EXPERIMENTAL_PATHS_WITH_OVERRIDE = {
275278
'color.duotone': true,
276279
'color.gradients': true,
277280
'color.palette': true,
278-
'typography.fontFamilies': true,
279281
'typography.fontSizes': true,
280282
'spacing.spacingSizes': true,
281283
};

packages/blocks/src/api/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,5 @@ export { default as node } from './node';
163163
export {
164164
__EXPERIMENTAL_STYLE_PROPERTY,
165165
__EXPERIMENTAL_ELEMENTS,
166-
__EXPERIMENTAL_PATHS_WITH_MERGE,
166+
__EXPERIMENTAL_PATHS_WITH_OVERRIDE,
167167
} from './constants';

0 commit comments

Comments
 (0)