Skip to content

Commit 1d8e971

Browse files
committed
Update use-global-styles-output.js
1 parent b089f25 commit 1d8e971

File tree

1 file changed

+21
-29
lines changed

1 file changed

+21
-29
lines changed

src/OnboardingSPA/utils/global-styles/use-global-styles-output.js

Lines changed: 21 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* External dependencies
33
*/
44
// eslint-disable-next-line import/no-extraneous-dependencies
5-
import { kebabCase } from 'lodash';
5+
import { get, kebabCase, reduce } from 'lodash';
66
/**
77
* WordPress dependencies
88
*/
@@ -62,35 +62,27 @@ const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
6262
* @return {Array<Object>} An array of style declarations.
6363
*/
6464
function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
65-
return PRESET_METADATA.reduce(
65+
return reduce(
66+
PRESET_METADATA,
6667
( declarations, { path, valueKey, valueFunc, cssVarInfix } ) => {
67-
const presetByOrigin = getValueFromObjectPath(
68-
blockPresets,
69-
path,
70-
[]
71-
);
72-
[ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
73-
if ( presetByOrigin[ origin ] ) {
74-
presetByOrigin[ origin ].forEach( ( value ) => {
75-
if ( valueKey && ! valueFunc ) {
76-
declarations.push(
77-
`--wp--preset--${ cssVarInfix }--${ kebabCase(
78-
value.slug
79-
) }: ${ value[ valueKey ] }`
80-
);
81-
} else if (
82-
valueFunc &&
83-
typeof valueFunc === 'function'
84-
) {
85-
declarations.push(
86-
`--wp--preset--${ cssVarInfix }--${ kebabCase(
87-
value.slug
88-
) }: ${ valueFunc( value, mergedSettings ) }`
89-
);
90-
}
91-
} );
92-
}
93-
} );
68+
const presetByOrigin = get( blockPresets, path, [] );
69+
if ( presetByOrigin && Array.isArray( presetByOrigin ) ) {
70+
presetByOrigin.forEach( ( value ) => {
71+
if ( valueKey && ! valueFunc ) {
72+
declarations.push(
73+
`--wp--preset--${ cssVarInfix }--${ kebabCase(
74+
value.slug
75+
) }: ${ value[ valueKey ] }`
76+
);
77+
} else if ( valueFunc && typeof valueFunc === 'function' ) {
78+
declarations.push(
79+
`--wp--preset--${ cssVarInfix }--${ kebabCase(
80+
value.slug
81+
) }: ${ valueFunc( value, mergedSettings ) }`
82+
);
83+
}
84+
} );
85+
}
9486

9587
return declarations;
9688
},

0 commit comments

Comments
 (0)