|
2 | 2 | * External dependencies
|
3 | 3 | */
|
4 | 4 | // eslint-disable-next-line import/no-extraneous-dependencies
|
5 |
| -import { kebabCase } from 'lodash'; |
| 5 | +import { get, kebabCase, reduce } from 'lodash'; |
6 | 6 | /**
|
7 | 7 | * WordPress dependencies
|
8 | 8 | */
|
@@ -62,35 +62,27 @@ const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
|
62 | 62 | * @return {Array<Object>} An array of style declarations.
|
63 | 63 | */
|
64 | 64 | function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
|
65 |
| - return PRESET_METADATA.reduce( |
| 65 | + return reduce( |
| 66 | + PRESET_METADATA, |
66 | 67 | ( 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 | + } |
94 | 86 |
|
95 | 87 | return declarations;
|
96 | 88 | },
|
|
0 commit comments