@wordpress/edit-site 4.11.0 → 4.12.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 (127) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +4 -2
  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 +22 -2
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +152 -28
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/global-styles/dimensions-panel.js +6 -2
  9. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  10. package/build/components/global-styles/hooks.js +1 -1
  11. package/build/components/global-styles/hooks.js.map +1 -1
  12. package/build/components/global-styles/screen-color-palette.js +1 -1
  13. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  14. package/build/components/global-styles/screen-colors.js +51 -7
  15. package/build/components/global-styles/screen-colors.js.map +1 -1
  16. package/build/components/global-styles/screen-heading-color.js +157 -0
  17. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  18. package/build/components/global-styles/screen-typography-element.js +4 -0
  19. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  20. package/build/components/global-styles/screen-typography.js +5 -0
  21. package/build/components/global-styles/screen-typography.js.map +1 -1
  22. package/build/components/global-styles/typography-panel.js +73 -12
  23. package/build/components/global-styles/typography-panel.js.map +1 -1
  24. package/build/components/global-styles/typography-utils.js +217 -0
  25. package/build/components/global-styles/typography-utils.js.map +1 -0
  26. package/build/components/global-styles/ui.js +11 -0
  27. package/build/components/global-styles/ui.js.map +1 -1
  28. package/build/components/global-styles/use-global-styles-output.js +61 -40
  29. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  30. package/build/components/global-styles/utils.js +17 -2
  31. package/build/components/global-styles/utils.js.map +1 -1
  32. package/build/components/header/index.js +15 -4
  33. package/build/components/header/index.js.map +1 -1
  34. package/build/components/header/undo-redo/redo.js +2 -1
  35. package/build/components/header/undo-redo/redo.js.map +1 -1
  36. package/build/components/list/actions/index.js +1 -1
  37. package/build/components/list/actions/index.js.map +1 -1
  38. package/build/components/save-button/index.js +2 -3
  39. package/build/components/save-button/index.js.map +1 -1
  40. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  41. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  42. package/build/components/sidebar/template-card/template-actions.js +1 -1
  43. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  44. package/build/components/template-details/index.js +1 -1
  45. package/build/components/template-details/index.js.map +1 -1
  46. package/build/components/template-details/template-areas.js +1 -1
  47. package/build/components/template-details/template-areas.js.map +1 -1
  48. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  49. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  50. package/build-module/components/add-new-template/add-custom-template-modal.js +4 -2
  51. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  52. package/build-module/components/add-new-template/new-template.js +21 -3
  53. package/build-module/components/add-new-template/new-template.js.map +1 -1
  54. package/build-module/components/add-new-template/utils.js +147 -26
  55. package/build-module/components/add-new-template/utils.js.map +1 -1
  56. package/build-module/components/global-styles/dimensions-panel.js +6 -2
  57. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  58. package/build-module/components/global-styles/hooks.js +1 -1
  59. package/build-module/components/global-styles/hooks.js.map +1 -1
  60. package/build-module/components/global-styles/screen-color-palette.js +1 -1
  61. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  62. package/build-module/components/global-styles/screen-colors.js +51 -7
  63. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  64. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  65. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  66. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  67. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  68. package/build-module/components/global-styles/screen-typography.js +5 -0
  69. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  70. package/build-module/components/global-styles/typography-panel.js +74 -13
  71. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  72. package/build-module/components/global-styles/typography-utils.js +204 -0
  73. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  74. package/build-module/components/global-styles/ui.js +10 -0
  75. package/build-module/components/global-styles/ui.js.map +1 -1
  76. package/build-module/components/global-styles/use-global-styles-output.js +61 -44
  77. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  78. package/build-module/components/global-styles/utils.js +16 -2
  79. package/build-module/components/global-styles/utils.js.map +1 -1
  80. package/build-module/components/header/index.js +17 -6
  81. package/build-module/components/header/index.js.map +1 -1
  82. package/build-module/components/header/undo-redo/redo.js +3 -2
  83. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  84. package/build-module/components/list/actions/index.js +1 -1
  85. package/build-module/components/list/actions/index.js.map +1 -1
  86. package/build-module/components/save-button/index.js +3 -4
  87. package/build-module/components/save-button/index.js.map +1 -1
  88. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  89. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  90. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  91. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  92. package/build-module/components/template-details/index.js +1 -1
  93. package/build-module/components/template-details/index.js.map +1 -1
  94. package/build-module/components/template-details/template-areas.js +1 -1
  95. package/build-module/components/template-details/template-areas.js.map +1 -1
  96. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  97. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  98. package/build-style/style-rtl.css +13 -4
  99. package/build-style/style.css +13 -4
  100. package/package.json +29 -29
  101. package/src/components/add-new-template/add-custom-template-modal.js +12 -3
  102. package/src/components/add-new-template/new-template.js +40 -20
  103. package/src/components/add-new-template/utils.js +145 -16
  104. package/src/components/global-styles/dimensions-panel.js +5 -3
  105. package/src/components/global-styles/hooks.js +1 -0
  106. package/src/components/global-styles/screen-color-palette.js +1 -1
  107. package/src/components/global-styles/screen-colors.js +46 -4
  108. package/src/components/global-styles/screen-heading-color.js +201 -0
  109. package/src/components/global-styles/screen-typography-element.js +4 -0
  110. package/src/components/global-styles/screen-typography.js +6 -0
  111. package/src/components/global-styles/style.scss +13 -6
  112. package/src/components/global-styles/test/typography-utils.js +130 -0
  113. package/src/components/global-styles/test/use-global-styles-output.js +66 -3
  114. package/src/components/global-styles/typography-panel.js +85 -16
  115. package/src/components/global-styles/typography-utils.js +228 -0
  116. package/src/components/global-styles/ui.js +13 -0
  117. package/src/components/global-styles/use-global-styles-output.js +79 -48
  118. package/src/components/global-styles/utils.js +10 -0
  119. package/src/components/header/index.js +28 -3
  120. package/src/components/header/undo-redo/redo.js +6 -2
  121. package/src/components/list/actions/index.js +3 -1
  122. package/src/components/save-button/index.js +10 -13
  123. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  124. package/src/components/sidebar/template-card/template-actions.js +3 -1
  125. package/src/components/template-details/index.js +3 -1
  126. package/src/components/template-details/template-areas.js +3 -1
  127. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
