@wordpress/edit-site 4.10.0 → 4.12.1-next.d6164808d3.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.
Files changed (204) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +26 -44
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/new-template.js +45 -23
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +493 -242
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/block-editor/index.js +1 -3
  9. package/build/components/block-editor/index.js.map +1 -1
  10. package/build/components/block-editor/resizable-editor.js +26 -12
  11. package/build/components/block-editor/resizable-editor.js.map +1 -1
  12. package/build/components/global-styles/border-panel.js +3 -3
  13. package/build/components/global-styles/border-panel.js.map +1 -1
  14. package/build/components/global-styles/dimensions-panel.js +280 -20
  15. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  16. package/build/components/global-styles/hooks.js +4 -4
  17. package/build/components/global-styles/hooks.js.map +1 -1
  18. package/build/components/global-styles/screen-color-palette.js +1 -1
  19. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  20. package/build/components/global-styles/screen-colors.js +51 -7
  21. package/build/components/global-styles/screen-colors.js.map +1 -1
  22. package/build/components/global-styles/screen-heading-color.js +157 -0
  23. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  24. package/build/components/global-styles/screen-typography-element.js +4 -0
  25. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  26. package/build/components/global-styles/screen-typography.js +5 -0
  27. package/build/components/global-styles/screen-typography.js.map +1 -1
  28. package/build/components/global-styles/typography-panel.js +82 -14
  29. package/build/components/global-styles/typography-panel.js.map +1 -1
  30. package/build/components/global-styles/typography-utils.js +217 -0
  31. package/build/components/global-styles/typography-utils.js.map +1 -0
  32. package/build/components/global-styles/ui.js +11 -0
  33. package/build/components/global-styles/ui.js.map +1 -1
  34. package/build/components/global-styles/use-global-styles-output.js +183 -52
  35. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  36. package/build/components/global-styles/utils.js +85 -5
  37. package/build/components/global-styles/utils.js.map +1 -1
  38. package/build/components/header/document-actions/index.js +1 -0
  39. package/build/components/header/document-actions/index.js.map +1 -1
  40. package/build/components/header/index.js +27 -12
  41. package/build/components/header/index.js.map +1 -1
  42. package/build/components/header/mode-switcher/index.js +0 -4
  43. package/build/components/header/mode-switcher/index.js.map +1 -1
  44. package/build/components/header/more-menu/index.js +13 -3
  45. package/build/components/header/more-menu/index.js.map +1 -1
  46. package/build/components/header/undo-redo/redo.js +2 -1
  47. package/build/components/header/undo-redo/redo.js.map +1 -1
  48. package/build/components/list/actions/index.js +1 -1
  49. package/build/components/list/actions/index.js.map +1 -1
  50. package/build/components/save-button/index.js +2 -3
  51. package/build/components/save-button/index.js.map +1 -1
  52. package/build/components/sidebar/default-sidebar.js +11 -1
  53. package/build/components/sidebar/default-sidebar.js.map +1 -1
  54. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  55. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  56. package/build/components/sidebar/plugin-sidebar/index.js +11 -1
  57. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  58. package/build/components/sidebar/template-card/template-actions.js +1 -1
  59. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  60. package/build/components/template-details/edit-template-title.js +1 -1
  61. package/build/components/template-details/edit-template-title.js.map +1 -1
  62. package/build/components/template-details/index.js +19 -9
  63. package/build/components/template-details/index.js.map +1 -1
  64. package/build/components/template-details/template-areas.js +1 -1
  65. package/build/components/template-details/template-areas.js.map +1 -1
  66. package/build/components/template-details/template-part-area-selector.js +47 -0
  67. package/build/components/template-details/template-part-area-selector.js.map +1 -0
  68. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  69. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  70. package/build/hooks/index.js +2 -0
  71. package/build/hooks/index.js.map +1 -1
  72. package/build/hooks/template-part-edit.js +86 -0
  73. package/build/hooks/template-part-edit.js.map +1 -0
  74. package/build/index.js +1 -1
  75. package/build/index.js.map +1 -1
  76. package/build-module/components/add-new-template/add-custom-template-modal.js +27 -45
  77. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  78. package/build-module/components/add-new-template/new-template.js +45 -25
  79. package/build-module/components/add-new-template/new-template.js.map +1 -1
  80. package/build-module/components/add-new-template/utils.js +489 -230
  81. package/build-module/components/add-new-template/utils.js.map +1 -1
  82. package/build-module/components/block-editor/index.js +1 -2
  83. package/build-module/components/block-editor/index.js.map +1 -1
  84. package/build-module/components/block-editor/resizable-editor.js +26 -12
  85. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  86. package/build-module/components/global-styles/border-panel.js +3 -3
  87. package/build-module/components/global-styles/border-panel.js.map +1 -1
  88. package/build-module/components/global-styles/dimensions-panel.js +278 -22
  89. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  90. package/build-module/components/global-styles/hooks.js +4 -4
  91. package/build-module/components/global-styles/hooks.js.map +1 -1
  92. package/build-module/components/global-styles/screen-color-palette.js +1 -1
  93. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  94. package/build-module/components/global-styles/screen-colors.js +51 -7
  95. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  96. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  97. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  98. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  99. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  100. package/build-module/components/global-styles/screen-typography.js +5 -0
  101. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  102. package/build-module/components/global-styles/typography-panel.js +83 -15
  103. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  104. package/build-module/components/global-styles/typography-utils.js +204 -0
  105. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  106. package/build-module/components/global-styles/ui.js +10 -0
  107. package/build-module/components/global-styles/ui.js.map +1 -1
  108. package/build-module/components/global-styles/use-global-styles-output.js +182 -61
  109. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  110. package/build-module/components/global-styles/utils.js +82 -5
  111. package/build-module/components/global-styles/utils.js.map +1 -1
  112. package/build-module/components/header/document-actions/index.js +1 -0
  113. package/build-module/components/header/document-actions/index.js.map +1 -1
  114. package/build-module/components/header/index.js +30 -14
  115. package/build-module/components/header/index.js.map +1 -1
  116. package/build-module/components/header/mode-switcher/index.js +0 -4
  117. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  118. package/build-module/components/header/more-menu/index.js +13 -3
  119. package/build-module/components/header/more-menu/index.js.map +1 -1
  120. package/build-module/components/header/undo-redo/redo.js +3 -2
  121. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  122. package/build-module/components/list/actions/index.js +1 -1
  123. package/build-module/components/list/actions/index.js.map +1 -1
  124. package/build-module/components/save-button/index.js +3 -4
  125. package/build-module/components/save-button/index.js.map +1 -1
  126. package/build-module/components/sidebar/default-sidebar.js +9 -1
  127. package/build-module/components/sidebar/default-sidebar.js.map +1 -1
  128. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  129. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  130. package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
  131. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  132. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  133. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  134. package/build-module/components/template-details/edit-template-title.js +1 -1
  135. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  136. package/build-module/components/template-details/index.js +19 -10
  137. package/build-module/components/template-details/index.js.map +1 -1
  138. package/build-module/components/template-details/template-areas.js +1 -1
  139. package/build-module/components/template-details/template-areas.js.map +1 -1
  140. package/build-module/components/template-details/template-part-area-selector.js +35 -0
  141. package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
  142. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  143. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  144. package/build-module/hooks/index.js +1 -0
  145. package/build-module/hooks/index.js.map +1 -1
  146. package/build-module/hooks/template-part-edit.js +67 -0
  147. package/build-module/hooks/template-part-edit.js.map +1 -0
  148. package/build-module/index.js +1 -1
  149. package/build-module/index.js.map +1 -1
  150. package/build-style/style-rtl.css +40 -33
  151. package/build-style/style.css +40 -33
  152. package/package.json +29 -29
  153. package/src/components/add-new-template/add-custom-template-modal.js +39 -48
  154. package/src/components/add-new-template/new-template.js +50 -58
  155. package/src/components/add-new-template/style.scss +20 -8
  156. package/src/components/add-new-template/utils.js +529 -231
  157. package/src/components/block-editor/index.js +0 -2
  158. package/src/components/block-editor/resizable-editor.js +28 -18
  159. package/src/components/editor/style.scss +1 -0
  160. package/src/components/global-styles/border-panel.js +3 -3
  161. package/src/components/global-styles/dimensions-panel.js +344 -45
  162. package/src/components/global-styles/hooks.js +6 -3
  163. package/src/components/global-styles/screen-color-palette.js +1 -1
  164. package/src/components/global-styles/screen-colors.js +46 -4
  165. package/src/components/global-styles/screen-heading-color.js +201 -0
  166. package/src/components/global-styles/screen-typography-element.js +4 -0
  167. package/src/components/global-styles/screen-typography.js +6 -0
  168. package/src/components/global-styles/style.scss +14 -6
  169. package/src/components/global-styles/test/typography-utils.js +130 -0
  170. package/src/components/global-styles/test/use-global-styles-output.js +143 -4
  171. package/src/components/global-styles/test/utils.js +68 -8
  172. package/src/components/global-styles/typography-panel.js +119 -48
  173. package/src/components/global-styles/typography-utils.js +228 -0
  174. package/src/components/global-styles/ui.js +13 -0
  175. package/src/components/global-styles/use-global-styles-output.js +203 -53
  176. package/src/components/global-styles/utils.js +70 -4
  177. package/src/components/header/document-actions/index.js +3 -0
  178. package/src/components/header/index.js +41 -14
  179. package/src/components/header/mode-switcher/index.js +0 -3
  180. package/src/components/header/more-menu/index.js +7 -2
  181. package/src/components/header/style.scss +5 -3
  182. package/src/components/header/undo-redo/redo.js +6 -2
  183. package/src/components/list/actions/index.js +3 -1
  184. package/src/components/save-button/index.js +10 -13
  185. package/src/components/sidebar/default-sidebar.js +12 -0
  186. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  187. package/src/components/sidebar/plugin-sidebar/index.js +12 -0
  188. package/src/components/sidebar/style.scss +4 -0
  189. package/src/components/sidebar/template-card/template-actions.js +3 -1
  190. package/src/components/template-details/edit-template-title.js +7 -3
  191. package/src/components/template-details/index.js +23 -8
  192. package/src/components/template-details/style.scss +0 -5
  193. package/src/components/template-details/template-areas.js +3 -1
  194. package/src/components/template-details/template-part-area-selector.js +38 -0
  195. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
  196. package/src/hooks/index.js +1 -0
  197. package/src/hooks/template-part-edit.js +82 -0
  198. package/src/index.js +1 -1
  199. package/src/style.scss +0 -1
  200. package/build/components/edit-template-part-menu-button/index.js +0 -90
  201. package/build/components/edit-template-part-menu-button/index.js.map +0 -1
  202. package/build-module/components/edit-template-part-menu-button/index.js +0 -72
  203. package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
  204. package/src/components/edit-template-part-menu-button/index.js +0 -82
