@wordpress/edit-site 4.10.0 → 4.12.1-next.d6164808d3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +26 -44
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/new-template.js +45 -23
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +493 -242
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/block-editor/index.js +1 -3
  9. package/build/components/block-editor/index.js.map +1 -1
  10. package/build/components/block-editor/resizable-editor.js +26 -12
  11. package/build/components/block-editor/resizable-editor.js.map +1 -1
  12. package/build/components/global-styles/border-panel.js +3 -3
  13. package/build/components/global-styles/border-panel.js.map +1 -1
  14. package/build/components/global-styles/dimensions-panel.js +280 -20
  15. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  16. package/build/components/global-styles/hooks.js +4 -4
  17. package/build/components/global-styles/hooks.js.map +1 -1
  18. package/build/components/global-styles/screen-color-palette.js +1 -1
  19. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  20. package/build/components/global-styles/screen-colors.js +51 -7
  21. package/build/components/global-styles/screen-colors.js.map +1 -1
  22. package/build/components/global-styles/screen-heading-color.js +157 -0
  23. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  24. package/build/components/global-styles/screen-typography-element.js +4 -0
  25. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  26. package/build/components/global-styles/screen-typography.js +5 -0
  27. package/build/components/global-styles/screen-typography.js.map +1 -1
  28. package/build/components/global-styles/typography-panel.js +82 -14
  29. package/build/components/global-styles/typography-panel.js.map +1 -1
  30. package/build/components/global-styles/typography-utils.js +217 -0
  31. package/build/components/global-styles/typography-utils.js.map +1 -0
  32. package/build/components/global-styles/ui.js +11 -0
  33. package/build/components/global-styles/ui.js.map +1 -1
  34. package/build/components/global-styles/use-global-styles-output.js +183 -52
  35. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  36. package/build/components/global-styles/utils.js +85 -5
  37. package/build/components/global-styles/utils.js.map +1 -1
  38. package/build/components/header/document-actions/index.js +1 -0
  39. package/build/components/header/document-actions/index.js.map +1 -1
  40. package/build/components/header/index.js +27 -12
  41. package/build/components/header/index.js.map +1 -1
  42. package/build/components/header/mode-switcher/index.js +0 -4
  43. package/build/components/header/mode-switcher/index.js.map +1 -1
  44. package/build/components/header/more-menu/index.js +13 -3
  45. package/build/components/header/more-menu/index.js.map +1 -1
  46. package/build/components/header/undo-redo/redo.js +2 -1
  47. package/build/components/header/undo-redo/redo.js.map +1 -1
  48. package/build/components/list/actions/index.js +1 -1
  49. package/build/components/list/actions/index.js.map +1 -1
  50. package/build/components/save-button/index.js +2 -3
  51. package/build/components/save-button/index.js.map +1 -1
  52. package/build/components/sidebar/default-sidebar.js +11 -1
  53. package/build/components/sidebar/default-sidebar.js.map +1 -1
  54. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  55. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  56. package/build/components/sidebar/plugin-sidebar/index.js +11 -1
  57. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  58. package/build/components/sidebar/template-card/template-actions.js +1 -1
  59. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  60. package/build/components/template-details/edit-template-title.js +1 -1
  61. package/build/components/template-details/edit-template-title.js.map +1 -1
  62. package/build/components/template-details/index.js +19 -9
  63. package/build/components/template-details/index.js.map +1 -1
  64. package/build/components/template-details/template-areas.js +1 -1
  65. package/build/components/template-details/template-areas.js.map +1 -1
  66. package/build/components/template-details/template-part-area-selector.js +47 -0
  67. package/build/components/template-details/template-part-area-selector.js.map +1 -0
  68. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  69. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  70. package/build/hooks/index.js +2 -0
  71. package/build/hooks/index.js.map +1 -1
  72. package/build/hooks/template-part-edit.js +86 -0
  73. package/build/hooks/template-part-edit.js.map +1 -0
  74. package/build/index.js +1 -1
  75. package/build/index.js.map +1 -1
  76. package/build-module/components/add-new-template/add-custom-template-modal.js +27 -45
  77. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  78. package/build-module/components/add-new-template/new-template.js +45 -25
  79. package/build-module/components/add-new-template/new-template.js.map +1 -1
  80. package/build-module/components/add-new-template/utils.js +489 -230
  81. package/build-module/components/add-new-template/utils.js.map +1 -1
  82. package/build-module/components/block-editor/index.js +1 -2
  83. package/build-module/components/block-editor/index.js.map +1 -1
  84. package/build-module/components/block-editor/resizable-editor.js +26 -12
  85. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  86. package/build-module/components/global-styles/border-panel.js +3 -3
  87. package/build-module/components/global-styles/border-panel.js.map +1 -1
  88. package/build-module/components/global-styles/dimensions-panel.js +278 -22
  89. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  90. package/build-module/components/global-styles/hooks.js +4 -4
  91. package/build-module/components/global-styles/hooks.js.map +1 -1
  92. package/build-module/components/global-styles/screen-color-palette.js +1 -1
  93. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  94. package/build-module/components/global-styles/screen-colors.js +51 -7
  95. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  96. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  97. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  98. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  99. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  100. package/build-module/components/global-styles/screen-typography.js +5 -0
  101. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  102. package/build-module/components/global-styles/typography-panel.js +83 -15
  103. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  104. package/build-module/components/global-styles/typography-utils.js +204 -0
  105. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  106. package/build-module/components/global-styles/ui.js +10 -0
  107. package/build-module/components/global-styles/ui.js.map +1 -1
  108. package/build-module/components/global-styles/use-global-styles-output.js +182 -61
  109. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  110. package/build-module/components/global-styles/utils.js +82 -5
  111. package/build-module/components/global-styles/utils.js.map +1 -1
  112. package/build-module/components/header/document-actions/index.js +1 -0
  113. package/build-module/components/header/document-actions/index.js.map +1 -1
  114. package/build-module/components/header/index.js +30 -14
  115. package/build-module/components/header/index.js.map +1 -1
  116. package/build-module/components/header/mode-switcher/index.js +0 -4
  117. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  118. package/build-module/components/header/more-menu/index.js +13 -3
  119. package/build-module/components/header/more-menu/index.js.map +1 -1
  120. package/build-module/components/header/undo-redo/redo.js +3 -2
  121. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  122. package/build-module/components/list/actions/index.js +1 -1
  123. package/build-module/components/list/actions/index.js.map +1 -1
  124. package/build-module/components/save-button/index.js +3 -4
  125. package/build-module/components/save-button/index.js.map +1 -1
  126. package/build-module/components/sidebar/default-sidebar.js +9 -1
  127. package/build-module/components/sidebar/default-sidebar.js.map +1 -1
  128. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  129. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  130. package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
  131. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  132. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  133. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  134. package/build-module/components/template-details/edit-template-title.js +1 -1
  135. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  136. package/build-module/components/template-details/index.js +19 -10
  137. package/build-module/components/template-details/index.js.map +1 -1
  138. package/build-module/components/template-details/template-areas.js +1 -1
  139. package/build-module/components/template-details/template-areas.js.map +1 -1
  140. package/build-module/components/template-details/template-part-area-selector.js +35 -0
  141. package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
  142. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  143. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  144. package/build-module/hooks/index.js +1 -0
  145. package/build-module/hooks/index.js.map +1 -1
  146. package/build-module/hooks/template-part-edit.js +67 -0
  147. package/build-module/hooks/template-part-edit.js.map +1 -0
  148. package/build-module/index.js +1 -1
  149. package/build-module/index.js.map +1 -1
  150. package/build-style/style-rtl.css +40 -33
  151. package/build-style/style.css +40 -33
  152. package/package.json +29 -29
  153. package/src/components/add-new-template/add-custom-template-modal.js +39 -48
  154. package/src/components/add-new-template/new-template.js +50 -58
  155. package/src/components/add-new-template/style.scss +20 -8
  156. package/src/components/add-new-template/utils.js +529 -231
  157. package/src/components/block-editor/index.js +0 -2
  158. package/src/components/block-editor/resizable-editor.js +28 -18
  159. package/src/components/editor/style.scss +1 -0
  160. package/src/components/global-styles/border-panel.js +3 -3
  161. package/src/components/global-styles/dimensions-panel.js +344 -45
  162. package/src/components/global-styles/hooks.js +6 -3
  163. package/src/components/global-styles/screen-color-palette.js +1 -1
  164. package/src/components/global-styles/screen-colors.js +46 -4
  165. package/src/components/global-styles/screen-heading-color.js +201 -0
  166. package/src/components/global-styles/screen-typography-element.js +4 -0
  167. package/src/components/global-styles/screen-typography.js +6 -0
  168. package/src/components/global-styles/style.scss +14 -6
  169. package/src/components/global-styles/test/typography-utils.js +130 -0
  170. package/src/components/global-styles/test/use-global-styles-output.js +143 -4
  171. package/src/components/global-styles/test/utils.js +68 -8
  172. package/src/components/global-styles/typography-panel.js +119 -48
  173. package/src/components/global-styles/typography-utils.js +228 -0
  174. package/src/components/global-styles/ui.js +13 -0
  175. package/src/components/global-styles/use-global-styles-output.js +203 -53
  176. package/src/components/global-styles/utils.js +70 -4
  177. package/src/components/header/document-actions/index.js +3 -0
  178. package/src/components/header/index.js +41 -14
  179. package/src/components/header/mode-switcher/index.js +0 -3
  180. package/src/components/header/more-menu/index.js +7 -2
  181. package/src/components/header/style.scss +5 -3
  182. package/src/components/header/undo-redo/redo.js +6 -2
  183. package/src/components/list/actions/index.js +3 -1
  184. package/src/components/save-button/index.js +10 -13
  185. package/src/components/sidebar/default-sidebar.js +12 -0
  186. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  187. package/src/components/sidebar/plugin-sidebar/index.js +12 -0
  188. package/src/components/sidebar/style.scss +4 -0
  189. package/src/components/sidebar/template-card/template-actions.js +3 -1
  190. package/src/components/template-details/edit-template-title.js +7 -3
  191. package/src/components/template-details/index.js +23 -8
  192. package/src/components/template-details/style.scss +0 -5
  193. package/src/components/template-details/template-areas.js +3 -1
  194. package/src/components/template-details/template-part-area-selector.js +38 -0
  195. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
  196. package/src/hooks/index.js +1 -0
  197. package/src/hooks/template-part-edit.js +82 -0
  198. package/src/index.js +1 -1
  199. package/src/style.scss +0 -1
  200. package/build/components/edit-template-part-menu-button/index.js +0 -90
  201. package/build/components/edit-template-part-menu-button/index.js.map +0 -1
  202. package/build-module/components/edit-template-part-menu-button/index.js +0 -72
  203. package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
  204. package/src/components/edit-template-part-menu-button/index.js +0 -82
