Skip to content

Commit

Permalink
Global Styles: rename core origin key to default for presets (#36645
Browse files Browse the repository at this point in the history
)

Co-authored-by: André <583546+oandregal@users.noreply.github.com>
  • Loading branch information
jorgefilipecosta and oandregal committed Nov 19, 2021
1 parent 070c722 commit 914c9c9
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions lib/class-wp-theme-json-gutenberg.php
Expand Up @@ -35,7 +35,7 @@ class WP_Theme_JSON_Gutenberg {
const ROOT_BLOCK_SELECTOR = 'body';

const VALID_ORIGINS = array(
'core',
'default',
'theme',
'user',
);
Expand Down Expand Up @@ -281,7 +281,7 @@ class WP_Theme_JSON_Gutenberg {
* Constructor.
*
* @param array $theme_json A structure that follows the theme.json schema.
* @param string $origin What source of data this object represents. One of core, theme, or user. Default: theme.
* @param string $origin What source of data this object represents. One of default, theme, or user. Default: theme.
*/
public function __construct( $theme_json = array(), $origin = 'theme' ) {
if ( ! in_array( $origin, self::VALID_ORIGINS, true ) ) {
Expand Down Expand Up @@ -1263,7 +1263,7 @@ private static function get_setting_nodes( $theme_json, $selectors = array() ) {
* 'variables': only the CSS Custom Properties for presets & custom ones.
* 'styles': only the styles section in theme.json.
* 'presets': only the classes for the presets.
* @param array $origins A list of origins to include. By default it includes 'core', 'theme', and 'user'.
* @param array $origins A list of origins to include. By default it includes 'default', 'theme', and 'user'.
*
* @return string Stylesheet.
*/
Expand Down
6 changes: 3 additions & 3 deletions lib/class-wp-theme-json-resolver-gutenberg.php
Expand Up @@ -117,7 +117,7 @@ public static function get_core_data() {

$config = self::read_json_file( __DIR__ . '/theme.json' );
$config = self::translate( $config );
self::$core = new WP_Theme_JSON_Gutenberg( $config, 'core' );
self::$core = new WP_Theme_JSON_Gutenberg( $config, 'default' );

return self::$core;
}
Expand Down Expand Up @@ -283,8 +283,8 @@ public static function get_user_data() {

/**
* There are three sources of data (origins) for a site:
* core, theme, and user. The user's has higher priority
* than the theme's, and the theme's higher than core's.
* default, theme, and user. The user's has higher priority
* than the theme's, and the theme's higher than defaults's.
*
* Unlike the getters {@link get_core_data},
* {@link get_theme_data}, and {@link get_user_data},
Expand Down
6 changes: 3 additions & 3 deletions lib/compat/wordpress-5.9/get-global-styles-and-settings.php
Expand Up @@ -99,14 +99,14 @@ function gutenberg_get_global_stylesheet( $types = array() ) {
$types = array( 'variables', 'styles', 'presets' );
}

$origins = array( 'core', 'theme', 'user' );
$origins = array( 'default', 'theme', 'user' );
if ( ! $supports_theme_json && ! $supports_link_color ) {
// In this case we only enqueue the core presets (CSS Custom Properties + the classes).
$origins = array( 'core' );
$origins = array( 'default' );
} elseif ( ! $supports_theme_json && $supports_link_color ) {
// For the legacy link color feature to work, the CSS Custom Properties
// should be in scope (either the core or the theme ones).
$origins = array( 'core', 'theme' );
$origins = array( 'default', 'theme' );
}

$tree = WP_Theme_JSON_Resolver_Gutenberg::get_merged_data();
Expand Down
6 changes: 3 additions & 3 deletions lib/global-styles.php
Expand Up @@ -114,7 +114,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
$colors_by_origin['user'] : (
isset( $colors_by_origin['theme'] ) ?
$colors_by_origin['theme'] :
$colors_by_origin['core']
$colors_by_origin['default']
);
}

Expand All @@ -124,7 +124,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
$gradients_by_origin['user'] : (
isset( $gradients_by_origin['theme'] ) ?
$gradients_by_origin['theme'] :
$gradients_by_origin['core']
$gradients_by_origin['default']
);
}

Expand All @@ -134,7 +134,7 @@ function_exists( 'gutenberg_is_edit_site_page' ) &&
$font_sizes_by_origin['user'] : (
isset( $font_sizes_by_origin['theme'] ) ?
$font_sizes_by_origin['theme'] :
$font_sizes_by_origin['core']
$font_sizes_by_origin['default']
);
}

Expand Down
Expand Up @@ -174,7 +174,7 @@ const PanelColorGradientSettingsMultipleSelect = ( props ) => {
const colorGradientSettings = useCommonSingleMultipleSelects();
const customColors = useSetting( 'color.palette.user' );
const themeColors = useSetting( 'color.palette.theme' );
const defaultColors = useSetting( 'color.palette.core' );
const defaultColors = useSetting( 'color.palette.default' );
const shouldDisplayDefaultColors = useSetting( 'color.defaultPalette' );

colorGradientSettings.colors = useMemo( () => {
Expand Down Expand Up @@ -215,7 +215,7 @@ const PanelColorGradientSettingsMultipleSelect = ( props ) => {

const customGradients = useSetting( 'color.gradients.user' );
const themeGradients = useSetting( 'color.gradients.theme' );
const defaultGradients = useSetting( 'color.gradients.core' );
const defaultGradients = useSetting( 'color.gradients.default' );
const shouldDisplayDefaultGradients = useSetting(
'color.defaultGradients'
);
Expand Down
2 changes: 1 addition & 1 deletion packages/block-editor/src/components/use-setting/index.js
Expand Up @@ -119,7 +119,7 @@ export default function useSetting( path ) {
return (
experimentalFeaturesResult.user ??
experimentalFeaturesResult.theme ??
experimentalFeaturesResult.core
experimentalFeaturesResult.default
);
}
return experimentalFeaturesResult;
Expand Down
Expand Up @@ -23,7 +23,7 @@ export const GLOBAL_STYLES_PALETTE = [
];

export const GLOBAL_STYLES_GRADIENTS = {
core: [
default: [
{
name: 'Vivid cyan blue to vivid purple',
gradient:
Expand Down Expand Up @@ -138,7 +138,7 @@ export const PARSED_GLOBAL_STYLES = {
export const RAW_FEATURES = {
color: {
palette: {
core: [
default: [
{
name: 'Black',
slug: 'black',
Expand Down Expand Up @@ -174,7 +174,7 @@ export const RAW_FEATURES = {
],
},
gradients: {
core: [
default: [
{
name: 'Vivid cyan blue to vivid purple',
gradient:
Expand Down Expand Up @@ -204,7 +204,7 @@ export const RAW_FEATURES = {
},
typography: {
fontSizes: {
core: [
default: [
{
name: 'Small',
slug: 'small',
Expand Down
Expand Up @@ -265,7 +265,7 @@ function normalizeFontSizes( fontSizes ) {
const normalizedFontSizes = {};
const dimensions = Dimensions.get( 'window' );

[ 'core', 'theme', 'user' ].forEach( ( key ) => {
[ 'default', 'theme', 'user' ].forEach( ( key ) => {
if ( fontSizes[ key ] ) {
normalizedFontSizes[ key ] = fontSizes[ key ]?.map(
( fontSizeObject ) => {
Expand Down
6 changes: 3 additions & 3 deletions packages/edit-site/src/components/global-styles/hooks.js
Expand Up @@ -65,7 +65,7 @@ export function useSetting( path, blockName, source = 'all' ) {
const getSettingValue = ( configToUse ) => {
const result = get( configToUse, currentPath );
if ( PATHS_WITH_MERGE[ path ] ) {
return result?.user ?? result?.theme ?? result?.core;
return result?.user ?? result?.theme ?? result?.default;
}
return result;
};
Expand Down Expand Up @@ -220,7 +220,7 @@ export function getSupportedGlobalStylesPanels( name ) {
export function useColorsPerOrigin( name ) {
const [ customColors ] = useSetting( 'color.palette.user', name );
const [ themeColors ] = useSetting( 'color.palette.theme', name );
const [ defaultColors ] = useSetting( 'color.palette.core', name );
const [ defaultColors ] = useSetting( 'color.palette.default', name );
const [ shouldDisplayDefaultColors ] = useSetting( 'color.defaultPalette' );

return useMemo( () => {
Expand Down Expand Up @@ -263,7 +263,7 @@ export function useColorsPerOrigin( name ) {
export function useGradientsPerOrigin( name ) {
const [ customGradients ] = useSetting( 'color.gradients.user', name );
const [ themeGradients ] = useSetting( 'color.gradients.theme', name );
const [ defaultGradients ] = useSetting( 'color.gradients.core', name );
const [ defaultGradients ] = useSetting( 'color.gradients.default', name );
const [ shouldDisplayDefaultGradients ] = useSetting(
'color.defaultGradients'
);
Expand Down
Expand Up @@ -268,7 +268,7 @@ describe( 'global styles renderer', () => {
settings: {
color: {
palette: {
core: [
default: [
{
name: 'White',
slug: 'white',
Expand All @@ -286,7 +286,7 @@ describe( 'global styles renderer', () => {
'core/heading': {
color: {
palette: {
core: [
default: [
{
name: 'Blue',
slug: 'blue',
Expand Down
Expand Up @@ -60,7 +60,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
PRESET_METADATA,
( declarations, { path, valueKey, cssVarInfix } ) => {
const presetByOrigin = get( blockPresets, path, [] );
[ 'core', 'theme', 'user' ].forEach( ( origin ) => {
[ 'default', 'theme', 'user' ].forEach( ( origin ) => {
if ( presetByOrigin[ origin ] ) {
presetByOrigin[ origin ].forEach( ( value ) => {
declarations.push(
Expand Down Expand Up @@ -94,7 +94,7 @@ function getPresetsClasses( blockSelector, blockPresets = {} ) {
}

const presetByOrigin = get( blockPresets, path, [] );
[ 'core', 'theme', 'user' ].forEach( ( origin ) => {
[ 'default', 'theme', 'user' ].forEach( ( origin ) => {
if ( presetByOrigin[ origin ] ) {
presetByOrigin[ origin ].forEach( ( { slug } ) => {
classes.forEach( ( { classSuffix, propertyName } ) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/edit-site/src/components/global-styles/utils.js
Expand Up @@ -90,7 +90,7 @@ function findInPresetsBy(
for ( const presetByOrigin of orderedPresetsByOrigin ) {
if ( presetByOrigin ) {
// Preset origins ordered by priority.
const origins = [ 'user', 'theme', 'core' ];
const origins = [ 'user', 'theme', 'default' ];
for ( const origin of origins ) {
const presets = presetByOrigin[ origin ];
if ( presets ) {
Expand Down
18 changes: 9 additions & 9 deletions phpunit/class-wp-theme-json-test.php
Expand Up @@ -64,7 +64,7 @@ function test_get_settings() {
}

function test_get_settings_presets_are_keyed_by_origin() {
$core_origin = new WP_Theme_JSON_Gutenberg(
$default_origin = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
Expand All @@ -91,9 +91,9 @@ function test_get_settings_presets_are_keyed_by_origin() {
),
),
),
'core'
'default'
);
$no_origin = new WP_Theme_JSON_Gutenberg(
$no_origin = new WP_Theme_JSON_Gutenberg(
array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
Expand Down Expand Up @@ -122,15 +122,15 @@ function test_get_settings_presets_are_keyed_by_origin() {
)
);

$actual_core = $core_origin->get_raw_data();
$actual_default = $default_origin->get_raw_data();
$actual_no_origin = $no_origin->get_raw_data();

$expected_core = array(
$expected_default = array(
'version' => WP_Theme_JSON_Gutenberg::LATEST_SCHEMA,
'settings' => array(
'color' => array(
'palette' => array(
'core' => array(
'default' => array(
array(
'slug' => 'white',
'color' => 'white',
Expand All @@ -142,7 +142,7 @@ function test_get_settings_presets_are_keyed_by_origin() {
'core/group' => array(
'color' => array(
'palette' => array(
'core' => array(
'default' => array(
array(
'slug' => 'white',
'color' => 'white',
Expand Down Expand Up @@ -184,7 +184,7 @@ function test_get_settings_presets_are_keyed_by_origin() {
),
);

$this->assertEqualSetsWithIndex( $expected_core, $actual_core );
$this->assertEqualSetsWithIndex( $expected_default, $actual_default );
$this->assertEqualSetsWithIndex( $expected_no_origin, $actual_no_origin );
}

Expand Down Expand Up @@ -553,7 +553,7 @@ public function test_get_stylesheet_preset_values_are_marked_as_important() {
),
),
),
'core'
'default'
);

$this->assertEquals(
Expand Down

0 comments on commit 914c9c9

Please sign in to comment.