@wordpress/block-editor 15.16.1-next.v.202604091042.0 → 15.17.0
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/CHANGELOG.md +2 -0
- package/build/components/copy-handler/index.cjs.map +2 -2
- package/build/components/link-control/link-preview.cjs +3 -1
- package/build/components/link-control/link-preview.cjs.map +2 -2
- package/build/components/preset-input-control/index.cjs +7 -4
- package/build/components/preset-input-control/index.cjs.map +2 -2
- package/build/components/rich-text/event-listeners/index.cjs.map +2 -2
- package/build/components/spacing-sizes-control/utils.cjs +1 -1
- package/build/components/spacing-sizes-control/utils.cjs.map +2 -2
- package/build/components/writing-flow/use-selection-observer.cjs +23 -1
- package/build/components/writing-flow/use-selection-observer.cjs.map +2 -2
- package/build/hooks/style.cjs +54 -52
- package/build/hooks/style.cjs.map +2 -2
- package/build-module/components/copy-handler/index.mjs.map +2 -2
- package/build-module/components/link-control/link-preview.mjs +3 -1
- package/build-module/components/link-control/link-preview.mjs.map +2 -2
- package/build-module/components/preset-input-control/index.mjs +7 -4
- package/build-module/components/preset-input-control/index.mjs.map +2 -2
- package/build-module/components/rich-text/event-listeners/index.mjs.map +2 -2
- package/build-module/components/spacing-sizes-control/utils.mjs +1 -1
- package/build-module/components/spacing-sizes-control/utils.mjs.map +2 -2
- package/build-module/components/writing-flow/use-selection-observer.mjs +23 -1
- package/build-module/components/writing-flow/use-selection-observer.mjs.map +2 -2
- package/build-module/hooks/style.mjs +54 -52
- package/build-module/hooks/style.mjs.map +2 -2
- package/package.json +38 -38
- package/src/components/copy-handler/index.js +1 -0
- package/src/components/link-control/link-preview.js +3 -1
- package/src/components/preset-input-control/index.js +10 -4
- package/src/components/preset-input-control/test/index.js +70 -0
- package/src/components/rich-text/event-listeners/index.js +1 -0
- package/src/components/spacing-sizes-control/utils.js +1 -1
- package/src/components/writing-flow/use-selection-observer.js +39 -1
- package/src/hooks/style.js +75 -61
package/src/hooks/style.js
CHANGED
|
@@ -382,84 +382,98 @@ const elementTypes = [
|
|
|
382
382
|
// Used for generating the instance ID
|
|
383
383
|
const STYLE_BLOCK_PROPS_REFERENCE = {};
|
|
384
384
|
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
385
|
+
/**
|
|
386
|
+
* Generates CSS rules for block element styles (buttons, links, headings, etc.).
|
|
387
|
+
*
|
|
388
|
+
* Iterates over supported element types and compiles their styles, including
|
|
389
|
+
* pseudo-selectors (e.g. :hover) and related sub-elements (e.g. h1-h6 for headings),
|
|
390
|
+
* into scoped CSS rule strings.
|
|
391
|
+
*
|
|
392
|
+
* @param {Object} blockElementStyles The block's `style.elements` object.
|
|
393
|
+
* @param {string} blockName The block name, used for skip-serialization checks.
|
|
394
|
+
* @param {string} baseSelector The base CSS selector to scope rules under.
|
|
395
|
+
* @return {string|undefined} Concatenated CSS rules string, or undefined if none.
|
|
396
|
+
*/
|
|
397
|
+
function getElementCSSRules( blockElementStyles, blockName, baseSelector ) {
|
|
398
|
+
if ( ! blockElementStyles ) {
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
390
401
|
|
|
391
|
-
const
|
|
392
|
-
const blockElementStyles = style?.elements;
|
|
402
|
+
const rules = [];
|
|
393
403
|
|
|
394
|
-
|
|
395
|
-
|
|
404
|
+
elementTypes.forEach( ( { elementType, pseudo, elements } ) => {
|
|
405
|
+
const skipSerialization = shouldSkipSerialization(
|
|
406
|
+
blockName,
|
|
407
|
+
COLOR_SUPPORT_KEY,
|
|
408
|
+
elementType
|
|
409
|
+
);
|
|
410
|
+
|
|
411
|
+
if ( skipSerialization ) {
|
|
396
412
|
return;
|
|
397
413
|
}
|
|
398
414
|
|
|
399
|
-
const
|
|
415
|
+
const elementStyles = blockElementStyles?.[ elementType ];
|
|
400
416
|
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
elementType
|
|
417
|
+
// Process primary element type styles.
|
|
418
|
+
if ( elementStyles ) {
|
|
419
|
+
const selector = scopeSelector(
|
|
420
|
+
baseSelector,
|
|
421
|
+
ELEMENTS[ elementType ]
|
|
406
422
|
);
|
|
407
423
|
|
|
408
|
-
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
424
|
+
rules.push( compileCSS( elementStyles, { selector } ) );
|
|
411
425
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
ELEMENTS[ elementType ]
|
|
419
|
-
);
|
|
420
|
-
|
|
421
|
-
elementCSSRules.push(
|
|
422
|
-
compileCSS( elementStyles, { selector } )
|
|
423
|
-
);
|
|
424
|
-
|
|
425
|
-
// Process any interactive states for the element type.
|
|
426
|
-
if ( pseudo ) {
|
|
427
|
-
pseudo.forEach( ( pseudoSelector ) => {
|
|
428
|
-
if ( elementStyles[ pseudoSelector ] ) {
|
|
429
|
-
elementCSSRules.push(
|
|
430
|
-
compileCSS( elementStyles[ pseudoSelector ], {
|
|
431
|
-
selector: scopeSelector(
|
|
432
|
-
baseElementSelector,
|
|
433
|
-
`${ ELEMENTS[ elementType ] }${ pseudoSelector }`
|
|
434
|
-
),
|
|
435
|
-
} )
|
|
436
|
-
);
|
|
437
|
-
}
|
|
438
|
-
} );
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
// Process related elements e.g. h1-h6 for headings
|
|
443
|
-
if ( elements ) {
|
|
444
|
-
elements.forEach( ( element ) => {
|
|
445
|
-
if ( blockElementStyles[ element ] ) {
|
|
446
|
-
elementCSSRules.push(
|
|
447
|
-
compileCSS( blockElementStyles[ element ], {
|
|
426
|
+
// Process any interactive states for the element type.
|
|
427
|
+
if ( pseudo ) {
|
|
428
|
+
pseudo.forEach( ( pseudoSelector ) => {
|
|
429
|
+
if ( elementStyles[ pseudoSelector ] ) {
|
|
430
|
+
rules.push(
|
|
431
|
+
compileCSS( elementStyles[ pseudoSelector ], {
|
|
448
432
|
selector: scopeSelector(
|
|
449
|
-
|
|
450
|
-
ELEMENTS[
|
|
433
|
+
baseSelector,
|
|
434
|
+
`${ ELEMENTS[ elementType ] }${ pseudoSelector }`
|
|
451
435
|
),
|
|
452
436
|
} )
|
|
453
437
|
);
|
|
454
438
|
}
|
|
455
439
|
} );
|
|
456
440
|
}
|
|
457
|
-
}
|
|
441
|
+
}
|
|
442
|
+
|
|
443
|
+
// Process related elements e.g. h1-h6 for headings
|
|
444
|
+
if ( elements ) {
|
|
445
|
+
elements.forEach( ( element ) => {
|
|
446
|
+
if ( blockElementStyles[ element ] ) {
|
|
447
|
+
rules.push(
|
|
448
|
+
compileCSS( blockElementStyles[ element ], {
|
|
449
|
+
selector: scopeSelector(
|
|
450
|
+
baseSelector,
|
|
451
|
+
ELEMENTS[ element ]
|
|
452
|
+
),
|
|
453
|
+
} )
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
} );
|
|
457
|
+
}
|
|
458
|
+
} );
|
|
459
|
+
|
|
460
|
+
return rules.length > 0 ? rules.join( '' ) : undefined;
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
function useBlockProps( { name, style } ) {
|
|
464
|
+
const blockElementsContainerIdentifier = useInstanceId(
|
|
465
|
+
STYLE_BLOCK_PROPS_REFERENCE,
|
|
466
|
+
'wp-elements'
|
|
467
|
+
);
|
|
458
468
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
469
|
+
const baseElementSelector = `.${ blockElementsContainerIdentifier }`;
|
|
470
|
+
const blockElementStyles = style?.elements;
|
|
471
|
+
|
|
472
|
+
const styles = useMemo(
|
|
473
|
+
() =>
|
|
474
|
+
getElementCSSRules( blockElementStyles, name, baseElementSelector ),
|
|
475
|
+
[ baseElementSelector, blockElementStyles, name ]
|
|
476
|
+
);
|
|
463
477
|
|
|
464
478
|
useStyleOverride( { css: styles } );
|
|
465
479
|
|