@@ -0,0 +1,228 @@
1
+ /**
2
+ * The fluid utilities must match the backend equivalent.
3
+ * See: gutenberg_get_typography_font_size_value() in lib/block-supports/typography.php
4
+ * ---------------------------------------------------------------
5
+ */
6
+
7
+ /**
8
+ * Returns a font-size value based on a given font-size preset.
9
+ * Takes into account fluid typography parameters and attempts to return a css formula depending on available, valid values.
10
+ *
11
+ * @param {Object} preset
12
+ * @param {string} preset.size A default font size.
13
+ * @param {string} preset.name A font size name, displayed in the UI.
14
+ * @param {string} preset.slug A font size slug.
15
+ * @param {Object} preset.fluid
16
+ * @param {string|undefined} preset.fluid.max A maximum font size value.
17
+ * @param {string|undefined} preset.fluid.min A minimum font size value.
18
+ * @param {Object} typographySettings
19
+ * @param {boolean} typographySettings.fluid Whether fluid typography is enabled.
20
+ *
21
+ * @return {string} An font-size value
22
+ */
23
+ export function getTypographyFontSizeValue( preset, typographySettings ) {
24
+ const { size: defaultSize } = preset;
25
+
26
+ if ( true !== typographySettings?.fluid ) {
27
+ return defaultSize;
28
+ }
29
+
30
+ // Defaults.
31
+ const DEFAULT_MAXIMUM_VIEWPORT_WIDTH = '1600px';
32
+ const DEFAULT_MINIMUM_VIEWPORT_WIDTH = '768px';
33
+ const DEFAULT_MINIMUM_FONT_SIZE_FACTOR = 0.75;
34
+ const DEFAULT_MAXIMUM_FONT_SIZE_FACTOR = 1.5;
35
+ const DEFAULT_SCALE_FACTOR = 1;
36
+
37
+ // Font sizes.
38
+ // A font size has explicitly bypassed fluid calculations.
39
+ if ( false === preset?.fluid ) {
40
+ return defaultSize;
41
+ }
42
+
43
+ const fluidFontSizeSettings = preset?.fluid || {};
44
+
45
+ // Try to grab explicit min and max fluid font sizes.
46
+ let minimumFontSizeRaw = fluidFontSizeSettings?.min;
47
+ let maximumFontSizeRaw = fluidFontSizeSettings?.max;
48
+ const preferredSize = getTypographyValueAndUnit( defaultSize );
49
+
50
+ // Protect against unsupported units.
51
+ if ( ! preferredSize?.unit ) {
52
+ return defaultSize;
53
+ }
54
+
55
+ // If no fluid min or max font sizes are available, create some using min/max font size factors.
56
+ if ( ! minimumFontSizeRaw ) {
57
+ minimumFontSizeRaw =
58
+ preferredSize.value * DEFAULT_MINIMUM_FONT_SIZE_FACTOR +
59
+ preferredSize.unit;
60
+ }
61
+
62
+ if ( ! maximumFontSizeRaw ) {
63
+ maximumFontSizeRaw =
64
+ preferredSize.value * DEFAULT_MAXIMUM_FONT_SIZE_FACTOR +
65
+ preferredSize.unit;
66
+ }
67
+
68
+ const fluidFontSizeValue = getComputedFluidTypographyValue( {
69
+ maximumViewPortWidth: DEFAULT_MAXIMUM_VIEWPORT_WIDTH,
70
+ minimumViewPortWidth: DEFAULT_MINIMUM_VIEWPORT_WIDTH,
71
+ maximumFontSize: maximumFontSizeRaw,
72
+ minimumFontSize: minimumFontSizeRaw,
73
+ scaleFactor: DEFAULT_SCALE_FACTOR,
74
+ } );
75
+
76
+ if ( !! fluidFontSizeValue ) {
77
+ return fluidFontSizeValue;
78
+ }
79
+
80
+ return defaultSize;
81
+ }
82
+
83
+ /**
84
+ * Internal implementation of clamp() based on available min/max viewport width, and min/max font sizes.
85
+ *
86
+ * @param {Object} args
87
+ * @param {string} args.maximumViewPortWidth Maximum size up to which type will have fluidity.
88
+ * @param {string} args.minimumViewPortWidth Minimum viewport size from which type will have fluidity.
89
+ * @param {string} args.maximumFontSize Maximum font size for any clamp() calculation.
90
+ * @param {string} args.minimumFontSize Minimum font size for any clamp() calculation.
91
+ * @param {number} args.scaleFactor A scale factor to determine how fast a font scales within boundaries.
92
+ *
93
+ * @return {string|null} A font-size value using clamp().
94
+ */
95
+ export function getComputedFluidTypographyValue( {
96
+ maximumViewPortWidth,
97
+ minimumViewPortWidth,
98
+ maximumFontSize,
99
+ minimumFontSize,
100
+ scaleFactor,
101
+ } ) {
102
+ // Grab the minimum font size and normalize it in order to use the value for calculations.
103
+ const minimumFontSizeParsed = getTypographyValueAndUnit( minimumFontSize );
104
+
105
+ // We get a 'preferred' unit to keep units consistent when calculating,
106
+ // otherwise the result will not be accurate.
107
+ const fontSizeUnit = minimumFontSizeParsed?.unit || 'rem';
108
+
109
+ // Grab the maximum font size and normalize it in order to use the value for calculations.
110
+ const maximumFontSizeParsed = getTypographyValueAndUnit( maximumFontSize, {
111
+ coerceTo: fontSizeUnit,
112
+ } );
113
+
114
+ // Protect against unsupported units.
115
+ if ( ! minimumFontSizeParsed || ! maximumFontSizeParsed ) {
116
+ return null;
117
+ }
118
+
119
+ // Use rem for accessible fluid target font scaling.
120
+ const minimumFontSizeRem = getTypographyValueAndUnit( minimumFontSize, {
121
+ coerceTo: 'rem',
122
+ } );
123
+
124
+ // Viewport widths defined for fluid typography. Normalize units
125
+ const maximumViewPortWidthParsed = getTypographyValueAndUnit(
126
+ maximumViewPortWidth,
127
+ { coerceTo: fontSizeUnit }
128
+ );
129
+ const minumumViewPortWidthParsed = getTypographyValueAndUnit(
130
+ minimumViewPortWidth,
131
+ { coerceTo: fontSizeUnit }
132
+ );
133
+
134
+ // Protect against unsupported units.
135
+ if (
136
+ ! maximumViewPortWidthParsed ||
137
+ ! minumumViewPortWidthParsed ||
138
+ ! minimumFontSizeRem
139
+ ) {
140
+ return null;
141
+ }
142
+
143
+ // Build CSS rule.
144
+ // Borrowed from https://websemantics.uk/tools/responsive-font-calculator/.
145
+ const minViewPortWidthOffsetValue = roundToPrecision(
146
+ minumumViewPortWidthParsed.value / 100,
147
+ 3
148
+ );
149
+
150
+ const viewPortWidthOffset = minViewPortWidthOffsetValue + fontSizeUnit;
151
+ let linearFactor =
152
+ 100 *
153
+ ( ( maximumFontSizeParsed.value - minimumFontSizeParsed.value ) /
154
+ ( maximumViewPortWidthParsed.value -
155
+ minumumViewPortWidthParsed.value ) );
156
+ linearFactor = roundToPrecision( linearFactor, 3 ) || 1;
157
+ const linearFactorScaled = linearFactor * scaleFactor;
158
+ const fluidTargetFontSize = `${ minimumFontSizeRem.value }${ minimumFontSizeRem.unit } + ((1vw - ${ viewPortWidthOffset }) * ${ linearFactorScaled })`;
159
+
160
+ return `clamp(${ minimumFontSize }, ${ fluidTargetFontSize }, ${ maximumFontSize })`;
161
+ }
162
+
163
+ /**
164
+ *
165
+ * @param {string} rawValue Raw size value from theme.json.
166
+ * @param {Object|undefined} options Calculation options.
167
+ *
168
+ * @return {{ unit: string, value: number }|null} An object consisting of `'value'` and `'unit'` properties.
169
+ */
170
+ export function getTypographyValueAndUnit( rawValue, options = {} ) {
171
+ if ( ! rawValue ) {
172
+ return null;
173
+ }
174
+
175
+ const { coerceTo, rootSizeValue, acceptableUnits } = {
176
+ coerceTo: '',
177
+ // Default browser font size. Later we could inject some JS to compute this `getComputedStyle( document.querySelector( "html" ) ).fontSize`.
178
+ rootSizeValue: 16,
179
+ acceptableUnits: [ 'rem', 'px', 'em' ],
180
+ ...options,
181
+ };
182
+
183
+ const acceptableUnitsGroup = acceptableUnits?.join( '|' );
184
+ const regexUnits = new RegExp(
185
+ `^(\\d*\\.?\\d+)(${ acceptableUnitsGroup }){1,1}$`
186
+ );
187
+
188
+ const matches = rawValue.match( regexUnits );
189
+
190
+ // We need a number value and a unit.
191
+ if ( ! matches || matches.length < 3 ) {
192
+ return null;
193
+ }
194
+
195
+ let [ , value, unit ] = matches;
196
+
197
+ let returnValue = parseFloat( value );
198
+
199
+ if ( 'px' === coerceTo && ( 'em' === unit || 'rem' === unit ) ) {
200
+ returnValue = returnValue * rootSizeValue;
201
+ unit = coerceTo;
202
+ }
203
+
204
+ if ( 'px' === unit && ( 'em' === coerceTo || 'rem' === coerceTo ) ) {
205
+ returnValue = returnValue / rootSizeValue;
206
+ unit = coerceTo;
207
+ }
208
+
209
+ return {
210
+ value: returnValue,
211
+ unit,
212
+ };
213
+ }
214
+
215
+ /**
216
+ * Returns a value rounded to defined precision.
217
+ * Returns `undefined` if the value is not a valid finite number.
218
+ *
219
+ * @param {number} value Raw value.
220
+ * @param {number} digits The number of digits to appear after the decimal point
221
+ *
222
+ * @return {number|undefined} Value rounded to standard precision.
223
+ */
224
+ export function roundToPrecision( value, digits = 3 ) {
225
+ return Number.isFinite( value )
226
+ ? parseFloat( value.toFixed( digits ) )
227
+ : undefined;
228
+ }
@@ -20,6 +20,7 @@ import ScreenColorPalette from './screen-color-palette';
20
20
  import ScreenBackgroundColor from './screen-background-color';
