@wordpress/block-editor 13.0.5 → 13.0.6

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.
Files changed (27) hide show
  1. package/build/components/block-list/use-block-props/use-block-refs.js +9 -2
  2. package/build/components/block-list/use-block-props/use-block-refs.js.map +1 -1
  3. package/build/components/block-toolbar/shuffle.js +1 -1
  4. package/build/components/block-toolbar/shuffle.js.map +1 -1
  5. package/build/components/global-styles/hooks.js +5 -1
  6. package/build/components/global-styles/hooks.js.map +1 -1
  7. package/build/components/global-styles/use-global-styles-output.js +20 -4
  8. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  9. package/build/layouts/constrained.js +6 -2
  10. package/build/layouts/constrained.js.map +1 -1
  11. package/build-module/components/block-list/use-block-props/use-block-refs.js +11 -4
  12. package/build-module/components/block-list/use-block-props/use-block-refs.js.map +1 -1
  13. package/build-module/components/block-toolbar/shuffle.js +1 -1
  14. package/build-module/components/block-toolbar/shuffle.js.map +1 -1
  15. package/build-module/components/global-styles/hooks.js +5 -1
  16. package/build-module/components/global-styles/hooks.js.map +1 -1
  17. package/build-module/components/global-styles/use-global-styles-output.js +20 -4
  18. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  19. package/build-module/layouts/constrained.js +6 -2
  20. package/build-module/layouts/constrained.js.map +1 -1
  21. package/package.json +2 -2
  22. package/src/components/block-list/use-block-props/use-block-refs.js +19 -3
  23. package/src/components/block-toolbar/shuffle.js +2 -1
  24. package/src/components/global-styles/hooks.js +5 -1
  25. package/src/components/global-styles/test/use-global-styles-output.js +2 -1
  26. package/src/components/global-styles/use-global-styles-output.js +19 -2
  27. package/src/layouts/constrained.js +10 -2
@@ -128,6 +128,7 @@ describe( 'global styles renderer', () => {
128
128
  },
129
129
  },
130
130
  selector: ELEMENTS.link,
131
+ skipSelectorWrapper: true,
131
132
  },
