@wordpress/block-editor 13.0.4 → 13.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/components/global-styles/use-global-styles-output.js +8 -8
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/hooks/block-style-variation.js +63 -4
- package/build/hooks/block-style-variation.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +8 -8
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/hooks/block-style-variation.js +62 -4
- package/build-module/hooks/block-style-variation.js.map +1 -1
- package/package.json +2 -2
- package/src/components/global-styles/use-global-styles-output.js +8 -8
- package/src/hooks/block-style-variation.js +80 -3
- package/src/hooks/test/get-variation-styles-with-ref-values.js +91 -0
|
@@ -10,6 +10,7 @@ import { useContext, useMemo } from '@wordpress/element';
|
|
|
10
10
|
*/
|
|
11
11
|
import { GlobalStylesContext, toStyles, getBlockSelectors } from '../components/global-styles';
|
|
12
12
|
import { useStyleOverride } from './utils';
|
|
13
|
+
import { getValueFromObjectPath } from '../utils/object';
|
|
13
14
|
import { store as blockEditorStore } from '../store';
|
|
14
15
|
import { globalStylesDataKey } from '../store/private-keys';
|
|
15
16
|
import { unlock } from '../lock-unlock';
|
|
@@ -155,6 +156,61 @@ export function __unstableBlockStyleVariationOverridesWithConfig({
|
|
|
155
156
|
}, override.id))
|
|
156
157
|
});
|
|
157
158
|
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Retrieves any variation styles data and resolves any referenced values.
|
|
162
|
+
*
|
|
163
|
+
* @param {Object} globalStyles A complete global styles object, containing settings and styles.
|
|
164
|
+
* @param {string} name The name of the desired block type.
|
|
165
|
+
* @param {variation} variation The of the block style variation to retrieve data for.
|
|
166
|
+
*
|
|
167
|
+
* @return {Object|undefined} The global styles data for the specified variation.
|
|
168
|
+
*/
|
|
169
|
+
export function getVariationStylesWithRefValues(globalStyles, name, variation) {
|
|
170
|
+
if (!globalStyles?.styles?.blocks?.[name]?.variations?.[variation]) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Helper to recursively look for `ref` values to resolve.
|
|
175
|
+
const replaceRefs = variationStyles => {
|
|
176
|
+
Object.keys(variationStyles).forEach(key => {
|
|
177
|
+
const value = variationStyles[key];
|
|
178
|
+
|
|
179
|
+
// Only process objects.
|
|
180
|
+
if (typeof value === 'object' && value !== null) {
|
|
181
|
+
// Process `ref` value if present.
|
|
182
|
+
if (value.ref !== undefined) {
|
|
183
|
+
if (typeof value.ref !== 'string' || value.ref.trim() === '') {
|
|
184
|
+
// Remove invalid ref.
|
|
185
|
+
delete variationStyles[key];
|
|
186
|
+
} else {
|
|
187
|
+
// Resolve `ref` value.
|
|
188
|
+
const refValue = getValueFromObjectPath(globalStyles, value.ref);
|
|
189
|
+
if (refValue) {
|
|
190
|
+
variationStyles[key] = refValue;
|
|
191
|
+
} else {
|
|
192
|
+
delete variationStyles[key];
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
} else {
|
|
196
|
+
// Recursively resolve `ref` values in nested objects.
|
|
197
|
+
replaceRefs(value);
|
|
198
|
+
|
|
199
|
+
// After recursion, if value is empty due to explicitly
|
|
200
|
+
// `undefined` ref value, remove it.
|
|
201
|
+
if (Object.keys(value).length === 0) {
|
|
202
|
+
delete variationStyles[key];
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
// Deep clone variation node to avoid mutating it within global styles and losing refs.
|
|
210
|
+
const styles = JSON.parse(JSON.stringify(globalStyles.styles.blocks[name].variations[variation]));
|
|
211
|
+
replaceRefs(styles);
|
|
212
|
+
return styles;
|
|
213
|
+
}
|
|
158
214
|
function useBlockStyleVariation(name, variation, clientId) {
|
|
159
215
|
// Prefer global styles data in GlobalStylesContext, which are available
|
|
160
216
|
// if in the site editor. Otherwise fall back to whatever is in the
|
|
@@ -173,11 +229,13 @@ function useBlockStyleVariation(name, variation, clientId) {
|
|
|
173
229
|
};
|
|
174
230
|
}, []);
|
|
175
231
|
return useMemo(() => {
|
|
176
|
-
var _mergedConfig$styles, _mergedConfig$
|
|
177
|
-
const
|
|
178
|
-
const variationStyles = styles?.blocks?.[name]?.variations?.[variation];
|
|
179
|
-
return {
|
|
232
|
+
var _mergedConfig$setting, _mergedConfig$styles, _mergedConfig$setting2;
|
|
233
|
+
const variationStyles = getVariationStylesWithRefValues({
|
|
180
234
|
settings: (_mergedConfig$setting = mergedConfig?.settings) !== null && _mergedConfig$setting !== void 0 ? _mergedConfig$setting : globalSettings,
|
|
235
|
+
styles: (_mergedConfig$styles = mergedConfig?.styles) !== null && _mergedConfig$styles !== void 0 ? _mergedConfig$styles : globalStyles
|
|
236
|
+
}, name, variation);
|
|
237
|
+
return {
|
|
238
|
+
settings: (_mergedConfig$setting2 = mergedConfig?.settings) !== null && _mergedConfig$setting2 !== void 0 ? _mergedConfig$setting2 : globalSettings,
|
|
181
239
|
// The variation style data is all that is needed to generate
|
|
182
240
|
// the styles for the current application to a block. The variation
|
|
183
241
|
// name is updated to match the instance specific class name.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["getBlockTypes","store","blocksStore","useSelect","useContext","useMemo","GlobalStylesContext","toStyles","getBlockSelectors","useStyleOverride","blockEditorStore","globalStylesDataKey","unlock","jsx","_jsx","Fragment","_Fragment","VARIATION_PREFIX","getVariationMatches","className","split","reduce","matches","name","startsWith","match","slice","length","push","getVariationNameFromClass","registeredStyles","variation","some","style","OverrideStyles","override","__unstableBlockStyleVariationOverridesWithConfig","config","getBlockStyles","overrides","select","getStyleOverrides","getBlockName","overridesWithConfig","newOverrides","overriddenClientIds","clientId","includes","blockName","configStyles","styles","blocks","variations","variationConfig","settings","blockSelectors","hasBlockGapSupport","hasFallbackGapSupport","disableLayoutStyles","disableRootPadding","variationStyles","blockGap","blockStyles","layoutStyles","marginReset","presets","rootPadding","id","css","__unstableType","children","map","useBlockStyleVariation","merged","mergedConfig","globalSettings","globalStyles","getSettings","__experimentalFeatures","_mergedConfig$styles","_mergedConfig$setting","useBlockProps","variationClass","hasSupport","attributeKeys","isMatch"],"sources":["@wordpress/block-editor/src/hooks/block-style-variation.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockTypes, store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tGlobalStylesContext,\n\ttoStyles,\n\tgetBlockSelectors,\n} from '../components/global-styles';\nimport { useStyleOverride } from './utils';\nimport { store as blockEditorStore } from '../store';\nimport { globalStylesDataKey } from '../store/private-keys';\nimport { unlock } from '../lock-unlock';\n\nconst VARIATION_PREFIX = 'is-style-';\n\nfunction getVariationMatches( className ) {\n\tif ( ! className ) {\n\t\treturn [];\n\t}\n\treturn className.split( /\\s+/ ).reduce( ( matches, name ) => {\n\t\tif ( name.startsWith( VARIATION_PREFIX ) ) {\n\t\t\tconst match = name.slice( VARIATION_PREFIX.length );\n\t\t\tif ( match !== 'default' ) {\n\t\t\t\tmatches.push( match );\n\t\t\t}\n\t\t}\n\t\treturn matches;\n\t}, [] );\n}\n\n/**\n * Get the first block style variation that has been registered from the class string.\n *\n * @param {string} className CSS class string for a block.\n * @param {Array} registeredStyles Currently registered block styles.\n *\n * @return {string|null} The name of the first registered variation.\n */\nfunction getVariationNameFromClass( className, registeredStyles = [] ) {\n\t// The global flag affects how capturing groups work in JS. So the regex\n\t// below will only return full CSS classes not just the variation name.\n\tconst matches = getVariationMatches( className );\n\n\tif ( ! matches ) {\n\t\treturn null;\n\t}\n\n\tfor ( const variation of matches ) {\n\t\tif ( registeredStyles.some( ( style ) => style.name === variation ) ) {\n\t\t\treturn variation;\n\t\t}\n\t}\n\treturn null;\n}\n\n// A helper component to apply a style override using the useStyleOverride hook.\nfunction OverrideStyles( { override } ) {\n\tuseStyleOverride( override );\n}\n\n/**\n * This component is used to generate new block style variation overrides\n * based on an incoming theme config. If a matching style is found in the config,\n * a new override is created and returned. The overrides can be used in conjunction with\n * useStyleOverride to apply the new styles to the editor. Its use is\n * subject to change.\n *\n * @param {Object} props Props.\n * @param {Object} props.config A global styles object, containing settings and styles.\n * @return {JSX.Element|undefined} An array of new block variation overrides.\n */\nexport function __unstableBlockStyleVariationOverridesWithConfig( { config } ) {\n\tconst { getBlockStyles, overrides } = useSelect(\n\t\t( select ) => ( {\n\t\t\tgetBlockStyles: select( blocksStore ).getBlockStyles,\n\t\t\toverrides: unlock( select( blockEditorStore ) ).getStyleOverrides(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst { getBlockName } = useSelect( blockEditorStore );\n\n\tconst overridesWithConfig = useMemo( () => {\n\t\tif ( ! overrides?.length ) {\n\t\t\treturn;\n\t\t}\n\t\tconst newOverrides = [];\n\t\tconst overriddenClientIds = [];\n\t\tfor ( const [ , override ] of overrides ) {\n\t\t\tif (\n\t\t\t\toverride?.variation &&\n\t\t\t\toverride?.clientId &&\n\t\t\t\t/*\n\t\t\t\t * Because this component overwrites existing style overrides,\n\t\t\t\t * filter out any overrides that are already present in the store.\n\t\t\t\t */\n\t\t\t\t! overriddenClientIds.includes( override.clientId )\n\t\t\t) {\n\t\t\t\tconst blockName = getBlockName( override.clientId );\n\t\t\t\tconst configStyles =\n\t\t\t\t\tconfig?.styles?.blocks?.[ blockName ]?.variations?.[\n\t\t\t\t\t\toverride.variation\n\t\t\t\t\t];\n\t\t\t\tif ( configStyles ) {\n\t\t\t\t\tconst variationConfig = {\n\t\t\t\t\t\tsettings: config?.settings,\n\t\t\t\t\t\t// The variation style data is all that is needed to generate\n\t\t\t\t\t\t// the styles for the current application to a block. The variation\n\t\t\t\t\t\t// name is updated to match the instance specific class name.\n\t\t\t\t\t\tstyles: {\n\t\t\t\t\t\t\tblocks: {\n\t\t\t\t\t\t\t\t[ blockName ]: {\n\t\t\t\t\t\t\t\t\tvariations: {\n\t\t\t\t\t\t\t\t\t\t[ `${ override.variation }-${ override.clientId }` ]:\n\t\t\t\t\t\t\t\t\t\t\tconfigStyles,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tconst blockSelectors = getBlockSelectors(\n\t\t\t\t\t\tgetBlockTypes(),\n\t\t\t\t\t\tgetBlockStyles,\n\t\t\t\t\t\toverride.clientId\n\t\t\t\t\t);\n\t\t\t\t\tconst hasBlockGapSupport = false;\n\t\t\t\t\tconst hasFallbackGapSupport = true;\n\t\t\t\t\tconst disableLayoutStyles = true;\n\t\t\t\t\tconst disableRootPadding = true;\n\t\t\t\t\tconst variationStyles = toStyles(\n\t\t\t\t\t\tvariationConfig,\n\t\t\t\t\t\tblockSelectors,\n\t\t\t\t\t\thasBlockGapSupport,\n\t\t\t\t\t\thasFallbackGapSupport,\n\t\t\t\t\t\tdisableLayoutStyles,\n\t\t\t\t\t\tdisableRootPadding,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tblockGap: false,\n\t\t\t\t\t\t\tblockStyles: true,\n\t\t\t\t\t\t\tlayoutStyles: false,\n\t\t\t\t\t\t\tmarginReset: false,\n\t\t\t\t\t\t\tpresets: false,\n\t\t\t\t\t\t\trootPadding: false,\n\t\t\t\t\t\t\tvariationStyles: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tnewOverrides.push( {\n\t\t\t\t\t\tid: `${ override.variation }-${ override.clientId }`,\n\t\t\t\t\t\tcss: variationStyles,\n\t\t\t\t\t\t__unstableType: 'variation',\n\t\t\t\t\t\tvariation: override.variation,\n\t\t\t\t\t\t// The clientId will be stored with the override and used to ensure\n\t\t\t\t\t\t// the order of overrides matches the order of blocks so that the\n\t\t\t\t\t\t// correct CSS cascade is maintained.\n\t\t\t\t\t\tclientId: override.clientId,\n\t\t\t\t\t} );\n\t\t\t\t\toverriddenClientIds.push( override.clientId );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn newOverrides;\n\t}, [ config, overrides, getBlockStyles, getBlockName ] );\n\n\tif ( ! overridesWithConfig || ! overridesWithConfig.length ) {\n\t\treturn;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ overridesWithConfig.map( ( override ) => (\n\t\t\t\t<OverrideStyles key={ override.id } override={ override } />\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\nfunction useBlockStyleVariation( name, variation, clientId ) {\n\t// Prefer global styles data in GlobalStylesContext, which are available\n\t// if in the site editor. Otherwise fall back to whatever is in the\n\t// editor settings and available in the post editor.\n\tconst { merged: mergedConfig } = useContext( GlobalStylesContext );\n\tconst { globalSettings, globalStyles } = useSelect( ( select ) => {\n\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tglobalSettings: settings.__experimentalFeatures,\n\t\t\tglobalStyles: settings[ globalStylesDataKey ],\n\t\t};\n\t}, [] );\n\n\treturn useMemo( () => {\n\t\tconst styles = mergedConfig?.styles ?? globalStyles;\n\t\tconst variationStyles =\n\t\t\tstyles?.blocks?.[ name ]?.variations?.[ variation ];\n\n\t\treturn {\n\t\t\tsettings: mergedConfig?.settings ?? globalSettings,\n\t\t\t// The variation style data is all that is needed to generate\n\t\t\t// the styles for the current application to a block. The variation\n\t\t\t// name is updated to match the instance specific class name.\n\t\t\tstyles: {\n\t\t\t\tblocks: {\n\t\t\t\t\t[ name ]: {\n\t\t\t\t\t\tvariations: {\n\t\t\t\t\t\t\t[ `${ variation }-${ clientId }` ]: variationStyles,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}, [\n\t\tmergedConfig,\n\t\tglobalSettings,\n\t\tglobalStyles,\n\t\tvariation,\n\t\tclientId,\n\t\tname,\n\t] );\n}\n\n// Rather than leveraging `useInstanceId` here, the `clientId` is used.\n// This is so that the variation style override's ID is predictable\n// when the order of applied style variations changes.\nfunction useBlockProps( { name, className, clientId } ) {\n\tconst { getBlockStyles } = useSelect( blocksStore );\n\n\tconst registeredStyles = getBlockStyles( name );\n\tconst variation = getVariationNameFromClass( className, registeredStyles );\n\tconst variationClass = `${ VARIATION_PREFIX }${ variation }-${ clientId }`;\n\n\tconst { settings, styles } = useBlockStyleVariation(\n\t\tname,\n\t\tvariation,\n\t\tclientId\n\t);\n\n\tconst variationStyles = useMemo( () => {\n\t\tif ( ! variation ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst variationConfig = { settings, styles };\n\t\tconst blockSelectors = getBlockSelectors(\n\t\t\tgetBlockTypes(),\n\t\t\tgetBlockStyles,\n\t\t\tclientId\n\t\t);\n\t\tconst hasBlockGapSupport = false;\n\t\tconst hasFallbackGapSupport = true;\n\t\tconst disableLayoutStyles = true;\n\t\tconst disableRootPadding = true;\n\n\t\treturn toStyles(\n\t\t\tvariationConfig,\n\t\t\tblockSelectors,\n\t\t\thasBlockGapSupport,\n\t\t\thasFallbackGapSupport,\n\t\t\tdisableLayoutStyles,\n\t\t\tdisableRootPadding,\n\t\t\t{\n\t\t\t\tblockGap: false,\n\t\t\t\tblockStyles: true,\n\t\t\t\tlayoutStyles: false,\n\t\t\t\tmarginReset: false,\n\t\t\t\tpresets: false,\n\t\t\t\trootPadding: false,\n\t\t\t\tvariationStyles: true,\n\t\t\t}\n\t\t);\n\t}, [ variation, settings, styles, getBlockStyles, clientId ] );\n\n\tuseStyleOverride( {\n\t\tid: `variation-${ clientId }`,\n\t\tcss: variationStyles,\n\t\t__unstableType: 'variation',\n\t\tvariation,\n\t\t// The clientId will be stored with the override and used to ensure\n\t\t// the order of overrides matches the order of blocks so that the\n\t\t// correct CSS cascade is maintained.\n\t\tclientId,\n\t} );\n\n\treturn variation ? { className: variationClass } : {};\n}\n\nexport default {\n\thasSupport: () => true,\n\tattributeKeys: [ 'className' ],\n\tisMatch: ( { className } ) => getVariationMatches( className ).length > 0,\n\tuseBlockProps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B,OAAOpD,QAAQ,CACd8C,eAAe,EACfE,cAAc,EACdC,kBAAkB,EAClBC,qBAAqB,EACrBC,mBAAmB,EACnBC,kBAAkB,EAClB;MACCE,QAAQ,EAAE,KAAK;MACfC,WAAW,EAAE,IAAI;MACjBC,YAAY,EAAE,KAAK;MACnBC,WAAW,EAAE,KAAK;MAClBC,OAAO,EAAE,KAAK;MACdC,WAAW,EAAE,KAAK;MAClBN,eAAe,EAAE;IAClB,CACD,CAAC;EACF,CAAC,EAAE,CAAE7B,SAAS,EAAEuB,QAAQ,EAAEJ,MAAM,EAAEZ,cAAc,EAAEQ,QAAQ,CAAG,CAAC;EAE9DrC,gBAAgB,CAAE;IACjB0D,EAAE,EAAG,aAAarB,QAAU,EAAC;IAC7BsB,GAAG,EAAER,eAAe;IACpBS,cAAc,EAAE,WAAW;IAC3BtC,SAAS;IACT;IACA;IACA;IACAe;EACD,CAAE,CAAC;EAEH,OAAOf,SAAS,GAAG;IAAEZ,SAAS,EAAE+D;EAAe,CAAC,GAAG,CAAC,CAAC;AACtD;AAEA,eAAe;EACdC,UAAU,EAAEA,CAAA,KAAM,IAAI;EACtBC,aAAa,EAAE,CAAE,WAAW,CAAE;EAC9BC,OAAO,EAAEA,CAAE;IAAElE;EAAU,CAAC,KAAMD,mBAAmB,CAAEC,SAAU,CAAC,CAACQ,MAAM,GAAG,CAAC;EACzEsD;AACD,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["getBlockTypes","store","blocksStore","useSelect","useContext","useMemo","GlobalStylesContext","toStyles","getBlockSelectors","useStyleOverride","getValueFromObjectPath","blockEditorStore","globalStylesDataKey","unlock","jsx","_jsx","Fragment","_Fragment","VARIATION_PREFIX","getVariationMatches","className","split","reduce","matches","name","startsWith","match","slice","length","push","getVariationNameFromClass","registeredStyles","variation","some","style","OverrideStyles","override","__unstableBlockStyleVariationOverridesWithConfig","config","getBlockStyles","overrides","select","getStyleOverrides","getBlockName","overridesWithConfig","newOverrides","overriddenClientIds","clientId","includes","blockName","configStyles","styles","blocks","variations","variationConfig","settings","blockSelectors","hasBlockGapSupport","hasFallbackGapSupport","disableLayoutStyles","disableRootPadding","variationStyles","blockGap","blockStyles","layoutStyles","marginReset","presets","rootPadding","id","css","__unstableType","children","map","getVariationStylesWithRefValues","globalStyles","replaceRefs","Object","keys","forEach","key","value","ref","undefined","trim","refValue","JSON","parse","stringify","useBlockStyleVariation","merged","mergedConfig","globalSettings","getSettings","__experimentalFeatures","_mergedConfig$setting","_mergedConfig$styles","_mergedConfig$setting2","useBlockProps","variationClass","hasSupport","attributeKeys","isMatch"],"sources":["@wordpress/block-editor/src/hooks/block-style-variation.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { getBlockTypes, store as blocksStore } from '@wordpress/blocks';\nimport { useSelect } from '@wordpress/data';\nimport { useContext, useMemo } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tGlobalStylesContext,\n\ttoStyles,\n\tgetBlockSelectors,\n} from '../components/global-styles';\nimport { useStyleOverride } from './utils';\nimport { getValueFromObjectPath } from '../utils/object';\nimport { store as blockEditorStore } from '../store';\nimport { globalStylesDataKey } from '../store/private-keys';\nimport { unlock } from '../lock-unlock';\n\nconst VARIATION_PREFIX = 'is-style-';\n\nfunction getVariationMatches( className ) {\n\tif ( ! className ) {\n\t\treturn [];\n\t}\n\treturn className.split( /\\s+/ ).reduce( ( matches, name ) => {\n\t\tif ( name.startsWith( VARIATION_PREFIX ) ) {\n\t\t\tconst match = name.slice( VARIATION_PREFIX.length );\n\t\t\tif ( match !== 'default' ) {\n\t\t\t\tmatches.push( match );\n\t\t\t}\n\t\t}\n\t\treturn matches;\n\t}, [] );\n}\n\n/**\n * Get the first block style variation that has been registered from the class string.\n *\n * @param {string} className CSS class string for a block.\n * @param {Array} registeredStyles Currently registered block styles.\n *\n * @return {string|null} The name of the first registered variation.\n */\nfunction getVariationNameFromClass( className, registeredStyles = [] ) {\n\t// The global flag affects how capturing groups work in JS. So the regex\n\t// below will only return full CSS classes not just the variation name.\n\tconst matches = getVariationMatches( className );\n\n\tif ( ! matches ) {\n\t\treturn null;\n\t}\n\n\tfor ( const variation of matches ) {\n\t\tif ( registeredStyles.some( ( style ) => style.name === variation ) ) {\n\t\t\treturn variation;\n\t\t}\n\t}\n\treturn null;\n}\n\n// A helper component to apply a style override using the useStyleOverride hook.\nfunction OverrideStyles( { override } ) {\n\tuseStyleOverride( override );\n}\n\n/**\n * This component is used to generate new block style variation overrides\n * based on an incoming theme config. If a matching style is found in the config,\n * a new override is created and returned. The overrides can be used in conjunction with\n * useStyleOverride to apply the new styles to the editor. Its use is\n * subject to change.\n *\n * @param {Object} props Props.\n * @param {Object} props.config A global styles object, containing settings and styles.\n * @return {JSX.Element|undefined} An array of new block variation overrides.\n */\nexport function __unstableBlockStyleVariationOverridesWithConfig( { config } ) {\n\tconst { getBlockStyles, overrides } = useSelect(\n\t\t( select ) => ( {\n\t\t\tgetBlockStyles: select( blocksStore ).getBlockStyles,\n\t\t\toverrides: unlock( select( blockEditorStore ) ).getStyleOverrides(),\n\t\t} ),\n\t\t[]\n\t);\n\tconst { getBlockName } = useSelect( blockEditorStore );\n\n\tconst overridesWithConfig = useMemo( () => {\n\t\tif ( ! overrides?.length ) {\n\t\t\treturn;\n\t\t}\n\t\tconst newOverrides = [];\n\t\tconst overriddenClientIds = [];\n\t\tfor ( const [ , override ] of overrides ) {\n\t\t\tif (\n\t\t\t\toverride?.variation &&\n\t\t\t\toverride?.clientId &&\n\t\t\t\t/*\n\t\t\t\t * Because this component overwrites existing style overrides,\n\t\t\t\t * filter out any overrides that are already present in the store.\n\t\t\t\t */\n\t\t\t\t! overriddenClientIds.includes( override.clientId )\n\t\t\t) {\n\t\t\t\tconst blockName = getBlockName( override.clientId );\n\t\t\t\tconst configStyles =\n\t\t\t\t\tconfig?.styles?.blocks?.[ blockName ]?.variations?.[\n\t\t\t\t\t\toverride.variation\n\t\t\t\t\t];\n\t\t\t\tif ( configStyles ) {\n\t\t\t\t\tconst variationConfig = {\n\t\t\t\t\t\tsettings: config?.settings,\n\t\t\t\t\t\t// The variation style data is all that is needed to generate\n\t\t\t\t\t\t// the styles for the current application to a block. The variation\n\t\t\t\t\t\t// name is updated to match the instance specific class name.\n\t\t\t\t\t\tstyles: {\n\t\t\t\t\t\t\tblocks: {\n\t\t\t\t\t\t\t\t[ blockName ]: {\n\t\t\t\t\t\t\t\t\tvariations: {\n\t\t\t\t\t\t\t\t\t\t[ `${ override.variation }-${ override.clientId }` ]:\n\t\t\t\t\t\t\t\t\t\t\tconfigStyles,\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t},\n\t\t\t\t\t};\n\t\t\t\t\tconst blockSelectors = getBlockSelectors(\n\t\t\t\t\t\tgetBlockTypes(),\n\t\t\t\t\t\tgetBlockStyles,\n\t\t\t\t\t\toverride.clientId\n\t\t\t\t\t);\n\t\t\t\t\tconst hasBlockGapSupport = false;\n\t\t\t\t\tconst hasFallbackGapSupport = true;\n\t\t\t\t\tconst disableLayoutStyles = true;\n\t\t\t\t\tconst disableRootPadding = true;\n\t\t\t\t\tconst variationStyles = toStyles(\n\t\t\t\t\t\tvariationConfig,\n\t\t\t\t\t\tblockSelectors,\n\t\t\t\t\t\thasBlockGapSupport,\n\t\t\t\t\t\thasFallbackGapSupport,\n\t\t\t\t\t\tdisableLayoutStyles,\n\t\t\t\t\t\tdisableRootPadding,\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tblockGap: false,\n\t\t\t\t\t\t\tblockStyles: true,\n\t\t\t\t\t\t\tlayoutStyles: false,\n\t\t\t\t\t\t\tmarginReset: false,\n\t\t\t\t\t\t\tpresets: false,\n\t\t\t\t\t\t\trootPadding: false,\n\t\t\t\t\t\t\tvariationStyles: true,\n\t\t\t\t\t\t}\n\t\t\t\t\t);\n\t\t\t\t\tnewOverrides.push( {\n\t\t\t\t\t\tid: `${ override.variation }-${ override.clientId }`,\n\t\t\t\t\t\tcss: variationStyles,\n\t\t\t\t\t\t__unstableType: 'variation',\n\t\t\t\t\t\tvariation: override.variation,\n\t\t\t\t\t\t// The clientId will be stored with the override and used to ensure\n\t\t\t\t\t\t// the order of overrides matches the order of blocks so that the\n\t\t\t\t\t\t// correct CSS cascade is maintained.\n\t\t\t\t\t\tclientId: override.clientId,\n\t\t\t\t\t} );\n\t\t\t\t\toverriddenClientIds.push( override.clientId );\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn newOverrides;\n\t}, [ config, overrides, getBlockStyles, getBlockName ] );\n\n\tif ( ! overridesWithConfig || ! overridesWithConfig.length ) {\n\t\treturn;\n\t}\n\n\treturn (\n\t\t<>\n\t\t\t{ overridesWithConfig.map( ( override ) => (\n\t\t\t\t<OverrideStyles key={ override.id } override={ override } />\n\t\t\t) ) }\n\t\t</>\n\t);\n}\n\n/**\n * Retrieves any variation styles data and resolves any referenced values.\n *\n * @param {Object} globalStyles A complete global styles object, containing settings and styles.\n * @param {string} name The name of the desired block type.\n * @param {variation} variation The of the block style variation to retrieve data for.\n *\n * @return {Object|undefined} The global styles data for the specified variation.\n */\nexport function getVariationStylesWithRefValues(\n\tglobalStyles,\n\tname,\n\tvariation\n) {\n\tif ( ! globalStyles?.styles?.blocks?.[ name ]?.variations?.[ variation ] ) {\n\t\treturn;\n\t}\n\n\t// Helper to recursively look for `ref` values to resolve.\n\tconst replaceRefs = ( variationStyles ) => {\n\t\tObject.keys( variationStyles ).forEach( ( key ) => {\n\t\t\tconst value = variationStyles[ key ];\n\n\t\t\t// Only process objects.\n\t\t\tif ( typeof value === 'object' && value !== null ) {\n\t\t\t\t// Process `ref` value if present.\n\t\t\t\tif ( value.ref !== undefined ) {\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof value.ref !== 'string' ||\n\t\t\t\t\t\tvalue.ref.trim() === ''\n\t\t\t\t\t) {\n\t\t\t\t\t\t// Remove invalid ref.\n\t\t\t\t\t\tdelete variationStyles[ key ];\n\t\t\t\t\t} else {\n\t\t\t\t\t\t// Resolve `ref` value.\n\t\t\t\t\t\tconst refValue = getValueFromObjectPath(\n\t\t\t\t\t\t\tglobalStyles,\n\t\t\t\t\t\t\tvalue.ref\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tif ( refValue ) {\n\t\t\t\t\t\t\tvariationStyles[ key ] = refValue;\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tdelete variationStyles[ key ];\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// Recursively resolve `ref` values in nested objects.\n\t\t\t\t\treplaceRefs( value );\n\n\t\t\t\t\t// After recursion, if value is empty due to explicitly\n\t\t\t\t\t// `undefined` ref value, remove it.\n\t\t\t\t\tif ( Object.keys( value ).length === 0 ) {\n\t\t\t\t\t\tdelete variationStyles[ key ];\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t} );\n\t};\n\n\t// Deep clone variation node to avoid mutating it within global styles and losing refs.\n\tconst styles = JSON.parse(\n\t\tJSON.stringify(\n\t\t\tglobalStyles.styles.blocks[ name ].variations[ variation ]\n\t\t)\n\t);\n\treplaceRefs( styles );\n\n\treturn styles;\n}\n\nfunction useBlockStyleVariation( name, variation, clientId ) {\n\t// Prefer global styles data in GlobalStylesContext, which are available\n\t// if in the site editor. Otherwise fall back to whatever is in the\n\t// editor settings and available in the post editor.\n\tconst { merged: mergedConfig } = useContext( GlobalStylesContext );\n\tconst { globalSettings, globalStyles } = useSelect( ( select ) => {\n\t\tconst settings = select( blockEditorStore ).getSettings();\n\t\treturn {\n\t\t\tglobalSettings: settings.__experimentalFeatures,\n\t\t\tglobalStyles: settings[ globalStylesDataKey ],\n\t\t};\n\t}, [] );\n\n\treturn useMemo( () => {\n\t\tconst variationStyles = getVariationStylesWithRefValues(\n\t\t\t{\n\t\t\t\tsettings: mergedConfig?.settings ?? globalSettings,\n\t\t\t\tstyles: mergedConfig?.styles ?? globalStyles,\n\t\t\t},\n\t\t\tname,\n\t\t\tvariation\n\t\t);\n\n\t\treturn {\n\t\t\tsettings: mergedConfig?.settings ?? globalSettings,\n\t\t\t// The variation style data is all that is needed to generate\n\t\t\t// the styles for the current application to a block. The variation\n\t\t\t// name is updated to match the instance specific class name.\n\t\t\tstyles: {\n\t\t\t\tblocks: {\n\t\t\t\t\t[ name ]: {\n\t\t\t\t\t\tvariations: {\n\t\t\t\t\t\t\t[ `${ variation }-${ clientId }` ]: variationStyles,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t};\n\t}, [\n\t\tmergedConfig,\n\t\tglobalSettings,\n\t\tglobalStyles,\n\t\tvariation,\n\t\tclientId,\n\t\tname,\n\t] );\n}\n\n// Rather than leveraging `useInstanceId` here, the `clientId` is used.\n// This is so that the variation style override's ID is predictable\n// when the order of applied style variations changes.\nfunction useBlockProps( { name, className, clientId } ) {\n\tconst { getBlockStyles } = useSelect( blocksStore );\n\n\tconst registeredStyles = getBlockStyles( name );\n\tconst variation = getVariationNameFromClass( className, registeredStyles );\n\tconst variationClass = `${ VARIATION_PREFIX }${ variation }-${ clientId }`;\n\n\tconst { settings, styles } = useBlockStyleVariation(\n\t\tname,\n\t\tvariation,\n\t\tclientId\n\t);\n\n\tconst variationStyles = useMemo( () => {\n\t\tif ( ! variation ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst variationConfig = { settings, styles };\n\t\tconst blockSelectors = getBlockSelectors(\n\t\t\tgetBlockTypes(),\n\t\t\tgetBlockStyles,\n\t\t\tclientId\n\t\t);\n\t\tconst hasBlockGapSupport = false;\n\t\tconst hasFallbackGapSupport = true;\n\t\tconst disableLayoutStyles = true;\n\t\tconst disableRootPadding = true;\n\n\t\treturn toStyles(\n\t\t\tvariationConfig,\n\t\t\tblockSelectors,\n\t\t\thasBlockGapSupport,\n\t\t\thasFallbackGapSupport,\n\t\t\tdisableLayoutStyles,\n\t\t\tdisableRootPadding,\n\t\t\t{\n\t\t\t\tblockGap: false,\n\t\t\t\tblockStyles: true,\n\t\t\t\tlayoutStyles: false,\n\t\t\t\tmarginReset: false,\n\t\t\t\tpresets: false,\n\t\t\t\trootPadding: false,\n\t\t\t\tvariationStyles: true,\n\t\t\t}\n\t\t);\n\t}, [ variation, settings, styles, getBlockStyles, clientId ] );\n\n\tuseStyleOverride( {\n\t\tid: `variation-${ clientId }`,\n\t\tcss: variationStyles,\n\t\t__unstableType: 'variation',\n\t\tvariation,\n\t\t// The clientId will be stored with the override and used to ensure\n\t\t// the order of overrides matches the order of blocks so that the\n\t\t// correct CSS cascade is maintained.\n\t\tclientId,\n\t} );\n\n\treturn variation ? { className: variationClass } : {};\n}\n\nexport default {\n\thasSupport: () => true,\n\tattributeKeys: [ 'className' ],\n\tisMatch: ( { className } ) => getVariationMatches( className ).length > 0,\n\tuseBlockProps,\n};\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,KAAK,IAAIC,WAAW,QAAQ,mBAAmB;AACvE,SAASC,SAAS,QAAQ,iBAAiB;AAC3C,SAASC,UAAU,EAAEC,OAAO,QAAQ,oBAAoB;;AAExD;AACA;AACA;AACA,SACCC,mBAAmB,EACnBC,QAAQ,EACRC,iBAAiB,QACX,6BAA6B;AACpC,SAASC,gBAAgB,QAAQ,SAAS;AAC1C,SAASC,sBAAsB,QAAQ,iBAAiB;AACxD,SAAST,KAAK,IAAIU,gBAAgB,QAAQ,UAAU;AACpD,SAASC,mBAAmB,QAAQ,uBAAuB;AAC3D,SAASC,MAAM,QAAQ,gBAAgB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAExC,MAAMC,gBAAgB,GAAG,WAAW;AAEpC,SAASC,mBAAmBA,CAAEC,SAAS,EAAG;EACzC,IAAK,CAAEA,SAAS,EAAG;IAClB,OAAO,EAAE;EACV;EACA,OAAOA,SAAS,CAACC,KAAK,CAAE,KAAM,CAAC,CAACC,MA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AAM,EAAEZ,cAAc,EAAEQ,QAAQ,CAAG,CAAC;EAE9DtC,gBAAgB,CAAE;IACjB2D,EAAE,EAAG,aAAarB,QAAU,EAAC;IAC7BsB,GAAG,EAAER,eAAe;IACpBS,cAAc,EAAE,WAAW;IAC3BtC,SAAS;IACT;IACA;IACA;IACAe;EACD,CAAE,CAAC;EAEH,OAAOf,SAAS,GAAG;IAAEZ,SAAS,EAAE8E;EAAe,CAAC,GAAG,CAAC,CAAC;AACtD;AAEA,eAAe;EACdC,UAAU,EAAEA,CAAA,KAAM,IAAI;EACtBC,aAAa,EAAE,CAAE,WAAW,CAAE;EAC9BC,OAAO,EAAEA,CAAE;IAAEjF;EAAU,CAAC,KAAMD,mBAAmB,CAAEC,SAAU,CAAC,CAACQ,MAAM,GAAG,CAAC;EACzEqE;AACD,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wordpress/block-editor",
|
|
3
|
-
"version": "13.0.
|
|
3
|
+
"version": "13.0.5",
|
|
4
4
|
"description": "Generic block editor.",
|
|
5
5
|
"author": "The WordPress Contributors",
|
|
6
6
|
"license": "GPL-2.0-or-later",
|
|
@@ -86,5 +86,5 @@
|
|
|
86
86
|
"publishConfig": {
|
|
87
87
|
"access": "public"
|
|
88
88
|
},
|
|
89
|
-
"gitHead": "
|
|
89
|
+
"gitHead": "38063ae466e1b62d400b910136757a4cafdbe7fa"
|
|
90
90
|
}
|
|
@@ -656,7 +656,7 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
|
|
|
656
656
|
}
|
|
657
657
|
const variationSelector =
|
|
658
658
|
blockSelectors[ blockName ]
|
|
659
|
-
|
|
659
|
+
?.styleVariationSelectors?.[ variationName ];
|
|
660
660
|
|
|
661
661
|
// Process the variation's inner element styles.
|
|
662
662
|
// This comes before the inner block styles so the
|
|
@@ -685,18 +685,18 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
|
|
|
685
685
|
const variationBlockSelector = scopeSelector(
|
|
686
686
|
variationSelector,
|
|
687
687
|
blockSelectors[ variationBlockName ]
|
|
688
|
-
|
|
688
|
+
?.selector
|
|
689
689
|
);
|
|
690
690
|
const variationDuotoneSelector = scopeSelector(
|
|
691
691
|
variationSelector,
|
|
692
692
|
blockSelectors[ variationBlockName ]
|
|
693
|
-
|
|
693
|
+
?.duotoneSelector
|
|
694
694
|
);
|
|
695
695
|
const variationFeatureSelectors =
|
|
696
696
|
scopeFeatureSelectors(
|
|
697
697
|
variationSelector,
|
|
698
698
|
blockSelectors[ variationBlockName ]
|
|
699
|
-
|
|
699
|
+
?.featureSelectors
|
|
700
700
|
);
|
|
701
701
|
|
|
702
702
|
const variationBlockStyleNodes =
|
|
@@ -713,10 +713,10 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
|
|
|
713
713
|
featureSelectors: variationFeatureSelectors,
|
|
714
714
|
fallbackGapValue:
|
|
715
715
|
blockSelectors[ variationBlockName ]
|
|
716
|
-
|
|
716
|
+
?.fallbackGapValue,
|
|
717
717
|
hasLayoutSupport:
|
|
718
718
|
blockSelectors[ variationBlockName ]
|
|
719
|
-
|
|
719
|
+
?.hasLayoutSupport,
|
|
720
720
|
styles: variationBlockStyleNodes,
|
|
721
721
|
} );
|
|
722
722
|
|
|
@@ -924,8 +924,8 @@ export const toStyles = (
|
|
|
924
924
|
ruleset += `padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) }
|
|
925
925
|
.has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); }
|
|
926
926
|
.has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); }
|
|
927
|
-
.has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull
|
|
928
|
-
.has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull
|
|
927
|
+
.has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull)) { padding-right: 0; padding-left: 0; }
|
|
928
|
+
.has-global-padding :where(:not(.alignfull.is-layout-flow) > .has-global-padding:not(.wp-block-block, .alignfull)) > .alignfull { margin-left: 0; margin-right: 0;
|
|
929
929
|
`;
|
|
930
930
|
}
|
|
931
931
|
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
getBlockSelectors,
|
|
15
15
|
} from '../components/global-styles';
|
|
16
16
|
import { useStyleOverride } from './utils';
|
|
17
|
+
import { getValueFromObjectPath } from '../utils/object';
|
|
17
18
|
import { store as blockEditorStore } from '../store';
|
|
18
19
|
import { globalStylesDataKey } from '../store/private-keys';
|
|
19
20
|
import { unlock } from '../lock-unlock';
|
|
@@ -180,6 +181,77 @@ export function __unstableBlockStyleVariationOverridesWithConfig( { config } ) {
|
|
|
180
181
|
);
|
|
181
182
|
}
|
|
182
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Retrieves any variation styles data and resolves any referenced values.
|
|
186
|
+
*
|
|
187
|
+
* @param {Object} globalStyles A complete global styles object, containing settings and styles.
|
|
188
|
+
* @param {string} name The name of the desired block type.
|
|
189
|
+
* @param {variation} variation The of the block style variation to retrieve data for.
|
|
190
|
+
*
|
|
191
|
+
* @return {Object|undefined} The global styles data for the specified variation.
|
|
192
|
+
*/
|
|
193
|
+
export function getVariationStylesWithRefValues(
|
|
194
|
+
globalStyles,
|
|
195
|
+
name,
|
|
196
|
+
variation
|
|
197
|
+
) {
|
|
198
|
+
if ( ! globalStyles?.styles?.blocks?.[ name ]?.variations?.[ variation ] ) {
|
|
199
|
+
return;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Helper to recursively look for `ref` values to resolve.
|
|
203
|
+
const replaceRefs = ( variationStyles ) => {
|
|
204
|
+
Object.keys( variationStyles ).forEach( ( key ) => {
|
|
205
|
+
const value = variationStyles[ key ];
|
|
206
|
+
|
|
207
|
+
// Only process objects.
|
|
208
|
+
if ( typeof value === 'object' && value !== null ) {
|
|
209
|
+
// Process `ref` value if present.
|
|
210
|
+
if ( value.ref !== undefined ) {
|
|
211
|
+
if (
|
|
212
|
+
typeof value.ref !== 'string' ||
|
|
213
|
+
value.ref.trim() === ''
|
|
214
|
+
) {
|
|
215
|
+
// Remove invalid ref.
|
|
216
|
+
delete variationStyles[ key ];
|
|
217
|
+
} else {
|
|
218
|
+
// Resolve `ref` value.
|
|
219
|
+
const refValue = getValueFromObjectPath(
|
|
220
|
+
globalStyles,
|
|
221
|
+
value.ref
|
|
222
|
+
);
|
|
223
|
+
|
|
224
|
+
if ( refValue ) {
|
|
225
|
+
variationStyles[ key ] = refValue;
|
|
226
|
+
} else {
|
|
227
|
+
delete variationStyles[ key ];
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
} else {
|
|
231
|
+
// Recursively resolve `ref` values in nested objects.
|
|
232
|
+
replaceRefs( value );
|
|
233
|
+
|
|
234
|
+
// After recursion, if value is empty due to explicitly
|
|
235
|
+
// `undefined` ref value, remove it.
|
|
236
|
+
if ( Object.keys( value ).length === 0 ) {
|
|
237
|
+
delete variationStyles[ key ];
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
} );
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// Deep clone variation node to avoid mutating it within global styles and losing refs.
|
|
245
|
+
const styles = JSON.parse(
|
|
246
|
+
JSON.stringify(
|
|
247
|
+
globalStyles.styles.blocks[ name ].variations[ variation ]
|
|
248
|
+
)
|
|
249
|
+
);
|
|
250
|
+
replaceRefs( styles );
|
|
251
|
+
|
|
252
|
+
return styles;
|
|
253
|
+
}
|
|
254
|
+
|
|
183
255
|
function useBlockStyleVariation( name, variation, clientId ) {
|
|
184
256
|
// Prefer global styles data in GlobalStylesContext, which are available
|
|
185
257
|
// if in the site editor. Otherwise fall back to whatever is in the
|
|
@@ -194,9 +266,14 @@ function useBlockStyleVariation( name, variation, clientId ) {
|
|
|
194
266
|
}, [] );
|
|
195
267
|
|
|
196
268
|
return useMemo( () => {
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
269
|
+
const variationStyles = getVariationStylesWithRefValues(
|
|
270
|
+
{
|
|
271
|
+
settings: mergedConfig?.settings ?? globalSettings,
|
|
272
|
+
styles: mergedConfig?.styles ?? globalStyles,
|
|
273
|
+
},
|
|
274
|
+
name,
|
|
275
|
+
variation
|
|
276
|
+
);
|
|
200
277
|
|
|
201
278
|
return {
|
|
202
279
|
settings: mergedConfig?.settings ?? globalSettings,
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { getVariationStylesWithRefValues } from '../block-style-variation';
|
|
5
|
+
|
|
6
|
+
describe( 'getVariationStylesWithRefValues', () => {
|
|
7
|
+
it( 'should resolve ref values correctly', () => {
|
|
8
|
+
const globalStyles = {
|
|
9
|
+
styles: {
|
|
10
|
+
color: { background: 'red' },
|
|
11
|
+
blocks: {
|
|
12
|
+
'core/heading': {
|
|
13
|
+
color: { text: 'blue' },
|
|
14
|
+
},
|
|
15
|
+
'core/group': {
|
|
16
|
+
variations: {
|
|
17
|
+
custom: {
|
|
18
|
+
color: {
|
|
19
|
+
text: { ref: 'styles.does-not-exist' },
|
|
20
|
+
background: {
|
|
21
|
+
ref: 'styles.color.background',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
blocks: {
|
|
25
|
+
'core/heading': {
|
|
26
|
+
color: {
|
|
27
|
+
text: {
|
|
28
|
+
ref: 'styles.blocks.core/heading.color.text',
|
|
29
|
+
},
|
|
30
|
+
background: { ref: '' },
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
elements: {
|
|
35
|
+
link: {
|
|
36
|
+
color: {
|
|
37
|
+
text: {
|
|
38
|
+
ref: 'styles.elements.link.color.text',
|
|
39
|
+
},
|
|
40
|
+
background: { ref: undefined },
|
|
41
|
+
},
|
|
42
|
+
':hover': {
|
|
43
|
+
color: {
|
|
44
|
+
text: {
|
|
45
|
+
ref: 'styles.elements.link.:hover.color.text',
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
elements: {
|
|
56
|
+
link: {
|
|
57
|
+
color: { text: 'green' },
|
|
58
|
+
':hover': {
|
|
59
|
+
color: { text: 'yellow' },
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
expect(
|
|
67
|
+
getVariationStylesWithRefValues(
|
|
68
|
+
globalStyles,
|
|
69
|
+
'core/group',
|
|
70
|
+
'custom'
|
|
71
|
+
)
|
|
72
|
+
).toEqual( {
|
|
73
|
+
color: { background: 'red' },
|
|
74
|
+
blocks: {
|
|
75
|
+
'core/heading': {
|
|
76
|
+
color: { text: 'blue' },
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
elements: {
|
|
80
|
+
link: {
|
|
81
|
+
color: {
|
|
82
|
+
text: 'green',
|
|
83
|
+
},
|
|
84
|
+
':hover': {
|
|
85
|
+
color: { text: 'yellow' },
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
} );
|
|
90
|
+
} );
|
|
91
|
+
} );
|