Skip to content

Commit 371812e

Browse files
committed
Revert "Add defaultFontSizes option to theme.json (#56661)"
This reverts commit 940f0fe.
1 parent 90e9bc9 commit 371812e

File tree

8 files changed

+31
-101
lines changed

8 files changed

+31
-101
lines changed

docs/reference-guides/theme-json-reference/theme-json-living.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,6 @@ Settings related to typography.
177177

178178
| Property | Type | Default | Props |
179179
| --- | --- | --- |--- |
180-
| defaultFontSizes | boolean | true | |
181180
| customFontSize | boolean | true | |
182181
| fontStyle | boolean | true | |
183182
| fontWeight | boolean | true | |

lib/class-wp-theme-json-gutenberg.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class WP_Theme_JSON_Gutenberg {
155155
),
156156
array(
157157
'path' => array( 'typography', 'fontSizes' ),
158-
'prevent_override' => array( 'typography', 'defaultFontSizes' ),
158+
'prevent_override' => false,
159159
'use_default_names' => true,
160160
'value_func' => 'gutenberg_get_typography_font_size_value',
161161
'css_vars' => '--wp--preset--font-size--$slug',
@@ -413,20 +413,19 @@ class WP_Theme_JSON_Gutenberg {
413413
'defaultPresets' => null,
414414
),
415415
'typography' => array(
416-
'fluid' => null,
417-
'customFontSize' => null,
418-
'defaultFontSizes' => null,
419-
'dropCap' => null,
420-
'fontFamilies' => null,
421-
'fontSizes' => null,
422-
'fontStyle' => null,
423-
'fontWeight' => null,
424-
'letterSpacing' => null,
425-
'lineHeight' => null,
426-
'textColumns' => null,
427-
'textDecoration' => null,
428-
'textTransform' => null,
429-
'writingMode' => null,
416+
'fluid' => null,
417+
'customFontSize' => null,
418+
'dropCap' => null,
419+
'fontFamilies' => null,
420+
'fontSizes' => null,
421+
'fontStyle' => null,
422+
'fontWeight' => null,
423+
'letterSpacing' => null,
424+
'lineHeight' => null,
425+
'textColumns' => null,
426+
'textDecoration' => null,
427+
'textTransform' => null,
428+
'writingMode' => null,
430429
),
431430
);
432431

