@@ -88,13 +88,6 @@ const SOURCE_DESCRIPTORS = {
8888 breadcrumb : [ SOURCE_BREADCRUMB_PARTS . styles ] ,
8989 layer : 'root' ,
9090 } ,
91- rootElement : {
92- breadcrumb : [
93- SOURCE_BREADCRUMB_PARTS . styles ,
94- SOURCE_BREADCRUMB_PARTS . elements ,
95- ] ,
96- layer : 'rootElement' ,
97- } ,
9891 block : {
9992 breadcrumb : [
10093 SOURCE_BREADCRUMB_PARTS . styles ,
@@ -103,15 +96,6 @@ const SOURCE_DESCRIPTORS = {
10396 ] ,
10497 layer : 'block' ,
10598 } ,
106- blockElement : {
107- breadcrumb : [
108- SOURCE_BREADCRUMB_PARTS . styles ,
109- SOURCE_BREADCRUMB_PARTS . blocks ,
110- SOURCE_BREADCRUMB_PARTS . blockName ,
111- SOURCE_BREADCRUMB_PARTS . elements ,
112- ] ,
113- layer : 'blockElement' ,
114- } ,
11599 blockVariation : {
116100 breadcrumb : [
117101 SOURCE_BREADCRUMB_PARTS . styles ,
@@ -122,38 +106,24 @@ const SOURCE_DESCRIPTORS = {
122106 ] ,
123107 layer : 'blockVariation' ,
124108 } ,
125- blockVariationElement : {
126- breadcrumb : [
127- SOURCE_BREADCRUMB_PARTS . styles ,
128- SOURCE_BREADCRUMB_PARTS . blocks ,
129- SOURCE_BREADCRUMB_PARTS . blockName ,
130- SOURCE_BREADCRUMB_PARTS . variations ,
131- SOURCE_BREADCRUMB_PARTS . variationName ,
132- SOURCE_BREADCRUMB_PARTS . elements ,
133- ] ,
134- layer : 'blockVariationElement' ,
135- } ,
136109} ;
137110
138111function createSourceDescriptor (
139112 type ,
140- { blockName, variation, element , blockStyles } = { }
113+ { blockName, variation, blockStyles } = { }
141114) {
142115 const descriptor = SOURCE_DESCRIPTORS [ type ] ;
143116 if ( ! descriptor ) {
144117 return null ;
145118 }
146119 return {
147120 ...descriptor ,
148- breadcrumb : element
149- ? [ ...descriptor . breadcrumb , element ]
150- : [ ...descriptor . breadcrumb ] ,
121+ breadcrumb : [ ...descriptor . breadcrumb ] ,
151122 blockName : blockName ?? null ,
152123 variation : variation ?? null ,
153124 variationTitle :
154125 blockStyles ?. find ( ( style ) => style . name === variation ) ?. label ??
155126 null ,
156- element : element ?? null ,
157127 } ;
158128}
159129
@@ -236,8 +206,7 @@ function isRefObject( v ) {
236206 * leaves and sub-trees that are not tree-structural and not the
237207 * `elements` sub-tree itself. The `elements` sub-tree IS preserved as a
238208 * passthrough on the final payload so panels that read e.g.
239- * `inheritedValue.elements.link.color.text` keep working; it just does
240- * not participate in the element-scoped fold.
209+ * `inheritedValue.elements.link.color.text` keep working.
241210 *
242211 * Does not recurse or clone; the returned contribution references the
243212 * original layer's sub-objects. The deep-merge step copies them into a
@@ -269,37 +238,6 @@ function pickLayerRootContribution( layer ) {
269238 return Object . keys ( contribution ) . length === 0 ? null : contribution ;
270239}
271240
272- /**
273- * Pick the element-scope contribution from `layer.elements[element]`.
274- * Returns a plain-object "layer-shaped" contribution — same top-level
275- * keys as a normal layer — so it can be merged in the same pipeline as
276- * root-scope contributions, inheriting deep-merge semantics.
277- *
278- * @param {Object } layer Raw styles layer.
279- * @param {?string } element Element tag (e.g. `h2`, `link`).
280- * @return {Object|null } Element-scope contribution, or `null` when no leaves contribute.
281- */
282- function pickLayerElementContribution ( layer , element ) {
283- if ( ! element || ! layer || ! layer . elements ) {
284- return null ;
285- }
286- const folded = layer . elements [ element ] ;
287- if ( ! folded || typeof folded !== 'object' || Array . isArray ( folded ) ) {
288- return null ;
289- }
290- const contribution = { } ;
291- for ( const key of Object . keys ( folded ) ) {
292- if ( TREE_STRUCTURAL_KEYS . has ( key ) || key === 'elements' ) {
293- continue ;
294- }
295- if ( isExplicitEmpty ( folded [ key ] ) ) {
296- continue ;
297- }
298- contribution [ key ] = folded [ key ] ;
299- }
300- return Object . keys ( contribution ) . length === 0 ? null : contribution ;
301- }
302-
303241/**
304242 * Deep-merge `source` into `target` with the following rules:
305243 * - Plain objects recurse.
@@ -379,22 +317,6 @@ function deepMergeDroppingEmpties(
379317 return target ;
380318}
381319
382- /**
383- * Read a layer's `elements[ element ]` sub-object, guarding against
384- * non-object values.
385- *
386- * @param {?Object } layer Raw styles layer.
387- * @param {?string } element Element tag (e.g. `h2`, `link`, `button`).
388- * @return {Object|null } The element sub-object, or `null`.
389- */
390- function getElementObject ( layer , element ) {
391- if ( ! layer || ! element ) {
392- return null ;
393- }
394- const el = layer . elements ?. [ element ] ;
395- return el && typeof el === 'object' && ! Array . isArray ( el ) ? el : null ;
396- }
397-
398320/**
399321 * Resolve the state-scoped slice of a layer-shaped object for the selected
400322 * block style state, guarding against nullish inputs.
@@ -420,7 +342,6 @@ function getStateSlice( layerObject, selectedState ) {
420342 *
421343 * @param {Object } args
422344 * @param {string } args.blockName Block name (e.g. `core/heading`).
423- * @param {?string } [args.element] Element tag to fold (e.g. `h2`, `link`), or null for block-scope only.
424345 * @param {?string } [args.ownVariation] Active block style variation slug, or null.
425346 * @param {Object } [args.globalStyles] The `settings[ globalStylesDataKey ]` payload.
426347 * @param {Array } [args.blockStyles] Registered styles for the block type.
@@ -429,7 +350,6 @@ function getStateSlice( layerObject, selectedState ) {
429350 */
430351function computeInheritedValue ( {
431352 blockName,
432- element = null ,
433353 ownVariation = null ,
434354 globalStyles,
435355 blockStyles = [ ] ,
@@ -455,35 +375,21 @@ function computeInheritedValue( {
455375 ) ?? null
456376 : null ;
457377
458- // Layers are ordered from low to high precedence. Root-scope and
459- // element-scope contributions are merged separately so element
460- // overrides can replace specific leaves without dropping sibling values.
378+ // Layers are ordered from low to high precedence: root defaults, the
379+ // block's own defaults, then the active block style variation. Each
380+ // layer's `elements` sub-tree is preserved as a passthrough so panels
381+ // can read element styles (e.g. `inheritedValue.elements.link`).
461382 const contributions = [
462383 createContribution (
463384 pickLayerRootContribution ( root ) ,
464385 createSourceDescriptor ( 'root' )
465386 ) ,
466- element
467- ? createContribution (
468- pickLayerElementContribution ( root , element ) ,
469- createSourceDescriptor ( 'rootElement' , { element } )
470- )
471- : null ,
472387 block
473388 ? createContribution (
474389 pickLayerRootContribution ( block ) ,
475390 createSourceDescriptor ( 'block' , { blockName } )
476391 )
477392 : null ,
478- block && element
479- ? createContribution (
480- pickLayerElementContribution ( block , element ) ,
481- createSourceDescriptor ( 'blockElement' , {
482- blockName,
483- element,
484- } )
485- )
486- : null ,
487393 variation
488394 ? createContribution (
489395 pickLayerRootContribution ( variation ) ,
@@ -494,17 +400,6 @@ function computeInheritedValue( {
494400 } )
495401 )
496402 : null ,
497- variation && element
498- ? createContribution (
499- pickLayerElementContribution ( variation , element ) ,
500- createSourceDescriptor ( 'blockVariationElement' , {
501- blockName,
502- variation : ownVariation ,
503- blockStyles,
504- element,
505- } )
506- )
507- : null ,
508403 ] ;
509404
510405 // When a non-default block style state (pseudo and/or responsive
@@ -523,17 +418,6 @@ function computeInheritedValue( {
523418 ) ,
524419 createSourceDescriptor ( 'root' )
525420 ) ,
526- element
527- ? createContribution (
528- pickLayerRootContribution (
529- getStateSlice (
530- getElementObject ( root , element ) ,
531- selectedState
532- )
533- ) ,
534- createSourceDescriptor ( 'rootElement' , { element } )
535- )
536- : null ,
537421 block
538422 ? createContribution (
539423 pickLayerRootContribution (
@@ -542,20 +426,6 @@ function computeInheritedValue( {
542426 createSourceDescriptor ( 'block' , { blockName } )
543427 )
544428 : null ,
545- block && element
546- ? createContribution (
547- pickLayerRootContribution (
548- getStateSlice (
549- getElementObject ( block , element ) ,
550- selectedState
551- )
552- ) ,
553- createSourceDescriptor ( 'blockElement' , {
554- blockName,
555- element,
556- } )
557- )
558- : null ,
559429 variation
560430 ? createContribution (
561431 pickLayerRootContribution (
@@ -567,22 +437,6 @@ function computeInheritedValue( {
567437 blockStyles,
568438 } )
569439 )
570- : null ,
571- variation && element
572- ? createContribution (
573- pickLayerRootContribution (
574- getStateSlice (
575- getElementObject ( variation , element ) ,
576- selectedState
577- )
578- ) ,
579- createSourceDescriptor ( 'blockVariationElement' , {
580- blockName,
581- variation : ownVariation ,
582- blockStyles,
583- element,
584- } )
585- )
586440 : null
587441 ) ;
588442 }
@@ -611,7 +465,7 @@ function computeInheritedValue( {
611465
612466/**
613467 * Shared memo for `buildInheritedValue`, keyed by Global
614- * Styles object identity and a `(blockName, element, ownVariation)` composite.
468+ * Styles object identity and a `(blockName, ownVariation)` composite.
615469 *
616470 * @type {WeakMap<object, Map<string, Object>> }
617471 */
@@ -646,8 +500,6 @@ export function buildInheritedValue( args ) {
646500 const key =
647501 ( args . blockName || '' ) +
648502 '\u0001' +
649- ( args . element || '' ) +
650- '\u0001' +
651503 ( args . ownVariation || '' ) +
652504 '\u0001' +
653505 blockStylesKey +
@@ -667,6 +519,5 @@ export const __unstable = {
667519 isExplicitEmpty,
668520 isRefObject,
669521 pickLayerRootContribution,
670- pickLayerElementContribution,
671522 deepMergeDroppingEmpties,
672523} ;
0 commit comments