132
133
  {
133
134
  styles: {
@@ -480,7 +481,7 @@ describe( 'global styles renderer', () => {
480
481
  };
481
482
 
482
483
  expect( toStyles( tree, blockSelectors ) ).toEqual(
483
- ':where(body) {margin: 0;}.is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-constrained > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-constrained > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) { max-width: var(--wp--style--global--content-size); margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignwide { max-width: var(--wp--style--global--wide-size); }body .is-layout-flex { display:flex; }.is-layout-flex { flex-wrap: wrap; align-items: center; }.is-layout-flex > :is(*, div) { margin: 0; }body .is-layout-grid { display:grid; }.is-layout-grid > :is(*, div) { margin: 0; }:root :where(body){background-color: red;margin: 10px;padding: 10px;}:root :where(a:where(:not(.wp-element-button))){color: blue;}a:where(:not(.wp-element-button)):hover{color: orange;}a:where(:not(.wp-element-button)):focus{color: orange;}:root :where(h1){font-size: 42px;}:root :where(.wp-block-group){margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}:root :where(h1,h2,h3,h4,h5,h6){color: orange;}:root :where(h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button))){color: hotpink;}h1 a:where(:not(.wp-element-button)):hover,h2 a:where(:not(.wp-element-button)):hover,h3 a:where(:not(.wp-element-button)):hover,h4 a:where(:not(.wp-element-button)):hover,h5 a:where(:not(.wp-element-button)):hover,h6 a:where(:not(.wp-element-button)):hover{color: red;}h1 a:where(:not(.wp-element-button)):focus,h2 a:where(:not(.wp-element-button)):focus,h3 a:where(:not(.wp-element-button)):focus,h4 a:where(:not(.wp-element-button)):focus,h5 a:where(:not(.wp-element-button)):focus,h6 a:where(:not(.wp-element-button)):focus{color: red;}:root :where(.wp-block-image img, .wp-block-image .wp-crop-area){border-radius: 9999px;}:root :where(.wp-block-image){color: red;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.has-white-color{color: var(--wp--preset--color--white) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}h1.has-blue-color,h2.has-blue-color,h3.has-blue-color,h4.has-blue-color,h5.has-blue-color,h6.has-blue-color{color: var(--wp--preset--color--blue) !important;}h1.has-blue-background-color,h2.has-blue-background-color,h3.has-blue-background-color,h4.has-blue-background-color,h5.has-blue-background-color,h6.has-blue-background-color{background-color: var(--wp--preset--color--blue) !important;}h1.has-blue-border-color,h2.has-blue-border-color,h3.has-blue-border-color,h4.has-blue-border-color,h5.has-blue-border-color,h6.has-blue-border-color{border-color: var(--wp--preset--color--blue) !important;}'
484
+ ':where(body) {margin: 0;}.is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }.is-layout-constrained > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }.is-layout-constrained > .aligncenter { margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > :where(:not(.alignleft):not(.alignright):not(.alignfull)) { max-width: var(--wp--style--global--content-size); margin-left: auto !important; margin-right: auto !important; }.is-layout-constrained > .alignwide { max-width: var(--wp--style--global--wide-size); }body .is-layout-flex { display:flex; }.is-layout-flex { flex-wrap: wrap; align-items: center; }.is-layout-flex > :is(*, div) { margin: 0; }body .is-layout-grid { display:grid; }.is-layout-grid > :is(*, div) { margin: 0; }:root :where(body){background-color: red;margin: 10px;padding: 10px;}a:where(:not(.wp-element-button)){color: blue;}:root :where(a:where(:not(.wp-element-button)):hover){color: orange;}:root :where(a:where(:not(.wp-element-button)):focus){color: orange;}h1{font-size: 42px;}:root :where(.wp-block-group){margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}:root :where(h1,h2,h3,h4,h5,h6){color: orange;}:root :where(h1 a:where(:not(.wp-element-button)),h2 a:where(:not(.wp-element-button)),h3 a:where(:not(.wp-element-button)),h4 a:where(:not(.wp-element-button)),h5 a:where(:not(.wp-element-button)),h6 a:where(:not(.wp-element-button))){color: hotpink;}:root :where(h1 a:where(:not(.wp-element-button)):hover,h2 a:where(:not(.wp-element-button)):hover,h3 a:where(:not(.wp-element-button)):hover,h4 a:where(:not(.wp-element-button)):hover,h5 a:where(:not(.wp-element-button)):hover,h6 a:where(:not(.wp-element-button)):hover){color: red;}:root :where(h1 a:where(:not(.wp-element-button)):focus,h2 a:where(:not(.wp-element-button)):focus,h3 a:where(:not(.wp-element-button)):focus,h4 a:where(:not(.wp-element-button)):focus,h5 a:where(:not(.wp-element-button)):focus,h6 a:where(:not(.wp-element-button)):focus){color: red;}:root :where(.wp-block-image img, .wp-block-image .wp-crop-area){border-radius: 9999px;}:root :where(.wp-block-image){color: red;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }.has-white-color{color: var(--wp--preset--color--white) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}h1.has-blue-color,h2.has-blue-color,h3.has-blue-color,h4.has-blue-color,h5.has-blue-color,h6.has-blue-color{color: var(--wp--preset--color--blue) !important;}h1.has-blue-background-color,h2.has-blue-background-color,h3.has-blue-background-color,h4.has-blue-background-color,h5.has-blue-background-color,h6.has-blue-background-color{background-color: var(--wp--preset--color--blue) !important;}h1.has-blue-border-color,h2.has-blue-border-color,h3.has-blue-border-color,h4.has-blue-border-color,h5.has-blue-border-color,h6.has-blue-border-color{border-color: var(--wp--preset--color--blue) !important;}'
484
485
  );
485
486
  } );
486
487
 
@@ -37,6 +37,12 @@ import { getValueFromObjectPath, setImmutably } from '../../utils/object';
37
37
  import { unlock } from '../../lock-unlock';
38
38
  import { setThemeFileUris } from './theme-file-uri-utils';
39
39
 
40
+ // Elements that rely on class names in their selectors.
41
+ const ELEMENT_CLASS_NAMES = {
42
+ button: 'wp-element-button',
43
+ caption: 'wp-element-caption',
44
+ };
45
+
40
46
  // List of block support features that can have their related styles
41
47
  // generated under their own feature level selector rather than the block's.
42
48
  const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
@@ -636,6 +642,9 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
636
642
  nodes.push( {
637
643
  styles: tree.styles?.elements?.[ name ],
638
644
  selector,
645
+ // Top level elements that don't use a class name should not receive the
646
+ // `:root :where()` wrapper to maintain backwards compatibility.
647
+ skipSelectorWrapper: ! ELEMENT_CLASS_NAMES[ name ],
639
648
  } );
640
649
  }
