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