@wordpress/edit-site 4.8.0 → 4.11.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 +6 -0
  2. package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
  3. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  4. package/build/components/add-new-template/add-custom-template-modal.js +204 -0
  5. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -0
  6. package/build/components/add-new-template/new-template.js +91 -33
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/add-new-template/utils.js +532 -0
  9. package/build/components/add-new-template/utils.js.map +1 -0
  10. package/build/components/block-editor/index.js +1 -3
  11. package/build/components/block-editor/index.js.map +1 -1
  12. package/build/components/code-editor/index.js +17 -4
  13. package/build/components/code-editor/index.js.map +1 -1
  14. package/build/components/editor/index.js +16 -0
  15. package/build/components/editor/index.js.map +1 -1
  16. package/build/components/error-boundary/index.js +6 -0
  17. package/build/components/error-boundary/index.js.map +1 -1
  18. package/build/components/global-styles/context-menu.js +6 -3
  19. package/build/components/global-styles/context-menu.js.map +1 -1
  20. package/build/components/global-styles/dimensions-panel.js +185 -19
  21. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  22. package/build/components/global-styles/global-styles-provider.js +4 -2
  23. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  24. package/build/components/global-styles/hooks.js +11 -2
  25. package/build/components/global-styles/hooks.js.map +1 -1
  26. package/build/components/global-styles/palette.js +2 -1
  27. package/build/components/global-styles/palette.js.map +1 -1
  28. package/build/components/global-styles/screen-block-list.js +4 -1
  29. package/build/components/global-styles/screen-block-list.js.map +1 -1
  30. package/build/components/global-styles/screen-button-color.js +80 -0
  31. package/build/components/global-styles/screen-button-color.js.map +1 -0
  32. package/build/components/global-styles/screen-color-palette.js +13 -17
  33. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  34. package/build/components/global-styles/screen-colors.js +56 -8
  35. package/build/components/global-styles/screen-colors.js.map +1 -1
  36. package/build/components/global-styles/screen-link-color.js +48 -14
  37. package/build/components/global-styles/screen-link-color.js.map +1 -1
  38. package/build/components/global-styles/screen-root.js +4 -2
  39. package/build/components/global-styles/screen-root.js.map +1 -1
  40. package/build/components/global-styles/screen-typography-element.js +4 -0
  41. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  42. package/build/components/global-styles/screen-typography.js +9 -1
  43. package/build/components/global-styles/screen-typography.js.map +1 -1
  44. package/build/components/global-styles/ui.js +11 -0
  45. package/build/components/global-styles/ui.js.map +1 -1
  46. package/build/components/global-styles/use-global-styles-output.js +282 -35
  47. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  48. package/build/components/global-styles/utils.js +35 -2
  49. package/build/components/global-styles/utils.js.map +1 -1
  50. package/build/components/header/index.js +29 -10
  51. package/build/components/header/index.js.map +1 -1
  52. package/build/components/header/more-menu/site-export.js +4 -1
  53. package/build/components/header/more-menu/site-export.js.map +1 -1
  54. package/build/components/header/undo-redo/redo.js +13 -4
  55. package/build/components/header/undo-redo/redo.js.map +1 -1
  56. package/build/components/header/undo-redo/undo.js +13 -4
  57. package/build/components/header/undo-redo/undo.js.map +1 -1
  58. package/build/components/keyboard-shortcut-help-modal/config.js +17 -0
  59. package/build/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  60. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  61. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  62. package/build/components/sidebar/template-card/index.js +19 -7
  63. package/build/components/sidebar/template-card/index.js.map +1 -1
  64. package/build/components/sidebar/template-card/template-actions.js +64 -0
  65. package/build/components/sidebar/template-card/template-actions.js.map +1 -0
  66. package/build/components/template-details/edit-template-title.js +11 -3
  67. package/build/components/template-details/edit-template-title.js.map +1 -1
  68. package/build/components/template-details/index.js +1 -20
  69. package/build/components/template-details/index.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/store/selectors.js +4 -1
  75. package/build/store/selectors.js.map +1 -1
  76. package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
  77. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  78. package/build-module/components/add-new-template/add-custom-template-modal.js +189 -0
  79. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -0
  80. package/build-module/components/add-new-template/new-template.js +90 -34
  81. package/build-module/components/add-new-template/new-template.js.map +1 -1
  82. package/build-module/components/add-new-template/utils.js +503 -0
  83. package/build-module/components/add-new-template/utils.js.map +1 -0
  84. package/build-module/components/block-editor/index.js +1 -2
  85. package/build-module/components/block-editor/index.js.map +1 -1
  86. package/build-module/components/code-editor/index.js +18 -5
  87. package/build-module/components/code-editor/index.js.map +1 -1
  88. package/build-module/components/editor/index.js +16 -0
  89. package/build-module/components/editor/index.js.map +1 -1
  90. package/build-module/components/error-boundary/index.js +5 -0
  91. package/build-module/components/error-boundary/index.js.map +1 -1
  92. package/build-module/components/global-styles/context-menu.js +6 -3
  93. package/build-module/components/global-styles/context-menu.js.map +1 -1
  94. package/build-module/components/global-styles/dimensions-panel.js +185 -20
  95. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  96. package/build-module/components/global-styles/global-styles-provider.js +4 -2
  97. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  98. package/build-module/components/global-styles/hooks.js +11 -2
  99. package/build-module/components/global-styles/hooks.js.map +1 -1
  100. package/build-module/components/global-styles/palette.js +2 -1
  101. package/build-module/components/global-styles/palette.js.map +1 -1
  102. package/build-module/components/global-styles/screen-block-list.js +4 -1
  103. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  104. package/build-module/components/global-styles/screen-button-color.js +67 -0
  105. package/build-module/components/global-styles/screen-button-color.js.map +1 -0
  106. package/build-module/components/global-styles/screen-color-palette.js +14 -19
  107. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  108. package/build-module/components/global-styles/screen-colors.js +57 -9
  109. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  110. package/build-module/components/global-styles/screen-link-color.js +47 -14
  111. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  112. package/build-module/components/global-styles/screen-root.js +4 -2
  113. package/build-module/components/global-styles/screen-root.js.map +1 -1
  114. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  115. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  116. package/build-module/components/global-styles/screen-typography.js +10 -2
  117. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  118. package/build-module/components/global-styles/ui.js +10 -0
  119. package/build-module/components/global-styles/ui.js.map +1 -1
  120. package/build-module/components/global-styles/use-global-styles-output.js +280 -42
  121. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  122. package/build-module/components/global-styles/utils.js +34 -3
  123. package/build-module/components/global-styles/utils.js.map +1 -1
  124. package/build-module/components/header/index.js +31 -11
  125. package/build-module/components/header/index.js.map +1 -1
  126. package/build-module/components/header/more-menu/site-export.js +4 -1
  127. package/build-module/components/header/more-menu/site-export.js.map +1 -1
  128. package/build-module/components/header/undo-redo/redo.js +9 -3
  129. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  130. package/build-module/components/header/undo-redo/undo.js +9 -3
  131. package/build-module/components/header/undo-redo/undo.js.map +1 -1
  132. package/build-module/components/keyboard-shortcut-help-modal/config.js +17 -0
  133. package/build-module/components/keyboard-shortcut-help-modal/config.js.map +1 -1
  134. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
  135. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  136. package/build-module/components/sidebar/template-card/index.js +18 -7
  137. package/build-module/components/sidebar/template-card/index.js.map +1 -1
  138. package/build-module/components/sidebar/template-card/template-actions.js +49 -0
  139. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -0
  140. package/build-module/components/template-details/edit-template-title.js +12 -3
  141. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  142. package/build-module/components/template-details/index.js +2 -21
  143. package/build-module/components/template-details/index.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/store/selectors.js +5 -2
  149. package/build-module/store/selectors.js.map +1 -1
  150. package/build-style/style-rtl.css +198 -49
  151. package/build-style/style.css +198 -49
  152. package/package.json +29 -29
  153. package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
  154. package/src/components/add-new-template/add-custom-template-modal.js +247 -0
  155. package/src/components/add-new-template/new-template.js +158 -70
  156. package/src/components/add-new-template/style.scss +149 -0
  157. package/src/components/add-new-template/utils.js +538 -0
  158. package/src/components/block-editor/index.js +0 -2
  159. package/src/components/code-editor/index.js +15 -5
  160. package/src/components/editor/index.js +11 -0
  161. package/src/components/error-boundary/index.js +5 -0
  162. package/src/components/global-styles/context-menu.js +3 -0
  163. package/src/components/global-styles/dimensions-panel.js +209 -21
  164. package/src/components/global-styles/global-styles-provider.js +8 -9
  165. package/src/components/global-styles/hooks.js +18 -0
  166. package/src/components/global-styles/palette.js +4 -1
  167. package/src/components/global-styles/screen-block-list.js +10 -1
  168. package/src/components/global-styles/screen-button-color.js +102 -0
  169. package/src/components/global-styles/screen-color-palette.js +25 -27
  170. package/src/components/global-styles/screen-colors.js +58 -7
  171. package/src/components/global-styles/screen-link-color.js +65 -23
  172. package/src/components/global-styles/screen-root.js +8 -2
  173. package/src/components/global-styles/screen-typography-element.js +4 -0
  174. package/src/components/global-styles/screen-typography.js +17 -2
  175. package/src/components/global-styles/style.scss +14 -8
  176. package/src/components/global-styles/test/use-global-styles-output.js +313 -16
  177. package/src/components/global-styles/ui.js +13 -0
  178. package/src/components/global-styles/use-global-styles-output.js +344 -38
  179. package/src/components/global-styles/utils.js +36 -2
  180. package/src/components/header/index.js +42 -17
  181. package/src/components/header/more-menu/site-export.js +3 -0
  182. package/src/components/header/style.scss +58 -8
  183. package/src/components/header/undo-redo/redo.js +6 -1
  184. package/src/components/header/undo-redo/undo.js +6 -1
  185. package/src/components/keyboard-shortcut-help-modal/config.js +12 -0
  186. package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
  187. package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
  188. package/src/components/list/style.scss +0 -8
  189. package/src/components/sidebar/style.scss +4 -0
  190. package/src/components/sidebar/template-card/index.js +15 -6
  191. package/src/components/sidebar/template-card/style.scss +49 -35
  192. package/src/components/sidebar/template-card/template-actions.js +43 -0
  193. package/src/components/template-details/edit-template-title.js +10 -2
  194. package/src/components/template-details/index.js +4 -21
  195. package/src/components/test/error-boundary.js +38 -0
  196. package/src/hooks/index.js +1 -0
  197. package/src/hooks/template-part-edit.js +82 -0
  198. package/src/store/selectors.js +11 -5
  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