lib/theme.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@
236236
},
237237
"typography": {
238238
"customFontSize": true,
239-
"defaultFontSizes": true,
240239
"dropCap": true,
241240
"fontSizes": [
242241
{

packages/block-editor/src/components/global-styles/hooks.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ const VALID_SETTINGS = [
6767
'spacing.units',
6868
'typography.fluid',
6969
'typography.customFontSize',
70-
'typography.defaultFontSizes',
7170
'typography.dropCap',
7271
'typography.fontFamilies',
7372
'typography.fontSizes',
@@ -240,7 +239,6 @@ export function useSettingsForBlockElement(
240239
...updatedSettings.typography,
241240
fontSizes: {},
242241
customFontSize: false,
243-
defaultFontSizes: false,
244242
};
245243
}
246244

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

Lines changed: 13 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import TextTransformControl from '../text-transform-control';
2222
import TextDecorationControl from '../text-decoration-control';
2323
import WritingModeControl from '../writing-mode-control';
2424
import { getValueFromVariable, TOOLSPANEL_DROPDOWNMENU_PROPS } from './utils';
25-
import { setImmutably, uniqByProperty } from '../../utils/object';
25+
import { setImmutably } from '../../utils/object';
2626

2727
const MIN_TEXT_COLUMNS = 1;
2828
const MAX_TEXT_COLUMNS = 6;
@@ -53,10 +53,7 @@ export function useHasTypographyPanel( settings ) {
5353

5454
function useHasFontSizeControl( settings ) {
5555
return (
56-
( settings?.typography?.defaultFontSizes !== false &&
57-
settings?.typography?.fontSizes?.default?.length ) ||
58-
settings?.typography?.fontSizes?.theme?.length ||
59-
settings?.typography?.fontSizes?.custom?.length ||
56+
hasMergedOrigins( settings?.typography?.fontSizes ) ||
6057
settings?.typography?.customFontSize
6158
);
6259
}
@@ -103,45 +100,16 @@ function useHasTextColumnsControl( settings ) {
103100
return settings?.typography?.textColumns;
104101
}
105102

106-
/**
107-
* TODO: The reversing and filtering of default font sizes is a hack so the
108-
* dropdown UI matches what is generated in the global styles CSS stylesheet.
109-
*
110-
* This is a temporary solution until #57733 is resolved. At which point,
111-
* the mergedFontSizes would just need to be the concatenated array of all
112-
* presets or a custom dropdown with sections for each.
113-
*
114-
* @see {@link https://github.com/WordPress/gutenberg/issues/57733}
115-
*
116-
* @param {Object} settings The global styles settings.
117-
*
118-
* @return {Array} The merged font sizes.
119-
*/
120-
function getMergedFontSizes( settings ) {
121-
// The font size presets are merged in reverse order so that the duplicates
122-
// that may defined later in the array have higher priority to match the CSS.
123-
const mergedFontSizesAll = uniqByProperty(
124-
[
125-
settings?.typography?.fontSizes?.custom,
126-
settings?.typography?.fontSizes?.theme,
127-
settings?.typography?.fontSizes?.default,
128-
].flatMap( ( presets ) => presets?.toReversed() ?? [] ),
129-
'slug'
130-
).reverse();
131-
132-
// Default presets exist in the global styles CSS no matter the setting, so
133-
// filtering them out in the UI has to be done after merging.
134-
const mergedFontSizes =
135-
settings?.typography?.defaultFontSizes === false
136-
? mergedFontSizesAll.filter(
137-
( { slug } ) =>
138-
! [ 'small', 'medium', 'large', 'x-large' ].includes(
139-
slug
140-
)
141-
)
142-
: mergedFontSizesAll;
143-
144-
return mergedFontSizes;
103+
function getUniqueFontSizesBySlug( settings ) {
104+
const fontSizes = settings?.typography?.fontSizes;
105+
const mergedFontSizes = fontSizes ? mergeOrigins( fontSizes ) : [];
106+
const uniqueSizes = [];
107+
for ( const currentSize of mergedFontSizes ) {
108+
if ( ! uniqueSizes.some( ( { slug } ) => slug === currentSize.slug ) ) {
109+
uniqueSizes.push( currentSize );
110+
}
111+
}
112+
return uniqueSizes;
145113
}
146114

147115
function TypographyToolsPanel( {
@@ -217,7 +185,7 @@ export default function TypographyPanel( {
217185
// Font Size
218186
const hasFontSizeEnabled = useHasFontSizeControl( settings );
219187
const disableCustomFontSizes = ! settings?.typography?.customFontSize;
220-
const mergedFontSizes = getMergedFontSizes( settings );
188+
const mergedFontSizes = getUniqueFontSizesBySlug( settings );
221189

222190
const fontSize = decodeValue( inheritedValue?.typography?.fontSize );
223191
const setFontSize = ( newValue, metadata ) => {

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ export function useBlockSettings( name, parentLayout ) {
177177
backgroundImage,
178178
backgroundSize,
179179
fontFamilies,
180-
userFontSizes,
181-
themeFontSizes,
182-
defaultFontSizes,
183-
defaultFontSizesEnabled,
180+
fontSizes,
184181
customFontSize,
185182
fontStyle,
186183
fontWeight,
@@ -227,10 +224,7 @@ export function useBlockSettings( name, parentLayout ) {
227224
'background.backgroundImage',
228225
'background.backgroundSize',
229226
'typography.fontFamilies',
230-
'typography.fontSizes.custom',
231-
'typography.fontSizes.theme',
232-
'typography.fontSizes.default',
233-
'typography.defaultFontSizes',
227+
'typography.fontSizes',
234228
'typography.customFontSize',
235229
'typography.fontStyle',
236230
'typography.fontWeight',
@@ -314,12 +308,9 @@ export function useBlockSettings( name, parentLayout ) {
314308
custom: fontFamilies,
315309
},
316310
fontSizes: {
317-
custom: userFontSizes,
318-
theme: themeFontSizes,
319-
default: defaultFontSizes,
311+
custom: fontSizes,
320312
},
321313
customFontSize,
322-
defaultFontSizes: defaultFontSizesEnabled,
323314
fontStyle,
324315
fontWeight,
325316
lineHeight,
@@ -356,10 +347,7 @@ export function useBlockSettings( name, parentLayout ) {
356347
backgroundImage,
357348
backgroundSize,
358349
fontFamilies,
359-
userFontSizes,
360-
themeFontSizes,
361-
defaultFontSizes,
362-
defaultFontSizesEnabled,
350+
fontSizes,
363351
customFontSize,
364352
fontStyle,
365353
fontWeight,

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

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,3 @@ export const getValueFromObjectPath = ( object, path, defaultValue ) => {
4949
} );
5050
return value ?? defaultValue;
5151
};
52-
53-
/**
54-
* Helper util to filter out objects with duplicate values for a given property.
55-
*
56-
* @param {Object[]} array Array of objects to filter.
57-
* @param {string} property Property to filter unique values by.
58-
*
59-
* @return {Object[]} Array of objects with unique values for the specified property.
60-
*/
61-
export function uniqByProperty( array, property ) {
62-
const seen = new Set();
63-
return array.filter( ( item ) => {
64-
const value = item[ property ];
65-
return seen.has( value ) ? false : seen.add( value );
66-
} );
67-
}

schemas/json/theme.json

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -489,11 +489,6 @@
489489
"description": "Settings related to typography.",
490490
"type": "object",
491491
"properties": {
492-
"defaultFontSizes": {
493-
"description": "Allow users to choose font sizes from the default font size presets.",
494-
"type": "boolean",
495-
"default": true
496-
},
497492
"customFontSize": {
498493
"description": "Allow users to set custom font sizes.",
499494
"type": "boolean",

0 commit comments

Comments
 (0)