@@ -3,8 +3,11 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.getBlockSelectors = void 0;
6
7
  exports.getLayoutStyles = getLayoutStyles;
7
- exports.toStyles = exports.toCustomProperties = exports.getNodesWithStyles = exports.getNodesWithSettings = void 0;
8
+ exports.getNodesWithStyles = exports.getNodesWithSettings = void 0;
9
+ exports.getStylesDeclarations = getStylesDeclarations;
10
+ exports.toStyles = exports.toCustomProperties = void 0;
8
11
  exports.toSvgFilters = toSvgFilters;
9
12
  exports.useGlobalStylesOutput = useGlobalStylesOutput;
10
13
 
@@ -14,6 +17,8 @@ var _lodash = require("lodash");
14
17
 
15
18
  var _blocks = require("@wordpress/blocks");
16
19
 
20
+ var _data = require("@wordpress/data");
21
+
17
22
  var _styleEngine = require("@wordpress/style-engine");
18
23
 
19
24
  var _blockEditor = require("@wordpress/block-editor");
@@ -35,12 +40,23 @@ var _hooks = require("./hooks");
35
40
  /**
36
41
  * Internal dependencies
37
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
+
38
52
  function compileStyleValue(uncompiledValue) {
53
+ var _uncompiledValue$star;
54
+
39
55
  const VARIABLE_REFERENCE_PREFIX = 'var:';
40
56
  const VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE = '|';
41
57
  const VARIABLE_PATH_SEPARATOR_TOKEN_STYLE = '--';
42
58
 
43
- if ((0, _lodash.startsWith)(uncompiledValue, VARIABLE_REFERENCE_PREFIX)) {
59
+ if (uncompiledValue !== null && uncompiledValue !== void 0 && (_uncompiledValue$star = uncompiledValue.startsWith) !== null && _uncompiledValue$star !== void 0 && _uncompiledValue$star.call(uncompiledValue, VARIABLE_REFERENCE_PREFIX)) {
44
60
  const variable = uncompiledValue.slice(VARIABLE_REFERENCE_PREFIX.length).split(VARIABLE_PATH_SEPARATOR_TOKEN_ATTRIBUTE).join(VARIABLE_PATH_SEPARATOR_TOKEN_STYLE);
45
61
  return `var(--wp--${variable})`;
46
62
  }
@@ -51,13 +67,15 @@ function compileStyleValue(uncompiledValue) {
51
67
  * Transform given preset tree into a set of style declarations.
52
68
  *
53
69
  * @param {Object} blockPresets
70
+ * @param {Object} mergedSettings Merged theme.json settings.
54
71
  *
55
- * @return {Array} An array of style declarations.
72
+ * @return {Array<Object>} An array of style declarations.
56
73
  */