@@ -10,7 +10,6 @@ import {
10
10
  pickBy,
11
11
  reduce,
12
12
  set,
13
- startsWith,
14
13
  } from 'lodash';
15
14
 
16
15
  /**
@@ -21,25 +20,37 @@ import {
21
20
  __EXPERIMENTAL_ELEMENTS as ELEMENTS,
22
21
  getBlockTypes,
23
22
  } from '@wordpress/blocks';
24
- import { useEffect, useState, useContext } from '@wordpress/element';
23
+ import { useSelect } from '@wordpress/data';
24
+ import { useContext, useMemo } from '@wordpress/element';
25
25
  import { getCSSRules } from '@wordpress/style-engine';
26
26
  import {
27
27
  __unstablePresetDuotoneFilter as PresetDuotoneFilter,
28
28
  __experimentalGetGapCSSValue as getGapCSSValue,
29
+ store as blockEditorStore,
29
30
  } from '@wordpress/block-editor';
30
31
 
31
32
  /**
32
33
  * Internal dependencies
33
34
  */
34
- import { PRESET_METADATA, ROOT_BLOCK_SELECTOR } from './utils';
35
+ import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
35
36
  import { GlobalStylesContext } from './context';
36
37
  import { useSetting } from './hooks';
37
38
 
39
+ // List of block support features that can have their related styles
40
+ // generated under their own feature level selector rather than the block's.
41
+ const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
42
+ __experimentalBorder: 'border',
43
+ color: 'color',
44
+ spacing: 'spacing',
45
+ typography: 'typography',
46
+ };
47
+
38
48
  function compileStyleValue( uncompiledValue ) {
39
49
  const VARIABLE_REFERENCE_PREFIX = 'var:';
40
50
  const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
41
51
  const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
42
- if ( startsWith( uncompiledValue, VARIABLE_REFERENCE_PREFIX ) ) {
52
+
53
+ if ( uncompiledValue?.startsWith?.( VARIABLE_REFERENCE_PREFIX ) ) {
43
54
  const variable = uncompiledValue
44
55
  .slice( VARIABLE_REFERENCE_PREFIX.length )
45
56
  .split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
@@ -53,10 +64,11 @@ function compileStyleValue( uncompiledValue ) {
53
64
  * Transform given preset tree into a set of style declarations.
54
65
  *
55
66
  * @param {Object} blockPresets
67
+ * @param {Object} mergedSettings Merged theme.json settings.
56
68
  *
57
- * @return {Array} An array of style declarations.
69
+ * @return {Array<Object>} An array of style declarations.
58
70
  */
59
- function getPresetsDeclarations( blockPresets = {} ) {
71
+ function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
60
72
  return reduce(
61
73
  PRESET_METADATA,
62
74
  ( declarations, { path, valueKey, valueFunc, cssVarInfix } ) => {
@@ -64,7 +76,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
64
76
  [ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
65
77
  if ( presetByOrigin[ origin ] ) {
66
78
  presetByOrigin[ origin ].forEach( ( value ) => {
67
- if ( valueKey ) {
79
+ if ( valueKey && ! valueFunc ) {
68
80
  declarations.push(
69
81
  `--wp--preset--${ cssVarInfix }--${ kebabCase(
70
82
  value.slug
@@ -77,7 +89,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
77
89
  declarations.push(
78
90
  `--wp--preset--${ cssVarInfix }--${ kebabCase(
79
91
  value.slug
80
- ) }: ${ valueFunc( value ) }`
92
+ ) }: ${ valueFunc( value, mergedSettings ) }`
81
93
  );
82
94
  }
83
95
  } );
@@ -172,14 +184,29 @@ function flattenTree( input = {}, prefix, token ) {
172
184
  /**
173
185
  * Transform given style tree into a set of style declarations.
174
186
  *
175
- * @param {Object} blockStyles Block styles.
187
+ * @param {Object} blockStyles Block styles.
188
+ *
189
+ * @param {string} selector The selector these declarations should attach to.
190
+ *
191
+ * @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
192
+ *
193
+ * @param {Object} tree A theme.json tree containing layout definitions.
176
194
  *
177
195
  * @return {Array} An array of style declarations.
178
196
  */
179
- function getStylesDeclarations( blockStyles = {} ) {
197
+ export function getStylesDeclarations(
198
+ blockStyles = {},
199
+ selector = '',
200
+ useRootPaddingAlign,
201
+ tree = {}
202
+ ) {
203
+ const isRoot = ROOT_BLOCK_SELECTOR === selector;
180
204
  const output = reduce(
181
205
  STYLE_PROPERTY,
182
- ( declarations, { value, properties, useEngine }, key ) => {
206
+ ( declarations, { value, properties, useEngine, rootOnly }, key ) => {
207
+ if ( rootOnly && ! isRoot ) {
208
+ return declarations;
209
+ }
183
210
  const pathToValue = value;
184
211
  if ( first( pathToValue ) === 'elements' || useEngine ) {
185
212
  return declarations;
@@ -187,6 +214,15 @@ function getStylesDeclarations( blockStyles = {} ) {
187
214
 
188
215
  const styleValue = get( blockStyles, pathToValue );
189
216
 
217
+ // Root-level padding styles don't currently support strings with CSS shorthand values.
218
+ // This may change: https://github.com/WordPress/gutenberg/issues/40132.
219
+ if (
220
+ key === '--wp--style--root--padding' &&
221
+ ( typeof styleValue === 'string' || ! useRootPaddingAlign )
222
+ ) {
223
+ return declarations;
224
+ }
225
+
190
226
  if ( !! properties && typeof styleValue !== 'string' ) {
191
227
  Object.entries( properties ).forEach( ( entry ) => {
192
228
  const [ name, prop ] = entry;
@@ -197,7 +233,9 @@ function getStylesDeclarations( blockStyles = {} ) {
197
233
  return;
198
234
  }
199
235
 
200
- const cssProperty = kebabCase( name );
236
+ const cssProperty = name.startsWith( '--' )
237
+ ? name
238
+ : kebabCase( name );
201
239
  declarations.push(
202
240
  `${ cssProperty }: ${ compileStyleValue(
203
241
  get( styleValue, [ prop ] )
@@ -224,10 +262,30 @@ function getStylesDeclarations( blockStyles = {} ) {
224
262
  // This is temporary as we absorb more and more styles into the engine.
225
263
  const extraRules = getCSSRules( blockStyles );
226
264
  extraRules.forEach( ( rule ) => {
265
+ // Don't output padding properties if padding variables are set.
266
+ if (
267
+ isRoot &&
268
+ useRootPaddingAlign &&
269
+ rule.key.startsWith( 'padding' )
270
+ ) {
271
+ return;
272
+ }
227
273
  const cssProperty = rule.key.startsWith( '--' )
228
274
  ? rule.key
229
275
  : kebabCase( rule.key );
230
- output.push( `${ cssProperty }: ${ compileStyleValue( rule.value ) }` );
276
+
277
+ let ruleValue = rule.value;
278
+ if ( typeof ruleValue !== 'string' && ruleValue?.ref ) {
279
+ const refPath = ruleValue.ref.split( '.' );
280
+ ruleValue = get( tree, refPath );
281
+ // Presence of another ref indicates a reference to another dynamic value.
282
+ // Pointing to another dynamic value is not supported.
283
+ if ( ! ruleValue || !! ruleValue?.ref ) {
284
+ return;
285
+ }
286
+ }
287
+
288
+ output.push( `${ cssProperty }: ${ ruleValue }` );
231
289
  } );
232
290
 
233
291
  return output;
@@ -294,14 +352,28 @@ export function getLayoutStyles( {
294
352
  }
295
353
 
296
354
  if ( declarations.length ) {
297
- const combinedSelector =
298
- selector === ROOT_BLOCK_SELECTOR
299
- ? `${ selector } .${ className }${
300
- spacingStyle?.selector || ''
301
- }`
302
- : `${ selector }.${ className }${
303
- spacingStyle?.selector || ''
304
- }`;
355
+ let combinedSelector = '';
356
+
357
+ if ( ! hasBlockGapSupport ) {
358
+ // For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
359
+ combinedSelector =
360
+ selector === ROOT_BLOCK_SELECTOR
361
+ ? `:where(.${ className }${
362
+ spacingStyle?.selector || ''
363
+ })`
364
+ : `:where(${ selector }.${ className }${
365
+ spacingStyle?.selector || ''
366
+ })`;
367
+ } else {
368
+ combinedSelector =
369
+ selector === ROOT_BLOCK_SELECTOR
370
+ ? `${ selector } .${ className }${
371
+ spacingStyle?.selector || ''
372
+ }`
373
+ : `${ selector }.${ className }${
374
+ spacingStyle?.selector || ''
375
+ }`;
376
+ }
305
377
  ruleset += `${ combinedSelector } { ${ declarations.join(
306
378
  '; '
307
379
  ) }; }`;
@@ -384,11 +456,12 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
384
456
  selector: ROOT_BLOCK_SELECTOR,
385
457
  } );
386
458
  }
387
- forEach( tree.styles?.elements, ( value, key ) => {
388
- if ( !! value && !! ELEMENTS[ key ] ) {
459
+
460
+ forEach( ELEMENTS, ( selector, name ) => {
461
+ if ( !! tree.styles?.elements[ name ] ) {
389
462
  nodes.push( {
390
- styles: value,
391
- selector: ELEMENTS[ key ],
463
+ styles: tree.styles?.elements[ name ],
464
+ selector,
392
465
  } );
393
466
  }
394
467
  } );
@@ -403,6 +476,7 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
403
476
  hasLayoutSupport: blockSelectors[ blockName ].hasLayoutSupport,
404
477
  selector: blockSelectors[ blockName ].selector,
405
478
  styles: blockStyles,
479
+ featureSelectors: blockSelectors[ blockName ].featureSelectors,
406
480
  } );
407
481
  }
408
482
 
@@ -480,10 +554,9 @@ export const getNodesWithSettings = ( tree, blockSelectors ) => {
480
554
 
481
555
  export const toCustomProperties = ( tree, blockSelectors ) => {
482
556
  const settings = getNodesWithSettings( tree, blockSelectors );
483
-
484
557
  let ruleset = '';
485
558
  settings.forEach( ( { presets, custom, selector } ) => {
486
- const declarations = getPresetsDeclarations( presets );
559
+ const declarations = getPresetsDeclarations( presets, tree?.settings );
487
560
  const customProps = flattenTree( custom, '--wp--custom--', '--' );
488
561
  if ( customProps.length > 0 ) {
489
562
  declarations.push( ...customProps );
@@ -501,10 +574,13 @@ export const toStyles = (
501
574
  tree,
502
575
  blockSelectors,
503
576
  hasBlockGapSupport,
504
- hasFallbackGapSupport
577
+ hasFallbackGapSupport,
578
+ disableLayoutStyles = false
505
579
  ) => {
506
580
  const nodesWithStyles = getNodesWithStyles( tree, blockSelectors );
507
581
  const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
582
+ const useRootPaddingAlign = tree?.settings?.useRootPaddingAwareAlignments;
583
+ const { contentSize, wideSize } = tree?.settings?.layout || {};
508
584
 
509
585
  /*
510
586
  * Reset default browser margin on the root body element.
@@ -514,7 +590,23 @@ export const toStyles = (
514
590
  * user-generated values take precedence in the CSS cascade.
515
591
  * @link https://github.com/WordPress/gutenberg/issues/36147.
516
592
  */
517
- let ruleset = 'body {margin: 0;}';
593
+ let ruleset = 'body {margin: 0;';
594
+
595
+ if ( contentSize ) {
596
+ ruleset += ` --wp--style--global--content-size: ${ contentSize };`;
597
+ }
598
+
599
+ if ( wideSize ) {
600
+ ruleset += ` --wp--style--global--wide-size: ${ wideSize };`;
601
+ }
602
+
603
+ if ( useRootPaddingAlign ) {
604
+ ruleset +=
605
+ 'padding-right: 0; padding-left: 0; padding-top: var(--wp--style--root--padding-top); padding-bottom: var(--wp--style--root--padding-bottom) } .has-global-padding { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left); } .has-global-padding > .alignfull { margin-right: calc(var(--wp--style--root--padding-right) * -1); margin-left: calc(var(--wp--style--root--padding-left) * -1); } .has-global-padding > .alignfull > :where([class*="wp-block-"]:not(.alignfull):not([class*="__"]),p,h1,h2,h3,h4,h5,h6,ul,ol) { padding-right: var(--wp--style--root--padding-right); padding-left: var(--wp--style--root--padding-left);';
606
+ }
607
+
608
+ ruleset += '}';
609
+
518
610
  nodesWithStyles.forEach(
519
611
  ( {
520
612
  selector,
@@ -522,7 +614,33 @@ export const toStyles = (
522
614
  styles,
523
615
  fallbackGapValue,
524
616
  hasLayoutSupport,
617
+ featureSelectors,
525
618
  } ) => {
619
+ // Process styles for block support features with custom feature level
620
+ // CSS selectors set.
621
+ if ( featureSelectors ) {
622
+ Object.entries( featureSelectors ).forEach(
623
+ ( [ featureName, featureSelector ] ) => {
624
+ if ( styles?.[ featureName ] ) {
625
+ const featureStyles = {
626
+ [ featureName ]: styles[ featureName ],
627
+ };
628
+ const featureDeclarations =
629
+ getStylesDeclarations( featureStyles );
630
+ delete styles[ featureName ];
631
+
632
+ if ( !! featureDeclarations.length ) {
633
+ ruleset =
634
+ ruleset +
635
+ `${ featureSelector }{${ featureDeclarations.join(
636
+ ';'
637
+ ) } }`;
638
+ }
639
+ }
640
+ }
641
+ );
642
+ }
643
+
526
644
  const duotoneStyles = {};
527
645
  if ( styles?.filter ) {
528
646
  duotoneStyles.filter = styles.filter;
@@ -533,18 +651,20 @@ export const toStyles = (
533
651
  if ( duotoneSelector ) {
534
652
  const duotoneDeclarations =
535
653
  getStylesDeclarations( duotoneStyles );
536
- if ( duotoneDeclarations.length === 0 ) {
537
- return;
654
+ if ( duotoneDeclarations.length > 0 ) {
655
+ ruleset =
656
+ ruleset +
657
+ `${ duotoneSelector }{${ duotoneDeclarations.join(
658
+ ';'
659
+ ) };}`;
538
660
  }
539
- ruleset =
540
- ruleset +
541
- `${ duotoneSelector }{${ duotoneDeclarations.join(
542
- ';'
543
- ) };}`;
544
661
  }
545
662
 
546
663
  // Process blockGap and layout styles.
547
- if ( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport ) {
664
+ if (
665
+ ! disableLayoutStyles &&
666
+ ( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport )
667
+ ) {
548
668
  ruleset += getLayoutStyles( {
549
669
  tree,
550
670
  style: styles,
@@ -556,7 +676,12 @@ export const toStyles = (
556
676
  }
557
677
 
558
678
  // Process the remaining block styles (they use either normal block class or __experimentalSelector).
559
- const declarations = getStylesDeclarations( styles );
679
+ const declarations = getStylesDeclarations(
680
+ styles,
681
+ selector,
682
+ useRootPaddingAlign,
683
+ tree
684
+ );
560
685
  if ( declarations?.length ) {
561
686
  ruleset =
562
687
  ruleset + `${ selector }{${ declarations.join( ';' ) };}`;
@@ -579,7 +704,7 @@ export const toStyles = (
579
704
 
580
705
  // `selector` maybe provided in a form
581
706
  // where block level selectors have sub element
582
- // selectors appended to them as a comma seperated
707
+ // selectors appended to them as a comma separated
583
708
  // string.
584
709
  // e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
585
710
  // Split and append pseudo selector to create
@@ -645,7 +770,7 @@ export function toSvgFilters( tree, blockSelectors ) {
645
770
  } );
646
771
  }
647
772
 
648
- const getBlockSelectors = ( blockTypes ) => {
773
+ export const getBlockSelectors = ( blockTypes ) => {
649
774
  const result = {};
650
775
  blockTypes.forEach( ( blockType ) => {
651
776
  const name = blockType.name;
@@ -657,9 +782,29 @@ const getBlockSelectors = ( blockTypes ) => {
657
782
  const hasLayoutSupport = !! blockType?.supports?.__experimentalLayout;
658
783
  const fallbackGapValue =
659
784
  blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
785
+
786
+ // For each block support feature add any custom selectors.
787
+ const featureSelectors = {};
788
+ Object.entries( BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS ).forEach(
789
+ ( [ featureKey, featureName ] ) => {
790
+ const featureSelector =
791
+ blockType?.supports?.[ featureKey ]?.__experimentalSelector;
792
+
793
+ if ( featureSelector ) {
794
+ featureSelectors[ featureName ] = scopeSelector(
795
+ selector,
796
+ featureSelector
797
+ );
798
+ }
799
+ }
800
+ );
801
+
660
802
  result[ name ] = {
661
803
  duotoneSelector,
662
804
  fallbackGapValue,
805
+ featureSelectors: Object.keys( featureSelectors ).length
806
+ ? featureSelectors
807
+ : undefined,
663
808
  hasLayoutSupport,
664
809
  name,
665
810
  selector,
@@ -670,17 +815,18 @@ const getBlockSelectors = ( blockTypes ) => {
670
815
  };
671
816
 
672
817
  export function useGlobalStylesOutput() {
673
- const [ stylesheets, setStylesheets ] = useState( [] );
674
- const [ settings, setSettings ] = useState( {} );
675
- const [ svgFilters, setSvgFilters ] = useState( {} );
676
818
  const { merged: mergedConfig } = useContext( GlobalStylesContext );
677
819
  const [ blockGap ] = useSetting( 'spacing.blockGap' );
678
820
  const hasBlockGapSupport = blockGap !== null;
679
821
  const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
822
+ const disableLayoutStyles = useSelect( ( select ) => {
823
+ const { getSettings } = select( blockEditorStore );
824
+ return !! getSettings().disableLayoutStyles;
825
+ } );
680
826
 
681
- useEffect( () => {
827
+ return useMemo( () => {
682
828
  if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
683
- return;
829
+ return [];
684
830
  }
685
831
 
686
832
  const blockSelectors = getBlockSelectors( getBlockTypes() );
@@ -692,10 +838,11 @@ export function useGlobalStylesOutput() {
692
838
  mergedConfig,
693
839
  blockSelectors,
694
840
  hasBlockGapSupport,
695
- hasFallbackGapSupport
841
+ hasFallbackGapSupport,
842
+ disableLayoutStyles
696
843
  );
697
844
  const filters = toSvgFilters( mergedConfig, blockSelectors );
698
- setStylesheets( [
845
+ const stylesheets = [
699
846
  {
700
847
  css: customProperties,
701
848
  isGlobalStyles: true,
@@ -704,10 +851,13 @@ export function useGlobalStylesOutput() {
704
851
  css: globalStyles,
705
852
  isGlobalStyles: true,
706
853
  },
707
- ] );
708
- setSettings( mergedConfig.settings );
709
- setSvgFilters( filters );
710
- }, [ hasBlockGapSupport, hasFallbackGapSupport, mergedConfig ] );
711
-
712
- return [ stylesheets, settings, svgFilters, hasBlockGapSupport ];
854
+ ];
855
+
856
+ return [ stylesheets, mergedConfig.settings, filters ];
857
+ }, [
858
+ hasBlockGapSupport,
859
+ hasFallbackGapSupport,
860
+ mergedConfig,
861
+ disableLayoutStyles,
862
+ ] );
713
863
  }
@@ -3,6 +3,11 @@
3
3
  */
4
4
  import { get, find } from 'lodash';
5
5
 
6
+ /**
7
+ * Internal dependencies
8
+ */
9
+ import { getTypographyFontSizeValue } from './typography-utils';
10
+
6
11
  /* Supporting data. */
7
12
  export const ROOT_BLOCK_NAME = 'root';
8
13
  export const ROOT_BLOCK_SELECTOR = 'body';
@@ -58,6 +63,8 @@ export const PRESET_METADATA = [
58
63
  },
59
64
  {
60
65
  path: [ 'typography', 'fontSizes' ],
66
+ valueFunc: ( preset, { typography: typographySettings } ) =>
67
+ getTypographyFontSizeValue( preset, typographySettings ),
61
68
  valueKey: 'size',
62
69
  cssVarInfix: 'font-size',
63
70
  classes: [ { classSuffix: 'font-size', propertyName: 'font-size' } ],
@@ -70,6 +77,13 @@ export const PRESET_METADATA = [
70
77
  { classSuffix: 'font-family', propertyName: 'font-family' },
71
78
  ],
72
79
  },
80
+ {
81
+ path: [ 'spacing', 'spacingSizes' ],
82
+ valueKey: 'spacingSizes',
83
+ cssVarInfix: 'spacing',
84
+ valueFunc: ( { size } ) => size,
85
+ classes: [],
86
+ },
73
87
  ];
74
88
 
75
89
  const STYLE_PATH_TO_CSS_VAR_INFIX = {
@@ -78,6 +92,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
78
92
  'elements.link.color.text': 'color',
79
93
  'elements.button.color.text': 'color',
80
94
  'elements.button.backgroundColor': 'background-color',
95
+ 'elements.heading.color': 'color',
96
+ 'elements.heading.backgroundColor': 'background-color',
97
+ 'elements.heading.gradient': 'gradient',
81
98
  'color.gradient': 'gradient',
82
99
  'typography.fontSize': 'font-size',
83
100
  'typography.fontFamily': 'font-family',
@@ -185,7 +202,7 @@ function getValueFromPresetVariable(
185
202
  }
186
203
 
187
204
  const presetObject = findInPresetsBy(
188
- features,
205
+ features.settings,
189
206
  blockName,
190
207
  metadata.path,
191
208
  'slug',
@@ -203,8 +220,8 @@ function getValueFromPresetVariable(
203
220
 
204
221
  function getValueFromCustomVariable( features, blockName, variable, path ) {
205
222
  const result =
206
- get( features, [ 'blocks', blockName, 'custom', ...path ] ) ??
207
- get( features, [ 'custom', ...path ] );
223
+ get( features.settings, [ 'blocks', blockName, 'custom', ...path ] ) ??
224
+ get( features.settings, [ 'custom', ...path ] );
208
225
  if ( ! result ) {
209
226
  return variable;
210
227
  }
@@ -212,9 +229,27 @@ function getValueFromCustomVariable( features, blockName, variable, path ) {
212
229
  return getValueFromVariable( features, blockName, result );
213
230
  }
214
231
 
232
+ /**
233
+ * Attempts to fetch the value of a theme.json CSS variable.
234
+ *
235
+ * @param {Object} features GlobalStylesContext config, e.g., user, base or merged. Represents the theme.json tree.
236
+ * @param {string} blockName The name of a block as represented in the styles property. E.g., 'root' for root-level, and 'core/${blockName}' for blocks.
237
+ * @param {string|*} variable An incoming style value. A CSS var value is expected, but it could be any value.
238
+ * @return {string|*|{ref}} The value of the CSS var, if found. If not found, the passed variable argument.
239
+ */
215
240
  export function getValueFromVariable( features, blockName, variable ) {
216
241
  if ( ! variable || typeof variable !== 'string' ) {
217
- return variable;
242
+ if ( variable?.ref && typeof variable?.ref === 'string' ) {
243
+ const refPath = variable.ref.split( '.' );
244
+ variable = get( features, refPath );
245
+ // Presence of another ref indicates a reference to another dynamic value.
246
+ // Pointing to another dynamic value is not supported.
247
+ if ( ! variable || !! variable?.ref ) {
248
+ return variable;
249
+ }
250
+ } else {
251
+ return variable;
252
+ }
218
253
  }
219
254
  const USER_VALUE_PREFIX = 'var:';
220
255
  const THEME_VALUE_PREFIX = 'var(--wp--';
@@ -255,3 +290,34 @@ export function getValueFromVariable( features, blockName, variable ) {
255
290
  }
256
291
  return variable;
257
292
  }
293
+
294
+ /**
295
+ * Function that scopes a selector with another one. This works a bit like
296
+ * SCSS nesting except the `&` operator isn't supported.
297
+ *
298
+ * @example
299
+ * ```js
300
+ * const scope = '.a, .b .c';
301
+ * const selector = '> .x, .y';
302
+ * const merged = scopeSelector( scope, selector );
303
+ * // merged is '.a > .x, .a .y, .b .c > .x, .b .c .y'
304
+ * ```
305
+ *
306
+ * @param {string} scope Selector to scope to.
307
+ * @param {string} selector Original selector.
308
+ *
309
+ * @return {string} Scoped selector.
310
+ */
311
+ export function scopeSelector( scope, selector ) {
312
+ const scopes = scope.split( ',' );
313
+ const selectors = selector.split( ',' );
314
+
315
+ const selectorsScoped = [];
316
+ scopes.forEach( ( outer ) => {
317
+ selectors.forEach( ( inner ) => {
318
+ selectorsScoped.push( `${ outer.trim() } ${ inner.trim() }` );
319
+ } );
320
+ } );
321
+
322
+ return selectorsScoped.join( ', ' );
323
+ }
@@ -141,6 +141,9 @@ export default function DocumentActions( {
141
141
  aria-expanded={ isOpen }
142
142
  aria-haspopup="true"
143
143
  onClick={ onToggle }
144
+ variant={
145
+ showIconLabels ? 'tertiary' : undefined
146
+ }
144
147
  label={ sprintf(
145
148
  /* translators: %s: the entity to see details about, like "template"*/
146
149
  __( 'Show %s details' ),