21
21
  import ScreenTextColor from './screen-text-color';
22
22
  import ScreenLinkColor from './screen-link-color';
23
+ import ScreenHeadingColor from './screen-heading-color';
23
24
  import ScreenButtonColor from './screen-button-color';
24
25
  import ScreenLayout from './screen-layout';
25
26
  import ScreenStyleVariations from './screen-style-variations';
@@ -59,6 +60,12 @@ function ContextScreens( { name } ) {
59
60
  <ScreenTypographyElement name={ name } element="link" />
60
61
  </GlobalStylesNavigationScreen>
61
62
 
63
+ <GlobalStylesNavigationScreen
64
+ path={ parentMenu + '/typography/heading' }
65
+ >
66
+ <ScreenTypographyElement name={ name } element="heading" />
67
+ </GlobalStylesNavigationScreen>
68
+
62
69
  <GlobalStylesNavigationScreen
63
70
  path={ parentMenu + '/typography/button' }
64
71
  >
@@ -89,6 +96,12 @@ function ContextScreens( { name } ) {
89
96
  <ScreenLinkColor name={ name } />
90
97
  </GlobalStylesNavigationScreen>
91
98
 
99
+ <GlobalStylesNavigationScreen
100
+ path={ parentMenu + '/colors/heading' }
101
+ >
102
+ <ScreenHeadingColor name={ name } />
103
+ </GlobalStylesNavigationScreen>
104
+
92
105
  <GlobalStylesNavigationScreen
93
106
  path={ parentMenu + '/colors/button' }
94
107
  >
@@ -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,11 +20,13 @@ 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
  /**
@@ -48,7 +49,7 @@ function compileStyleValue( uncompiledValue ) {
48
49
  const VARIABLE_REFERENCE_PREFIX = 'var:';
49
50
  const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
50
51
  const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
51
- if ( startsWith( uncompiledValue, VARIABLE_REFERENCE_PREFIX ) ) {
52
+ if ( uncompiledValue?.startsWith( VARIABLE_REFERENCE_PREFIX ) ) {
52
53
  const variable = uncompiledValue
53
54
  .slice( VARIABLE_REFERENCE_PREFIX.length )
54
55
  .split( VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE )
@@ -62,10 +63,11 @@ function compileStyleValue( uncompiledValue ) {
62
63
  * Transform given preset tree into a set of style declarations.
63
64
  *
64
65
  * @param {Object} blockPresets
66
+ * @param {Object} mergedSettings Merged theme.json settings.
65
67
  *
66
- * @return {Array} An array of style declarations.
68
+ * @return {Array<Object>} An array of style declarations.
67
69
  */
68
- function getPresetsDeclarations( blockPresets = {} ) {
70
+ function getPresetsDeclarations( blockPresets = {}, mergedSettings ) {
69
71
  return reduce(
70
72
  PRESET_METADATA,
71
73
  ( declarations, { path, valueKey, valueFunc, cssVarInfix } ) => {
@@ -73,7 +75,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
73
75
  [ 'default', 'theme', 'custom' ].forEach( ( origin ) => {
74
76
  if ( presetByOrigin[ origin ] ) {
75
77
  presetByOrigin[ origin ].forEach( ( value ) => {
76
- if ( valueKey ) {
78
+ if ( valueKey && ! valueFunc ) {
77
79
  declarations.push(
78
80
  `--wp--preset--${ cssVarInfix }--${ kebabCase(
79
81
  value.slug
@@ -86,7 +88,7 @@ function getPresetsDeclarations( blockPresets = {} ) {
86
88
  declarations.push(
87
89
  `--wp--preset--${ cssVarInfix }--${ kebabCase(
88
90
  value.slug
89
- ) }: ${ valueFunc( value ) }`
91
+ ) }: ${ valueFunc( value, mergedSettings ) }`
90
92
  );
91
93
  }
92
94
  } );
@@ -189,7 +191,7 @@ function flattenTree( input = {}, prefix, token ) {
189
191
  *
190
192
  * @return {Array} An array of style declarations.
191
193
  */
192
- function getStylesDeclarations(
194
+ export function getStylesDeclarations(
193
195
  blockStyles = {},
194
196
  selector = '',
195
197
  useRootPaddingAlign
@@ -208,6 +210,15 @@ function getStylesDeclarations(
208
210
 
209
211
  const styleValue = get( blockStyles, pathToValue );
210
212
 
213
+ // Root-level padding styles don't currently support strings with CSS shorthand values.
214
+ // This may change: https://github.com/WordPress/gutenberg/issues/40132.
215
+ if (
216
+ key === '--wp--style--root--padding' &&
217
+ ( typeof styleValue === 'string' || ! useRootPaddingAlign )
218
+ ) {
219
+ return declarations;
220
+ }
221
+
211
222
  if ( !! properties && typeof styleValue !== 'string' ) {
212
223
  Object.entries( properties ).forEach( ( entry ) => {
213
224
  const [ name, prop ] = entry;
@@ -227,13 +238,6 @@ function getStylesDeclarations(
227
238
  ) }`
228
239
  );
229
240
  } );
230
- } else if (
231
- key === '--wp--style--root--padding' &&
232
- typeof styleValue === 'string'
233
- ) {
234
- // Root-level padding styles don't currently support strings with CSS shorthand values.
235
- // This may change: https://github.com/WordPress/gutenberg/issues/40132.
236
- return declarations;
237
241
  } else if ( get( blockStyles, pathToValue, false ) ) {
238
242
  const cssProperty = key.startsWith( '--' )
239
243
  ? key
@@ -250,14 +254,18 @@ function getStylesDeclarations(
250
254
  []
251
255
  );
252
256
 
253
- if ( isRoot && useRootPaddingAlign ) {
254
- return output;
255
- }
256
-
257
257
  // The goal is to move everything to server side generated engine styles
258
258
  // This is temporary as we absorb more and more styles into the engine.
259
259
  const extraRules = getCSSRules( blockStyles );
260
260
  extraRules.forEach( ( rule ) => {
261
+ // Don't output padding properties if padding variables are set.
262
+ if (
263
+ isRoot &&
264
+ useRootPaddingAlign &&
265
+ rule.key.startsWith( 'padding' )
266
+ ) {
267
+ return;
268
+ }
261
269
  const cssProperty = rule.key.startsWith( '--' )
262
270
  ? rule.key
263
271
  : kebabCase( rule.key );
@@ -328,14 +336,28 @@ export function getLayoutStyles( {
328
336
  }
329
337
 
330
338
  if ( declarations.length ) {
331
- const combinedSelector =
332
- selector === ROOT_BLOCK_SELECTOR
333
- ? `${ selector } .${ className }${
334
- spacingStyle?.selector || ''
335
- }`
336
- : `${ selector }.${ className }${
337
- spacingStyle?.selector || ''
338
- }`;
339
+ let combinedSelector = '';
340
+
341
+ if ( ! hasBlockGapSupport ) {
342
+ // For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
343
+ combinedSelector =
344
+ selector === ROOT_BLOCK_SELECTOR
345
+ ? `:where(.${ className }${
346
+ spacingStyle?.selector || ''
347
+ })`
348
+ : `:where(${ selector }.${ className }${
349
+ spacingStyle?.selector || ''
350
+ })`;
351
+ } else {
352
+ combinedSelector =
353
+ selector === ROOT_BLOCK_SELECTOR
354
+ ? `${ selector } .${ className }${
355
+ spacingStyle?.selector || ''
356
+ }`
357
+ : `${ selector }.${ className }${
358
+ spacingStyle?.selector || ''
359
+ }`;
360
+ }
339
361
  ruleset += `${ combinedSelector } { ${ declarations.join(
340
362
  '; '
341
363
  ) }; }`;
@@ -418,11 +440,12 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
418
440
  selector: ROOT_BLOCK_SELECTOR,
419
441
  } );
420
442
  }
421
- forEach( tree.styles?.elements, ( value, key ) => {
422
- if ( !! value && !! ELEMENTS[ key ] ) {
443
+
444
+ forEach( ELEMENTS, ( selector, name ) => {
445
+ if ( !! tree.styles?.elements[ name ] ) {
423
446
  nodes.push( {
424
- styles: value,
425
- selector: ELEMENTS[ key ],
447
+ styles: tree.styles?.elements[ name ],
448
+ selector,
426
449
  } );
427
450
  }
428
451
  } );
@@ -515,10 +538,9 @@ export const getNodesWithSettings = ( tree, blockSelectors ) => {
515
538
 
516
539
  export const toCustomProperties = ( tree, blockSelectors ) => {
517
540
  const settings = getNodesWithSettings( tree, blockSelectors );
518
-
519
541
  let ruleset = '';
520
542
  settings.forEach( ( { presets, custom, selector } ) => {
521
- const declarations = getPresetsDeclarations( presets );
543
+ const declarations = getPresetsDeclarations( presets, tree?.settings );
522
544
  const customProps = flattenTree( custom, '--wp--custom--', '--' );
523
545
  if ( customProps.length > 0 ) {
524
546
  declarations.push( ...customProps );
@@ -536,7 +558,8 @@ export const toStyles = (
536
558
  tree,
537
559
  blockSelectors,
538
560
  hasBlockGapSupport,
539
- hasFallbackGapSupport
561
+ hasFallbackGapSupport,
562
+ disableLayoutStyles = false
540
563
  ) => {
541
564
  const nodesWithStyles = getNodesWithStyles( tree, blockSelectors );
542
565
  const nodesWithSettings = getNodesWithSettings( tree, blockSelectors );
@@ -612,7 +635,10 @@ export const toStyles = (
612
635
  }
613
636
 
614
637
  // Process blockGap and layout styles.
615
- if ( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport ) {
638
+ if (
639
+ ! disableLayoutStyles &&
640
+ ( ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport )
641
+ ) {
616
642
  ruleset += getLayoutStyles( {
617
643
  tree,
618
644
  style: styles,
@@ -762,17 +788,18 @@ export const getBlockSelectors = ( blockTypes ) => {
762
788
  };
763
789
 
764
790
  export function useGlobalStylesOutput() {
765
- const [ stylesheets, setStylesheets ] = useState( [] );
766
- const [ settings, setSettings ] = useState( {} );
767
- const [ svgFilters, setSvgFilters ] = useState( {} );
768
791
  const { merged: mergedConfig } = useContext( GlobalStylesContext );
769
792
  const [ blockGap ] = useSetting( 'spacing.blockGap' );
770
793
  const hasBlockGapSupport = blockGap !== null;
771
794
  const hasFallbackGapSupport = ! hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
795
+ const disableLayoutStyles = useSelect( ( select ) => {
796
+ const { getSettings } = select( blockEditorStore );
797
+ return !! getSettings().disableLayoutStyles;
798
+ } );
772
799
 
773
- useEffect( () => {
800
+ return useMemo( () => {
774
801
  if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
775
- return;
802
+ return [];
776
803
  }
777
804
 
778
805
  const blockSelectors = getBlockSelectors( getBlockTypes() );
@@ -784,10 +811,11 @@ export function useGlobalStylesOutput() {
784
811
  mergedConfig,
785
812
  blockSelectors,
786
813
  hasBlockGapSupport,
787
- hasFallbackGapSupport
814
+ hasFallbackGapSupport,
815
+ disableLayoutStyles
788
816
  );
789
817
  const filters = toSvgFilters( mergedConfig, blockSelectors );
790
- setStylesheets( [
818
+ const stylesheets = [
791
819
  {
792
820
  css: customProperties,
793
821
  isGlobalStyles: true,
@@ -796,10 +824,13 @@ export function useGlobalStylesOutput() {
796
824
  css: globalStyles,
797
825
  isGlobalStyles: true,
798
826
  },
799
- ] );
800
- setSettings( mergedConfig.settings );
801
- setSvgFilters( filters );
802
- }, [ hasBlockGapSupport, hasFallbackGapSupport, mergedConfig ] );
803
-
804
- return [ stylesheets, settings, svgFilters, hasBlockGapSupport ];
827
+ ];
828
+
829
+ return [ stylesheets, mergedConfig.settings, filters ];
830
+ }, [
831
+ hasBlockGapSupport,
832
+ hasFallbackGapSupport,
833
+ mergedConfig,
834
+ disableLayoutStyles,
835
+ ] );
805
836
  }
@@ -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' } ],
@@ -78,6 +85,9 @@ const STYLE_PATH_TO_CSS_VAR_INFIX = {
78
85
  'elements.link.color.text': 'color',
79
86
  'elements.button.color.text': 'color',
80
87
  'elements.button.backgroundColor': 'background-color',
88
+ 'elements.heading.color': 'color',
89
+ 'elements.heading.backgroundColor': 'background-color',
90
+ 'elements.heading.gradient': 'gradient',
81
91
  'color.gradient': 'gradient',
82
92
  'typography.fontSize': 'font-size',
83
93
  'typography.fontFamily': 'font-family',
@@ -11,8 +11,14 @@ import {
11
11
  import { useSelect, useDispatch } from '@wordpress/data';
12
12
  import { PinnedItems } from '@wordpress/interface';
13
13
  import { _x, __ } from '@wordpress/i18n';
14
- import { listView, plus } from '@wordpress/icons';
15
- import { Button, ToolbarItem } from '@wordpress/components';
14
+ import { listView, plus, external } from '@wordpress/icons';
15
+ import {
16
+ Button,
17
+ ToolbarItem,
18
+ MenuGroup,
19
+ MenuItem,
20
+ VisuallyHidden,
21
+ } from '@wordpress/components';
16
22
  import { store as keyboardShortcutsStore } from '@wordpress/keyboard-shortcuts';
17
23
  import { store as editorStore } from '@wordpress/editor';
18
24
  import { store as coreStore } from '@wordpress/core-data';
@@ -48,6 +54,7 @@ export default function Header( {
48
54
  listViewShortcut,
49
55
  isLoaded,
50
56
  isVisualMode,
57
+ settings,
51
58
  } = useSelect( ( select ) => {
52
59
  const {
53
60
  __experimentalGetPreviewDeviceType,
@@ -56,6 +63,7 @@ export default function Header( {
56
63
  isInserterOpened,
57
64
  isListViewOpened,
58
65
  getEditorMode,
66
+ getSettings,
59
67
  } = select( editSiteStore );
60
68
  const { getEditedEntityRecord } = select( coreStore );
61
69
  const { __experimentalGetTemplateInfo: getTemplateInfo } =
@@ -79,6 +87,7 @@ export default function Header( {
79
87
  'core/edit-site/toggle-list-view'
80
88
  ),
81
89
  isVisualMode: getEditorMode() === 'visual',
90
+ settings: getSettings(),
82
91
  };
83
92
  }, [] );
84
93
 
@@ -200,7 +209,23 @@ export default function Header( {
200
209
  <PreviewOptions
201
210
  deviceType={ deviceType }
202
211
  setDeviceType={ setPreviewDeviceType }
203
- />
212
+ >
213
+ <MenuGroup>
214
+ <MenuItem
215
+ href={ settings?.siteUrl }
216
+ target="_blank"
217
+ icon={ external }
218
+ >
219
+ { __( 'View site' ) }
220
+ <VisuallyHidden as="span">
221
+ {
222
+ /* translators: accessibility text */
223
+ __( '(opens in a new tab)' )
224
+ }
225
+ </VisuallyHidden>
226
+ </MenuItem>
227
+ </MenuGroup>
228
+ </PreviewOptions>
204
229
  ) }
205
230
  <SaveButton
206
231
  openEntitiesSavedStates={ openEntitiesSavedStates }
@@ -5,11 +5,15 @@ import { __, isRTL } from '@wordpress/i18n';
5
5
  import { Button } from '@wordpress/components';
6
6
  import { useSelect, useDispatch } from '@wordpress/data';
7
7
  import { redo as redoIcon, undo as undoIcon } from '@wordpress/icons';
8
- import { displayShortcut } from '@wordpress/keycodes';
8
+ import { displayShortcut, isAppleOS } from '@wordpress/keycodes';
9
9
  import { store as coreStore } from '@wordpress/core-data';
10
10
  import { forwardRef } from '@wordpress/element';
11
11
 
12
12
  function RedoButton( props, ref ) {
13
+ const shortcut = isAppleOS()
14
+ ? displayShortcut.primaryShift( 'z' )
15
+ : displayShortcut.primary( 'y' );
16
+
13
17
  const hasRedo = useSelect(
14
18
  ( select ) => select( coreStore ).hasRedo(),
15
19
  []
@@ -21,7 +25,7 @@ function RedoButton( props, ref ) {
21
25
  ref={ ref }
22
26
  icon={ ! isRTL() ? redoIcon : undoIcon }
23
27
  label={ __( 'Redo' ) }
24
- shortcut={ displayShortcut.primaryShift( 'z' ) }
28
+ shortcut={ shortcut }
25
29
  // If there are no undo levels we don't want to actually disable this
26
30
  // button, because it will remove focus for keyboard users.
27
31
  // See: https://github.com/WordPress/gutenberg/issues/3486
@@ -79,7 +79,9 @@ export default function Actions( { template } ) {
79
79
  ) }
80
80
  { isRevertable && (
81
81
  <MenuItem
82
- info={ __( 'Restore to default state' ) }
82
+ info={ __(
83
+ 'Use the template as supplied by the theme.'
84
+ ) }
83
85
  onClick={ () => {
84
86
  revertAndSaveTemplate();
85
87
  onClose();
@@ -30,18 +30,15 @@ export default function SaveButton( {
30
30
  const disabled = ! isDirty || isSaving;
31
31
 
32
32
  return (
33
- <>
34
- <Button
35
- variant="primary"
36
- className="edit-site-save-button__button"
37
- aria-disabled={ disabled }
38
- aria-expanded={ isEntitiesSavedStatesOpen }
39
- disabled={ disabled }
40
- isBusy={ isSaving }
41
- onClick={ disabled ? undefined : openEntitiesSavedStates }
42
- >
43
- { __( 'Save' ) }
44
- </Button>
45
- </>
33
+ <Button
34
+ variant="primary"
35
+ className="edit-site-save-button__button"
36
+ aria-disabled={ disabled }
37
+ aria-expanded={ isEntitiesSavedStatesOpen }
38
+ isBusy={ isSaving }
39
+ onClick={ disabled ? undefined : openEntitiesSavedStates }
40
+ >
41
+ { __( 'Save' ) }
42
+ </Button>
46
43
  );
47
44
  }