641
650
  } );
@@ -942,6 +951,7 @@ export const toStyles = (
942
951
  hasLayoutSupport,
943
952
  featureSelectors,
944
953
  styleVariationSelectors,
954
+ skipSelectorWrapper,
945
955
  } ) => {
946
956
  // Process styles for block support features with custom feature level
947
957
  // CSS selectors set.
@@ -1000,7 +1010,10 @@ export const toStyles = (
1000
1010
  disableRootPadding
1001
1011
  );
1002
1012
  if ( styleDeclarations?.length ) {
1003
- ruleset += `:root :where(${ selector }){${ styleDeclarations.join(
1013
+ const generalSelector = skipSelectorWrapper
1014
+ ? selector
1015
+ : `:root :where(${ selector })`;
1016
+ ruleset += `${ generalSelector }{${ styleDeclarations.join(
1004
1017
  ';'
1005
1018
  ) };}`;
1006
1019
  }
@@ -1094,7 +1107,11 @@ export const toStyles = (
1094
1107
  .map( ( sel ) => sel + pseudoKey )
1095
1108
  .join( ',' );
1096
1109
 
1097
- const pseudoRule = `${ _selector }{${ pseudoDeclarations.join(
1110
+ // As pseudo classes such as :hover, :focus etc. have class-level
1111
+ // specificity, they must use the `:root :where()` wrapper. This.
1112
+ // caps the specificity at `0-1-0` to allow proper nesting of variations
1113
+ // and block type element styles.
1114
+ const pseudoRule = `:root :where(${ _selector }){${ pseudoDeclarations.join(
1098
1115
  ';'
1099
1116
  ) };}`;
1100
1117
 
@@ -217,15 +217,23 @@ export default {
217
217
  const paddingValues = getCSSRules( style );
218
218
  paddingValues.forEach( ( rule ) => {
219
219
  if ( rule.key === 'paddingRight' ) {
220
+ // Add unit if 0, to avoid calc(0 * -1) which is invalid.
221
+ const paddingRightValue =
222
+ rule.value === '0' ? '0px' : rule.value;
223
+
220
224
  output += `
221
225
  ${ appendSelectors( selector, '> .alignfull' ) } {
222
- margin-right: calc(${ rule.value } * -1);
226
+ margin-right: calc(${ paddingRightValue } * -1);
223
227
  }
224
228
  `;
225
229
  } else if ( rule.key === 'paddingLeft' ) {
230
+ // Add unit if 0, to avoid calc(0 * -1) which is invalid.
231
+ const paddingLeftValue =
232
+ rule.value === '0' ? '0px' : rule.value;
233
+
226
234
  output += `
227
235
  ${ appendSelectors( selector, '> .alignfull' ) } {
228
- margin-left: calc(${ rule.value } * -1);
236
+ margin-left: calc(${ paddingLeftValue } * -1);
229
237
  }
230
238
  `;
231
239
  }