@@ -3,7 +3,7 @@ import { createElement } from "@wordpress/element";
3
3
  /**
4
4
  * External dependencies
5
5
  */
6
- import { first, forEach, get, isEmpty, isString, kebabCase, pickBy, reduce, set, startsWith } from 'lodash';
6
+ import { first, forEach, get, isEmpty, kebabCase, pickBy, reduce, set, startsWith } from 'lodash';
7
7
  /**
8
8
  * WordPress dependencies
9
9
  */
@@ -11,14 +11,22 @@ import { first, forEach, get, isEmpty, isString, kebabCase, pickBy, reduce, set,
11
11
  import { __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY, __EXPERIMENTAL_ELEMENTS as ELEMENTS, getBlockTypes } from '@wordpress/blocks';
12
12
  import { useEffect, useState, useContext } from '@wordpress/element';
13
13
  import { getCSSRules } from '@wordpress/style-engine';
14
- import { __unstablePresetDuotoneFilter as PresetDuotoneFilter } from '@wordpress/block-editor';
14
+ import { __unstablePresetDuotoneFilter as PresetDuotoneFilter, __experimentalGetGapCSSValue as getGapCSSValue } from '@wordpress/block-editor';
15
15
  /**
16
16
  * Internal dependencies
17
17
  */
18
18
 
19
- import { PRESET_METADATA, ROOT_BLOCK_SELECTOR } from './utils';
19
+ import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
20
20
  import { GlobalStylesContext } from './context';
21
- import { useSetting } from './hooks';
21
+ import { useSetting } from './hooks'; // List of block support features that can have their related styles
22
+ // generated under their own feature level selector rather than the block's.
23
+
24
+ const BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS = {
25
+ __experimentalBorder: 'border',
26
+ color: 'color',
27
+ spacing: 'spacing',
28
+ typography: 'typography'
29
+ };
22
30
 
23
31
  function compileStyleValue(uncompiledValue) {
24
32
  const VARIABLE_REFERENCE_PREFIX = 'var:';
@@ -145,7 +153,11 @@ function flattenTree() {
145
153
  /**
146
154
  * Transform given style tree into a set of style declarations.
147
155
  *
148
- * @param {Object} blockStyles Block styles.
156
+ * @param {Object} blockStyles Block styles.
157
+ *
158
+ * @param {string} selector The selector these declarations should attach to.
159
+ *
160
+ * @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
149
161
  *
150
162
  * @return {Array} An array of style declarations.
151
163
  */
@@ -153,12 +165,21 @@ function flattenTree() {
153
165
 
154
166
  function getStylesDeclarations() {
155
167
  let blockStyles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
168
+ let selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
169
+ let useRootPaddingAlign = arguments.length > 2 ? arguments[2] : undefined;
170
+ const isRoot = ROOT_BLOCK_SELECTOR === selector;
156
171
  const output = reduce(STYLE_PROPERTY, (declarations, _ref5, key) => {
157
172
  let {
158
173
  value,
159
174
  properties,
160
- useEngine
175
+ useEngine,
176
+ rootOnly
161
177
  } = _ref5;
178
+
179
+ if (rootOnly && !isRoot) {
180
+ return declarations;
181
+ }
182
+
162
183
  const pathToValue = value;
163
184
 
164
185
  if (first(pathToValue) === 'elements' || useEngine) {
@@ -167,7 +188,7 @@ function getStylesDeclarations() {
167
188
 
168
189
  const styleValue = get(blockStyles, pathToValue);
169
190
 
170
- if (!!properties && !isString(styleValue)) {
191
+ if (!!properties && typeof styleValue !== 'string') {
171
192
  Object.entries(properties).forEach(entry => {
172
193
  const [name, prop] = entry;
173
194
 
@@ -177,18 +198,27 @@ function getStylesDeclarations() {
177
198
  return;
178
199
  }
179
200
 
180
- const cssProperty = kebabCase(name);
201
+ const cssProperty = name.startsWith('--') ? name : kebabCase(name);
181
202
  declarations.push(`${cssProperty}: ${compileStyleValue(get(styleValue, [prop]))}`);
182
203
  });
204
+ } else if (key === '--wp--style--root--padding' && typeof styleValue === 'string') {
205
+ // Root-level padding styles don't currently support strings with CSS shorthand values.
206
+ // This may change: https://github.com/WordPress/gutenberg/issues/40132.
207
+ return declarations;
183
208
  } else if (get(blockStyles, pathToValue, false)) {
184
209
  const cssProperty = key.startsWith('--') ? key : kebabCase(key);
185
210
  declarations.push(`${cssProperty}: ${compileStyleValue(get(blockStyles, pathToValue))}`);
186
211
  }
187
212
 
188
213
  return declarations;
189
- }, []); // The goal is to move everything to server side generated engine styles
214
+ }, []);
215
+
216
+ if (isRoot && useRootPaddingAlign) {
217
+ return output;
218
+ } // The goal is to move everything to server side generated engine styles
190
219
  // This is temporary as we absorb more and more styles into the engine.
191
220
 
221
+
192
222
  const extraRules = getCSSRules(blockStyles);
193
223
  extraRules.forEach(rule => {
194
224
  const cssProperty = rule.key.startsWith('--') ? rule.key : kebabCase(rule.key);
@@ -196,7 +226,117 @@ function getStylesDeclarations() {
196
226
  });
197
227
  return output;
198
228
  }
229
+ /**
230
+ * Get generated CSS for layout styles by looking up layout definitions provided
231
+ * in theme.json, and outputting common layout styles, and specific blockGap values.
232
+ *
233
+ * @param {Object} props
234
+ * @param {Object} props.tree A theme.json tree containing layout definitions.
235
+ * @param {Object} props.style A style object containing spacing values.
236
+ * @param {string} props.selector Selector used to group together layout styling rules.
237
+ * @param {boolean} props.hasBlockGapSupport Whether or not the theme opts-in to blockGap support.
238
+ * @param {boolean} props.hasFallbackGapSupport Whether or not the theme allows fallback gap styles.
239
+ * @param {?string} props.fallbackGapValue An optional fallback gap value if no real gap value is available.
240
+ * @return {string} Generated CSS rules for the layout styles.
241
+ */
242
+
243
+
244
+ export function getLayoutStyles(_ref6) {
245
+ var _style$spacing, _tree$settings, _tree$settings$layout, _tree$settings2, _tree$settings2$layou;
246
+
247
+ let {
248
+ tree,
249
+ style,
250
+ selector,
251
+ hasBlockGapSupport,
252
+ hasFallbackGapSupport,
253
+ fallbackGapValue
254
+ } = _ref6;
255
+ let ruleset = '';
256
+ let gapValue = hasBlockGapSupport ? getGapCSSValue(style === null || style === void 0 ? void 0 : (_style$spacing = style.spacing) === null || _style$spacing === void 0 ? void 0 : _style$spacing.blockGap) : ''; // Ensure a fallback gap value for the root layout definitions,
257
+ // and use a fallback value if one is provided for the current block.
258
+
259
+ if (hasFallbackGapSupport) {
260
+ if (selector === ROOT_BLOCK_SELECTOR) {
261
+ gapValue = !gapValue ? '0.5em' : gapValue;
262
+ } else if (!hasBlockGapSupport && fallbackGapValue) {
263
+ gapValue = fallbackGapValue;
264
+ }
265
+ }
266
+
267
+ if (gapValue && tree !== null && tree !== void 0 && (_tree$settings = tree.settings) !== null && _tree$settings !== void 0 && (_tree$settings$layout = _tree$settings.layout) !== null && _tree$settings$layout !== void 0 && _tree$settings$layout.definitions) {
268
+ Object.values(tree.settings.layout.definitions).forEach(_ref7 => {
269
+ let {
270
+ className,
271
+ name,
272
+ spacingStyles
273
+ } = _ref7;
274
+
275
+ // Allow skipping default layout for themes that opt-in to block styles, but opt-out of blockGap.
276
+ if (!hasBlockGapSupport && 'default' === name) {
277
+ return;
278
+ }
279
+
280
+ if (spacingStyles !== null && spacingStyles !== void 0 && spacingStyles.length) {
281
+ spacingStyles.forEach(spacingStyle => {
282
+ const declarations = [];
283
+
284
+ if (spacingStyle.rules) {
285
+ Object.entries(spacingStyle.rules).forEach(_ref8 => {
286
+ let [cssProperty, cssValue] = _ref8;
287
+ declarations.push(`${cssProperty}: ${cssValue ? cssValue : gapValue}`);
288
+ });
289
+ }
290
+
291
+ if (declarations.length) {
292
+ const combinedSelector = selector === ROOT_BLOCK_SELECTOR ? `${selector} .${className}${(spacingStyle === null || spacingStyle === void 0 ? void 0 : spacingStyle.selector) || ''}` : `${selector}.${className}${(spacingStyle === null || spacingStyle === void 0 ? void 0 : spacingStyle.selector) || ''}`;
293
+ ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
294
+ }
295
+ });
296
+ }
297
+ }); // For backwards compatibility, ensure the legacy block gap CSS variable is still available.
298
+
299
+ if (selector === ROOT_BLOCK_SELECTOR && hasBlockGapSupport) {
300
+ ruleset += `${selector} { --wp--style--block-gap: ${gapValue}; }`;
301
+ }
302
+ } // Output base styles
303
+
304
+
305
+ if (selector === ROOT_BLOCK_SELECTOR && tree !== null && tree !== void 0 && (_tree$settings2 = tree.settings) !== null && _tree$settings2 !== void 0 && (_tree$settings2$layou = _tree$settings2.layout) !== null && _tree$settings2$layou !== void 0 && _tree$settings2$layou.definitions) {
306
+ const validDisplayModes = ['block', 'flex', 'grid'];
307
+ Object.values(tree.settings.layout.definitions).forEach(_ref9 => {
308
+ let {
309
+ className,
310
+ displayMode,
311
+ baseStyles
312
+ } = _ref9;
313
+
314
+ if (displayMode && validDisplayModes.includes(displayMode)) {
315
+ ruleset += `${selector} .${className} { display:${displayMode}; }`;
316
+ }
317
+
318
+ if (baseStyles !== null && baseStyles !== void 0 && baseStyles.length) {
319
+ baseStyles.forEach(baseStyle => {
320
+ const declarations = [];
321
+
322
+ if (baseStyle.rules) {
323
+ Object.entries(baseStyle.rules).forEach(_ref10 => {
324
+ let [cssProperty, cssValue] = _ref10;
325
+ declarations.push(`${cssProperty}: ${cssValue}`);
326
+ });
327
+ }
328
+
329
+ if (declarations.length) {
330
+ const combinedSelector = `${selector} .${className}${(baseStyle === null || baseStyle === void 0 ? void 0 : baseStyle.selector) || ''}`;
331
+ ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
332
+ }
333
+ });
334
+ }
335
+ });
336
+ }
199
337
 
338
+ return ruleset;
339
+ }
200
340
  export const getNodesWithStyles = (tree, blockSelectors) => {
201
341
  var _tree$styles, _tree$styles2;
202
342
 
@@ -234,9 +374,12 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
234
374
 
235
375
  if (!!blockStyles && !!(blockSelectors !== null && blockSelectors !== void 0 && (_blockSelectors$block = blockSelectors[blockName]) !== null && _blockSelectors$block !== void 0 && _blockSelectors$block.selector)) {
236
376
  nodes.push({
237
- styles: blockStyles,
377
+ duotoneSelector: blockSelectors[blockName].duotoneSelector,
378
+ fallbackGapValue: blockSelectors[blockName].fallbackGapValue,
379
+ hasLayoutSupport: blockSelectors[blockName].hasLayoutSupport,
238
380
  selector: blockSelectors[blockName].selector,
239
- duotoneSelector: blockSelectors[blockName].duotoneSelector
381
+ styles: blockStyles,
382
+ featureSelectors: blockSelectors[blockName].featureSelectors
240
383
  });
241
384
  }
242
385
 
@@ -244,7 +387,10 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
244
387
  if (!!value && !!(blockSelectors !== null && blockSelectors !== void 0 && blockSelectors[blockName]) && !!(ELEMENTS !== null && ELEMENTS !== void 0 && ELEMENTS[elementName])) {
245
388
  nodes.push({
246
389
  styles: value,
247
- selector: blockSelectors[blockName].selector.split(',').map(sel => sel + ' ' + ELEMENTS[elementName]).join(',')
390
+ selector: blockSelectors[blockName].selector.split(',').map(sel => {
391
+ const elementSelectors = ELEMENTS[elementName].split(',');
392
+ return elementSelectors.map(elementSelector => sel + ' ' + elementSelector);
393
+ }).join(',')
248
394
  });
249
395
  }
250
396
  });
@@ -252,7 +398,7 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
252
398
  return nodes;
253
399
  };
254
400
  export const getNodesWithSettings = (tree, blockSelectors) => {
255
- var _tree$settings, _tree$settings2;
401
+ var _tree$settings3, _tree$settings4;
256
402
 
257
403
  const nodes = [];
258
404
 
@@ -262,10 +408,10 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
262
408
 
263
409
  const pickPresets = treeToPickFrom => {
264
410
  const presets = {};
265
- PRESET_METADATA.forEach(_ref6 => {
411
+ PRESET_METADATA.forEach(_ref11 => {
266
412
  let {
267
413
  path
268
- } = _ref6;
414
+ } = _ref11;
269
415
  const value = get(treeToPickFrom, path, false);
270
416
 
271
417
  if (value !== false) {
@@ -277,7 +423,7 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
277
423
 
278
424
 
279
425
  const presets = pickPresets(tree.settings);
280
- const custom = (_tree$settings = tree.settings) === null || _tree$settings === void 0 ? void 0 : _tree$settings.custom;
426
+ const custom = (_tree$settings3 = tree.settings) === null || _tree$settings3 === void 0 ? void 0 : _tree$settings3.custom;
281
427
 
282
428
  if (!isEmpty(presets) || !!custom) {
283
429
  nodes.push({
@@ -288,7 +434,7 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
288
434
  } // Blocks.
289
435
 
290
436
 
291
- forEach((_tree$settings2 = tree.settings) === null || _tree$settings2 === void 0 ? void 0 : _tree$settings2.blocks, (node, blockName) => {
437
+ forEach((_tree$settings4 = tree.settings) === null || _tree$settings4 === void 0 ? void 0 : _tree$settings4.blocks, (node, blockName) => {
292
438
  const blockPresets = pickPresets(node);
293
439
  const blockCustom = node.custom;
294
440
 
@@ -305,12 +451,12 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
305
451
  export const toCustomProperties = (tree, blockSelectors) => {
306
452
  const settings = getNodesWithSettings(tree, blockSelectors);
307
453
  let ruleset = '';
308
- settings.forEach(_ref7 => {
454
+ settings.forEach(_ref12 => {
309
455
  let {
310
456
  presets,
311
457
  custom,
312
458
  selector
313
- } = _ref7;
459
+ } = _ref12;
314
460
  const declarations = getPresetsDeclarations(presets);
315
461
  const customProps = flattenTree(custom, '--wp--custom--', '--');
316
462
 
@@ -324,9 +470,12 @@ export const toCustomProperties = (tree, blockSelectors) => {
324
470
  });
325
471
  return ruleset;
326
472
  };
327
- export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
473
+ export const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) => {
474
+ var _tree$settings5;
475
+
328
476
  const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
329
477
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
478
+ const useRootPaddingAlign = tree === null || tree === void 0 ? void 0 : (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.useRootPaddingAwareAlignments;
330
479
  /*
331
480
  * Reset default browser margin on the root body element.
332
481
  * This is set on the root selector **before** generating the ruleset
@@ -337,12 +486,41 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
337
486
  */
338
487
 
339
488
  let ruleset = 'body {margin: 0;}';
340
- nodesWithStyles.forEach(_ref8 => {
489
+
490
+ if (useRootPaddingAlign) {
491
+ ruleset = 'body { margin: 0; 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); }';
492
+ }
493
+
494
+ nodesWithStyles.forEach(_ref13 => {
341
495
  let {
342
496
  selector,
343
497
  duotoneSelector,
344
- styles
345
- } = _ref8;
498
+ styles,
499
+ fallbackGapValue,
500
+ hasLayoutSupport,
501
+ featureSelectors
502
+ } = _ref13;
503
+
504
+ // Process styles for block support features with custom feature level
505
+ // CSS selectors set.
506
+ if (featureSelectors) {
507
+ Object.entries(featureSelectors).forEach(_ref14 => {
508
+ let [featureName, featureSelector] = _ref14;
509
+
510
+ if (styles !== null && styles !== void 0 && styles[featureName]) {
511
+ const featureStyles = {
512
+ [featureName]: styles[featureName]
513
+ };
514
+ const featureDeclarations = getStylesDeclarations(featureStyles);
515
+ delete styles[featureName];
516
+
517
+ if (!!featureDeclarations.length) {
518
+ ruleset = ruleset + `${featureSelector}{${featureDeclarations.join(';')} }`;
519
+ }
520
+ }
521
+ });
522
+ }
523
+
346
524
  const duotoneStyles = {};
347
525
 
348
526
  if (styles !== null && styles !== void 0 && styles.filter) {
@@ -359,16 +537,55 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
359
537
  }
360
538
 
361
539
  ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
362
- } // Process the remaning block styles (they use either normal block class or __experimentalSelector).
540
+ } // Process blockGap and layout styles.
363
541
 
364
542
 
365
- const declarations = getStylesDeclarations(styles);
543
+ if (ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport) {
544
+ ruleset += getLayoutStyles({
545
+ tree,
546
+ style: styles,
547
+ selector,
548
+ hasBlockGapSupport,
549
+ hasFallbackGapSupport,
550
+ fallbackGapValue
551
+ });
552
+ } // Process the remaining block styles (they use either normal block class or __experimentalSelector).
366
553
 
367
- if (declarations.length === 0) {
368
- return;
369
- }
370
554
 
371
- ruleset = ruleset + `${selector}{${declarations.join(';')};}`;
555
+ const declarations = getStylesDeclarations(styles, selector, useRootPaddingAlign);
556
+
557
+ if (declarations !== null && declarations !== void 0 && declarations.length) {
558
+ ruleset = ruleset + `${selector}{${declarations.join(';')};}`;
559
+ } // Check for pseudo selector in `styles` and handle separately.
560
+
561
+
562
+ const pseudoSelectorStyles = Object.entries(styles).filter(_ref15 => {
563
+ let [key] = _ref15;
564
+ return key.startsWith(':');
565
+ });
566
+
567
+ if (pseudoSelectorStyles !== null && pseudoSelectorStyles !== void 0 && pseudoSelectorStyles.length) {
568
+ pseudoSelectorStyles.forEach(_ref16 => {
569
+ let [pseudoKey, pseudoStyle] = _ref16;
570
+ const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
571
+
572
+ if (!(pseudoDeclarations !== null && pseudoDeclarations !== void 0 && pseudoDeclarations.length)) {
573
+ return;
574
+ } // `selector` maybe provided in a form
575
+ // where block level selectors have sub element
576
+ // selectors appended to them as a comma separated
577
+ // string.
578
+ // e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
579
+ // Split and append pseudo selector to create
580
+ // the proper rules to target the elements.
581
+
582
+
583
+ const _selector = selector.split(',').map(sel => sel + pseudoKey).join(',');
584
+
585
+ const pseudoRule = `${_selector}{${pseudoDeclarations.join(';')};}`;
586
+ ruleset = ruleset + pseudoRule;
587
+ });
588
+ }
372
589
  });
373
590
  /* Add alignment / layout styles */
374
591
 
@@ -377,15 +594,19 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
377
594
  ruleset = ruleset + '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
378
595
 
379
596
  if (hasBlockGapSupport) {
597
+ var _tree$styles3, _tree$styles3$spacing;
598
+
599
+ // Use fallback of `0.5em` just in case, however if there is blockGap support, there should nearly always be a real value.
600
+ const gapValue = getGapCSSValue(tree === null || tree === void 0 ? void 0 : (_tree$styles3 = tree.styles) === null || _tree$styles3 === void 0 ? void 0 : (_tree$styles3$spacing = _tree$styles3.spacing) === null || _tree$styles3$spacing === void 0 ? void 0 : _tree$styles3$spacing.blockGap) || '0.5em';
380
601
  ruleset = ruleset + '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
381
- ruleset = ruleset + '.wp-site-blocks > * + * { margin-block-start: var( --wp--style--block-gap ); }';
602
+ ruleset = ruleset + `.wp-site-blocks > * + * { margin-block-start: ${gapValue}; }`;
382
603
  }
383
604
 
384
- nodesWithSettings.forEach(_ref9 => {
605
+ nodesWithSettings.forEach(_ref17 => {
385
606
  let {
386
607
  selector,
387
608
  presets
388
- } = _ref9;
609
+ } = _ref17;
389
610
 
390
611
  if (ROOT_BLOCK_SELECTOR === selector) {
391
612
  // Do not add extra specificity for top-level classes.
@@ -402,31 +623,46 @@ export const toStyles = (tree, blockSelectors, hasBlockGapSupport) => {
402
623
  };
403
624
  export function toSvgFilters(tree, blockSelectors) {
404
625
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
405
- return nodesWithSettings.flatMap(_ref10 => {
626
+ return nodesWithSettings.flatMap(_ref18 => {
406
627
  let {
407
628
  presets
408
- } = _ref10;
629
+ } = _ref18;
409
630
  return getPresetsSvgFilters(presets);
410
631
  });
411
632
  }
412
-
413
- const getBlockSelectors = blockTypes => {
633
+ export const getBlockSelectors = blockTypes => {
414
634
  const result = {};
415
635
  blockTypes.forEach(blockType => {
416
- var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$;
636
+ var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$, _blockType$supports3, _blockType$supports4, _blockType$supports4$, _blockType$supports4$2;
417
637
 
418
638
  const name = blockType.name;
419
639
  const selector = (_blockType$supports$_ = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports = blockType.supports) === null || _blockType$supports === void 0 ? void 0 : _blockType$supports.__experimentalSelector) !== null && _blockType$supports$_ !== void 0 ? _blockType$supports$_ : '.wp-block-' + name.replace('core/', '').replace('/', '-');
420
640
  const duotoneSelector = (_blockType$supports$c = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports2 = blockType.supports) === null || _blockType$supports2 === void 0 ? void 0 : (_blockType$supports2$ = _blockType$supports2.color) === null || _blockType$supports2$ === void 0 ? void 0 : _blockType$supports2$.__experimentalDuotone) !== null && _blockType$supports$c !== void 0 ? _blockType$supports$c : null;
641
+ const hasLayoutSupport = !!(blockType !== null && blockType !== void 0 && (_blockType$supports3 = blockType.supports) !== null && _blockType$supports3 !== void 0 && _blockType$supports3.__experimentalLayout);
642
+ const fallbackGapValue = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports4 = blockType.supports) === null || _blockType$supports4 === void 0 ? void 0 : (_blockType$supports4$ = _blockType$supports4.spacing) === null || _blockType$supports4$ === void 0 ? void 0 : (_blockType$supports4$2 = _blockType$supports4$.blockGap) === null || _blockType$supports4$2 === void 0 ? void 0 : _blockType$supports4$2.__experimentalDefault; // For each block support feature add any custom selectors.
643
+
644
+ const featureSelectors = {};
645
+ Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(_ref19 => {
646
+ var _blockType$supports5, _blockType$supports5$;
647
+
648
+ let [featureKey, featureName] = _ref19;
649
+ const featureSelector = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports5 = blockType.supports) === null || _blockType$supports5 === void 0 ? void 0 : (_blockType$supports5$ = _blockType$supports5[featureKey]) === null || _blockType$supports5$ === void 0 ? void 0 : _blockType$supports5$.__experimentalSelector;
650
+
651
+ if (featureSelector) {
652
+ featureSelectors[featureName] = scopeSelector(selector, featureSelector);
653
+ }
654
+ });
421
655
  result[name] = {
656
+ duotoneSelector,
657
+ fallbackGapValue,
658
+ featureSelectors: Object.keys(featureSelectors).length ? featureSelectors : undefined,
659
+ hasLayoutSupport,
422
660
  name,
423
- selector,
424
- duotoneSelector
661
+ selector
425
662
  };
426
663
  });
427
664
  return result;
428
665
  };
429
-
430
666
  export function useGlobalStylesOutput() {
431
667
  const [stylesheets, setStylesheets] = useState([]);
432
668
  const [settings, setSettings] = useState({});
@@ -436,6 +672,8 @@ export function useGlobalStylesOutput() {
436
672
  } = useContext(GlobalStylesContext);
437
673
  const [blockGap] = useSetting('spacing.blockGap');
438
674
  const hasBlockGapSupport = blockGap !== null;
675
+ const hasFallbackGapSupport = !hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
676
+
439
677
  useEffect(() => {
440
678
  if (!(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.styles) || !(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.settings)) {
441
679
  return;
@@ -443,7 +681,7 @@ export function useGlobalStylesOutput() {
443
681
 
444
682
  const blockSelectors = getBlockSelectors(getBlockTypes());
445
683
  const customProperties = toCustomProperties(mergedConfig, blockSelectors);
446
- const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport);
684
+ const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport);
447
685
  const filters = toSvgFilters(mergedConfig, blockSelectors);
448
686
  setStylesheets([{
449
687
  css: customProperties,
@@ -454,7 +692,7 @@ export function useGlobalStylesOutput() {
454
692
  }]);
455
693
  setSettings(mergedConfig.settings);
456
694
  setSvgFilters(filters);
457
- }, [mergedConfig]);
695
+ }, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig]);
458
696
  return [stylesheets, settings, svgFilters, hasBlockGapSupport];
459
697
  }
460
698
  //# sourceMappingURL=use-global-styles-output.js.map