57
74
 
58
75
 
59
76
  function getPresetsDeclarations() {
60
77
  let blockPresets = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
78
+ let mergedSettings = arguments.length > 1 ? arguments[1] : undefined;
61
79
  return (0, _lodash.reduce)(_utils.PRESET_METADATA, (declarations, _ref) => {
62
80
  let {
63
81
  path,
@@ -69,10 +87,10 @@ function getPresetsDeclarations() {
69
87
  ['default', 'theme', 'custom'].forEach(origin => {
70
88
  if (presetByOrigin[origin]) {
71
89
  presetByOrigin[origin].forEach(value => {
72
- if (valueKey) {
90
+ if (valueKey && !valueFunc) {
73
91
  declarations.push(`--wp--preset--${cssVarInfix}--${(0, _lodash.kebabCase)(value.slug)}: ${value[valueKey]}`);
74
92
  } else if (valueFunc && typeof valueFunc === 'function') {
75
- declarations.push(`--wp--preset--${cssVarInfix}--${(0, _lodash.kebabCase)(value.slug)}: ${valueFunc(value)}`);
93
+ declarations.push(`--wp--preset--${cssVarInfix}--${(0, _lodash.kebabCase)(value.slug)}: ${valueFunc(value, mergedSettings)}`);
76
94
  }
77
95
  });
78
96
  }
@@ -160,7 +178,13 @@ function flattenTree() {
160
178
  /**
161
179
  * Transform given style tree into a set of style declarations.
162
180
  *
163
- * @param {Object} blockStyles Block styles.
181
+ * @param {Object} blockStyles Block styles.
182
+ *
183
+ * @param {string} selector The selector these declarations should attach to.
184
+ *
185
+ * @param {boolean} useRootPaddingAlign Whether to use CSS custom properties in root selector.
186
+ *
187
+ * @param {Object} tree A theme.json tree containing layout definitions.
164
188
  *
165
189
  * @return {Array} An array of style declarations.
166
190
  */
@@ -168,19 +192,34 @@ function flattenTree() {
168
192
 
169
193
  function getStylesDeclarations() {
170
194
  let blockStyles = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
195
+ let selector = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
196
+ let useRootPaddingAlign = arguments.length > 2 ? arguments[2] : undefined;
197
+ let tree = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
198
+ const isRoot = _utils.ROOT_BLOCK_SELECTOR === selector;
171
199
  const output = (0, _lodash.reduce)(_blocks.__EXPERIMENTAL_STYLE_PROPERTY, (declarations, _ref5, key) => {
172
200
  let {
173
201
  value,
174
202
  properties,
175
- useEngine
203
+ useEngine,
204
+ rootOnly
176
205
  } = _ref5;
206
+
207
+ if (rootOnly && !isRoot) {
208
+ return declarations;
209
+ }
210
+
177
211
  const pathToValue = value;
178
212
 
179
213
  if ((0, _lodash.first)(pathToValue) === 'elements' || useEngine) {
180
214
  return declarations;
181
215
  }
182
216
 
183
- const styleValue = (0, _lodash.get)(blockStyles, pathToValue);
217
+ const styleValue = (0, _lodash.get)(blockStyles, pathToValue); // Root-level padding styles don't currently support strings with CSS shorthand values.
218
+ // This may change: https://github.com/WordPress/gutenberg/issues/40132.
219
+
220
+ if (key === '--wp--style--root--padding' && (typeof styleValue === 'string' || !useRootPaddingAlign)) {
221
+ return declarations;
222
+ }
184
223
 
185
224
  if (!!properties && typeof styleValue !== 'string') {
186
225
  Object.entries(properties).forEach(entry => {
@@ -192,7 +231,7 @@ function getStylesDeclarations() {
192
231
  return;
193
232
  }
194
233
 
195
- const cssProperty = (0, _lodash.kebabCase)(name);
234
+ const cssProperty = name.startsWith('--') ? name : (0, _lodash.kebabCase)(name);
196
235
  declarations.push(`${cssProperty}: ${compileStyleValue((0, _lodash.get)(styleValue, [prop]))}`);
197
236
  });
198
237
  } else if ((0, _lodash.get)(blockStyles, pathToValue, false)) {
@@ -206,8 +245,29 @@ function getStylesDeclarations() {
206
245
 
207
246
  const extraRules = (0, _styleEngine.getCSSRules)(blockStyles);
208
247
  extraRules.forEach(rule => {
248
+ var _ruleValue;
249
+
250
+ // Don't output padding properties if padding variables are set.
251
+ if (isRoot && useRootPaddingAlign && rule.key.startsWith('padding')) {
252
+ return;
253
+ }
254
+
209
255
  const cssProperty = rule.key.startsWith('--') ? rule.key : (0, _lodash.kebabCase)(rule.key);
210
- output.push(`${cssProperty}: ${compileStyleValue(rule.value)}`);
256
+ let ruleValue = rule.value;
257
+
258
+ if (typeof ruleValue !== 'string' && (_ruleValue = ruleValue) !== null && _ruleValue !== void 0 && _ruleValue.ref) {
259
+ var _ruleValue2;
260
+
261
+ const refPath = ruleValue.ref.split('.');
262
+ ruleValue = (0, _lodash.get)(tree, refPath); // Presence of another ref indicates a reference to another dynamic value.
263
+ // Pointing to another dynamic value is not supported.
264
+
265
+ if (!ruleValue || !!((_ruleValue2 = ruleValue) !== null && _ruleValue2 !== void 0 && _ruleValue2.ref)) {
266
+ return;
267
+ }
268
+ }
269
+
270
+ output.push(`${cssProperty}: ${ruleValue}`);
211
271
  });
212
272
  return output;
213
273
  }
@@ -274,7 +334,15 @@ function getLayoutStyles(_ref6) {
274
334
  }
275
335
 
276
336
  if (declarations.length) {
277
- const 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) || ''}`;
337
+ let combinedSelector = '';
338
+
339
+ if (!hasBlockGapSupport) {
340
+ // For fallback gap styles, use lower specificity, to ensure styles do not unintentionally override theme styles.
341
+ 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) || ''})`;
342
+ } else {
343
+ 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) || ''}`;
344
+ }
345
+
278
346
  ruleset += `${combinedSelector} { ${declarations.join('; ')}; }`;
279
347
  }
280
348
  });
@@ -324,7 +392,7 @@ function getLayoutStyles(_ref6) {
324
392
  }
325
393
 
326
394
  const getNodesWithStyles = (tree, blockSelectors) => {
327
- var _tree$styles, _tree$styles2;
395
+ var _tree$styles3;
328
396
 
329
397
  const nodes = [];
330
398
 
@@ -344,16 +412,20 @@ const getNodesWithStyles = (tree, blockSelectors) => {
344
412
  });
345
413
  }
346
414
 
347
- (0, _lodash.forEach)((_tree$styles = tree.styles) === null || _tree$styles === void 0 ? void 0 : _tree$styles.elements, (value, key) => {
348
- if (!!value && !!_blocks.__EXPERIMENTAL_ELEMENTS[key]) {
415
+ (0, _lodash.forEach)(_blocks.__EXPERIMENTAL_ELEMENTS, (selector, name) => {
416
+ var _tree$styles;
417
+
418
+ if (!!((_tree$styles = tree.styles) !== null && _tree$styles !== void 0 && _tree$styles.elements[name])) {
419
+ var _tree$styles2;
420
+
349
421
  nodes.push({
350
- styles: value,
351
- selector: _blocks.__EXPERIMENTAL_ELEMENTS[key]
422
+ styles: (_tree$styles2 = tree.styles) === null || _tree$styles2 === void 0 ? void 0 : _tree$styles2.elements[name],
423
+ selector
352
424
  });
353
425
  }
354
426
  }); // Iterate over blocks: they can have styles & elements.
355
427
 
356
- (0, _lodash.forEach)((_tree$styles2 = tree.styles) === null || _tree$styles2 === void 0 ? void 0 : _tree$styles2.blocks, (node, blockName) => {
428
+ (0, _lodash.forEach)((_tree$styles3 = tree.styles) === null || _tree$styles3 === void 0 ? void 0 : _tree$styles3.blocks, (node, blockName) => {
357
429
  var _blockSelectors$block;
358
430
 
359
431
  const blockStyles = pickStyleKeys(node);
@@ -364,7 +436,8 @@ const getNodesWithStyles = (tree, blockSelectors) => {
364
436
  fallbackGapValue: blockSelectors[blockName].fallbackGapValue,
365
437
  hasLayoutSupport: blockSelectors[blockName].hasLayoutSupport,
366
438
  selector: blockSelectors[blockName].selector,
367
- styles: blockStyles
439
+ styles: blockStyles,
440
+ featureSelectors: blockSelectors[blockName].featureSelectors
368
441
  });
369
442
  }
370
443
 
@@ -451,7 +524,7 @@ const toCustomProperties = (tree, blockSelectors) => {
451
524
  custom,
452
525
  selector
453
526
  } = _ref12;
454
- const declarations = getPresetsDeclarations(presets);
527
+ const declarations = getPresetsDeclarations(presets, tree === null || tree === void 0 ? void 0 : tree.settings);
455
528
  const customProps = flattenTree(custom, '--wp--custom--', '--');
456
529
 
457
530
  if (customProps.length > 0) {
@@ -467,9 +540,17 @@ const toCustomProperties = (tree, blockSelectors) => {
467
540
 
468
541
  exports.toCustomProperties = toCustomProperties;
469
542
 
470
- const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) => {
543
+ const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport) {
544
+ var _tree$settings5, _tree$settings6;
545
+
546
+ let disableLayoutStyles = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
471
547
  const nodesWithStyles = getNodesWithStyles(tree, blockSelectors);
472
548
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
549
+ const useRootPaddingAlign = tree === null || tree === void 0 ? void 0 : (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.useRootPaddingAwareAlignments;
550
+ const {
551
+ contentSize,
552
+ wideSize
553
+ } = (tree === null || tree === void 0 ? void 0 : (_tree$settings6 = tree.settings) === null || _tree$settings6 === void 0 ? void 0 : _tree$settings6.layout) || {};
473
554
  /*
474
555
  * Reset default browser margin on the root body element.
475
556
  * This is set on the root selector **before** generating the ruleset
@@ -479,15 +560,51 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSuppor
479
560
  * @link https://github.com/WordPress/gutenberg/issues/36147.
480
561
  */
481
562
 
482
- let ruleset = 'body {margin: 0;}';
563
+ let ruleset = 'body {margin: 0;';
564
+
565
+ if (contentSize) {
566
+ ruleset += ` --wp--style--global--content-size: ${contentSize};`;
567
+ }
568
+
569
+ if (wideSize) {
570
+ ruleset += ` --wp--style--global--wide-size: ${wideSize};`;
571
+ }
572
+
573
+ if (useRootPaddingAlign) {
574
+ ruleset += '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);';
575
+ }
576
+
577
+ ruleset += '}';
483
578
  nodesWithStyles.forEach(_ref13 => {
484
579
  let {
485
580
  selector,
486
581
  duotoneSelector,
487
582
  styles,
488
583
  fallbackGapValue,
489
- hasLayoutSupport
584
+ hasLayoutSupport,
585
+ featureSelectors
490
586
  } = _ref13;
587
+
588
+ // Process styles for block support features with custom feature level
589
+ // CSS selectors set.
590
+ if (featureSelectors) {
591
+ Object.entries(featureSelectors).forEach(_ref14 => {
592
+ let [featureName, featureSelector] = _ref14;
593
+
594
+ if (styles !== null && styles !== void 0 && styles[featureName]) {
595
+ const featureStyles = {
596
+ [featureName]: styles[featureName]
597
+ };
598
+ const featureDeclarations = getStylesDeclarations(featureStyles);
599
+ delete styles[featureName];
600
+
601
+ if (!!featureDeclarations.length) {
602
+ ruleset = ruleset + `${featureSelector}{${featureDeclarations.join(';')} }`;
603
+ }
604
+ }
605
+ });
606
+ }
607
+
491
608
  const duotoneStyles = {};
492
609
 
493
610
  if (styles !== null && styles !== void 0 && styles.filter) {
@@ -499,15 +616,13 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSuppor
499
616
  if (duotoneSelector) {
500
617
  const duotoneDeclarations = getStylesDeclarations(duotoneStyles);
501
618
 
502
- if (duotoneDeclarations.length === 0) {
503
- return;
619
+ if (duotoneDeclarations.length > 0) {
620
+ ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
504
621
  }
505
-
506
- ruleset = ruleset + `${duotoneSelector}{${duotoneDeclarations.join(';')};}`;
507
622
  } // Process blockGap and layout styles.
508
623
 
509
624
 
510
- if (_utils.ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport) {
625
+ if (!disableLayoutStyles && (_utils.ROOT_BLOCK_SELECTOR === selector || hasLayoutSupport)) {
511
626
  ruleset += getLayoutStyles({
512
627
  tree,
513
628
  style: styles,
@@ -519,28 +634,28 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSuppor
519
634
  } // Process the remaining block styles (they use either normal block class or __experimentalSelector).
520
635
 
521
636
 
522
- const declarations = getStylesDeclarations(styles);
637
+ const declarations = getStylesDeclarations(styles, selector, useRootPaddingAlign, tree);
523
638
 
524
639
  if (declarations !== null && declarations !== void 0 && declarations.length) {
525
640
  ruleset = ruleset + `${selector}{${declarations.join(';')};}`;
526
641
  } // Check for pseudo selector in `styles` and handle separately.
527
642
 
528
643
 
529
- const pseudoSelectorStyles = Object.entries(styles).filter(_ref14 => {
530
- let [key] = _ref14;
644
+ const pseudoSelectorStyles = Object.entries(styles).filter(_ref15 => {
645
+ let [key] = _ref15;
531
646
  return key.startsWith(':');
532
647
  });
533
648
 
534
649
  if (pseudoSelectorStyles !== null && pseudoSelectorStyles !== void 0 && pseudoSelectorStyles.length) {
535
- pseudoSelectorStyles.forEach(_ref15 => {
536
- let [pseudoKey, pseudoStyle] = _ref15;
650
+ pseudoSelectorStyles.forEach(_ref16 => {
651
+ let [pseudoKey, pseudoStyle] = _ref16;
537
652
  const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
538
653
 
539
654
  if (!(pseudoDeclarations !== null && pseudoDeclarations !== void 0 && pseudoDeclarations.length)) {
540
655
  return;
541
656
  } // `selector` maybe provided in a form
542
657
  // where block level selectors have sub element
543
- // selectors appended to them as a comma seperated
658
+ // selectors appended to them as a comma separated
544
659
  // string.
545
660
  // e.g. `h1 a,h2 a,h3 a,h4 a,h5 a,h6 a`;
546
661
  // Split and append pseudo selector to create
@@ -561,19 +676,19 @@ const toStyles = (tree, blockSelectors, hasBlockGapSupport, hasFallbackGapSuppor
561
676
  ruleset = ruleset + '.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }';
562
677
 
563
678
  if (hasBlockGapSupport) {
564
- var _tree$styles3, _tree$styles3$spacing;
679
+ var _tree$styles4, _tree$styles4$spacing;
565
680
 
566
681
  // Use fallback of `0.5em` just in case, however if there is blockGap support, there should nearly always be a real value.
567
- const gapValue = (0, _blockEditor.__experimentalGetGapCSSValue)(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';
682
+ 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';
568
683
  ruleset = ruleset + '.wp-site-blocks > * { margin-block-start: 0; margin-block-end: 0; }';
569
684
  ruleset = ruleset + `.wp-site-blocks > * + * { margin-block-start: ${gapValue}; }`;
570
685
  }
571
686
 
572
- nodesWithSettings.forEach(_ref16 => {
687
+ nodesWithSettings.forEach(_ref17 => {
573
688
  let {
574
689
  selector,
575
690
  presets
576
- } = _ref16;
691
+ } = _ref17;
577
692
 
578
693
  if (_utils.ROOT_BLOCK_SELECTOR === selector) {
579
694
  // Do not add extra specificity for top-level classes.
@@ -593,10 +708,10 @@ exports.toStyles = toStyles;
593
708
 
594
709
  function toSvgFilters(tree, blockSelectors) {
595
710
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
596
- return nodesWithSettings.flatMap(_ref17 => {
711
+ return nodesWithSettings.flatMap(_ref18 => {
597
712
  let {
598
713
  presets
599
- } = _ref17;
714
+ } = _ref18;
600
715
  return getPresetsSvgFilters(presets);
601
716
  });
602
717
  }
@@ -610,10 +725,23 @@ const getBlockSelectors = blockTypes => {
610
725
  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('/', '-');
611
726
  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;
612
727
  const hasLayoutSupport = !!(blockType !== null && blockType !== void 0 && (_blockType$supports3 = blockType.supports) !== null && _blockType$supports3 !== void 0 && _blockType$supports3.__experimentalLayout);
613
- 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;
728
+ 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.
729
+
730
+ const featureSelectors = {};
731
+ Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(_ref19 => {
732
+ var _blockType$supports5, _blockType$supports5$;
733
+
734
+ let [featureKey, featureName] = _ref19;
735
+ 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;
736
+
737
+ if (featureSelector) {
738
+ featureSelectors[featureName] = (0, _utils.scopeSelector)(selector, featureSelector);
739
+ }
740
+ });
614
741
  result[name] = {
615
742
  duotoneSelector,
616
743
  fallbackGapValue,
744
+ featureSelectors: Object.keys(featureSelectors).length ? featureSelectors : undefined,
617
745
  hasLayoutSupport,
618
746
  name,
619
747
  selector
@@ -622,10 +750,9 @@ const getBlockSelectors = blockTypes => {
622
750
  return result;
623
751
  };
624
752
 
753
+ exports.getBlockSelectors = getBlockSelectors;
754
+
625
755
  function useGlobalStylesOutput() {
626
- const [stylesheets, setStylesheets] = (0, _element.useState)([]);
627
- const [settings, setSettings] = (0, _element.useState)({});
628
- const [svgFilters, setSvgFilters] = (0, _element.useState)({});
629
756
  const {
630
757
  merged: mergedConfig
631
758
  } = (0, _element.useContext)(_context.GlobalStylesContext);
@@ -633,25 +760,29 @@ function useGlobalStylesOutput() {
633
760
  const hasBlockGapSupport = blockGap !== null;
634
761
  const hasFallbackGapSupport = !hasBlockGapSupport; // This setting isn't useful yet: it exists as a placeholder for a future explicit fallback styles support.
635
762
 
636
- (0, _element.useEffect)(() => {
763
+ const disableLayoutStyles = (0, _data.useSelect)(select => {
764
+ const {
765
+ getSettings
766
+ } = select(_blockEditor.store);
767
+ return !!getSettings().disableLayoutStyles;
768
+ });
769
+ return (0, _element.useMemo)(() => {
637
770
  if (!(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.styles) || !(mergedConfig !== null && mergedConfig !== void 0 && mergedConfig.settings)) {
638
- return;
771
+ return [];
639
772
  }
640
773
 
641
774
  const blockSelectors = getBlockSelectors((0, _blocks.getBlockTypes)());
642
775
  const customProperties = toCustomProperties(mergedConfig, blockSelectors);
643
- const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport);
776
+ const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport, disableLayoutStyles);
644
777
  const filters = toSvgFilters(mergedConfig, blockSelectors);
645
- setStylesheets([{
778
+ const stylesheets = [{
646
779
  css: customProperties,
647
780
  isGlobalStyles: true
648
781
  }, {
649
782
  css: globalStyles,
650
783
  isGlobalStyles: true
651
- }]);
652
- setSettings(mergedConfig.settings);
653
- setSvgFilters(filters);
654
- }, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig]);
655
- return [stylesheets, settings, svgFilters, hasBlockGapSupport];
784
+ }];
785
+ return [stylesheets, mergedConfig.settings, filters];
786
+ }, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig, disableLayoutStyles]);
656
787
  }
657
788
  //# sourceMappingURL=use-global-styles-output.js.map