@wordpress/block-editor 11.6.0 → 11.7.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 (193) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +4 -0
  3. package/build/components/block-list/block-html.js +1 -3
  4. package/build/components/block-list/block-html.js.map +1 -1
  5. package/build/components/block-preview/auto.js +6 -23
  6. package/build/components/block-preview/auto.js.map +1 -1
  7. package/build/components/editor-styles/index.js +20 -2
  8. package/build/components/editor-styles/index.js.map +1 -1
  9. package/build/components/global-styles/color-panel.js +583 -0
  10. package/build/components/global-styles/color-panel.js.map +1 -0
  11. package/build/components/global-styles/dimensions-panel.js +8 -30
  12. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  13. package/build/components/global-styles/get-block-css-selector.js +129 -0
  14. package/build/components/global-styles/get-block-css-selector.js.map +1 -0
  15. package/build/components/global-styles/hooks.js +53 -1
  16. package/build/components/global-styles/hooks.js.map +1 -1
  17. package/build/components/global-styles/index.js +18 -2
  18. package/build/components/global-styles/index.js.map +1 -1
  19. package/build/components/global-styles/typography-panel.js +9 -35
  20. package/build/components/global-styles/typography-panel.js.map +1 -1
  21. package/build/components/global-styles/use-global-styles-output.js +160 -86
  22. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  23. package/build/components/global-styles/utils.js +2 -1
  24. package/build/components/global-styles/utils.js.map +1 -1
  25. package/build/components/image-size-control/index.js +8 -5
  26. package/build/components/image-size-control/index.js.map +1 -1
  27. package/build/components/inspector-controls-tabs/position-controls-panel.js +43 -7
  28. package/build/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  29. package/build/components/line-height-control/index.js +15 -1
  30. package/build/components/line-height-control/index.js.map +1 -1
  31. package/build/components/list-view/appender.js +105 -0
  32. package/build/components/list-view/appender.js.map +1 -0
  33. package/build/components/list-view/block.js +5 -5
  34. package/build/components/list-view/block.js.map +1 -1
  35. package/build/components/list-view/branch.js +25 -5
  36. package/build/components/list-view/branch.js.map +1 -1
  37. package/build/components/list-view/index.js +37 -13
  38. package/build/components/list-view/index.js.map +1 -1
  39. package/build/components/media-replace-flow/index.js +13 -4
  40. package/build/components/media-replace-flow/index.js.map +1 -1
  41. package/build/components/rich-text/format-edit.js +2 -30
  42. package/build/components/rich-text/format-edit.js.map +1 -1
  43. package/build/components/writing-flow/use-input.js +4 -8
  44. package/build/components/writing-flow/use-input.js.map +1 -1
  45. package/build/hooks/border.js +0 -1
  46. package/build/hooks/border.js.map +1 -1
  47. package/build/hooks/color.js +92 -229
  48. package/build/hooks/color.js.map +1 -1
  49. package/build/hooks/content-lock-ui.js +4 -2
  50. package/build/hooks/content-lock-ui.js.map +1 -1
  51. package/build/hooks/{color-panel.js → contrast-checker.js} +11 -49
  52. package/build/hooks/contrast-checker.js.map +1 -0
  53. package/build/hooks/dimensions.js +0 -1
  54. package/build/hooks/dimensions.js.map +1 -1
  55. package/build/hooks/duotone.js +3 -1
  56. package/build/hooks/duotone.js.map +1 -1
  57. package/build/hooks/position.js +2 -2
  58. package/build/hooks/position.js.map +1 -1
  59. package/build/hooks/style.js +23 -26
  60. package/build/hooks/style.js.map +1 -1
  61. package/build/hooks/typography.js +0 -1
  62. package/build/hooks/typography.js.map +1 -1
  63. package/build/hooks/utils.js +25 -76
  64. package/build/hooks/utils.js.map +1 -1
  65. package/build/layouts/grid.js +165 -0
  66. package/build/layouts/grid.js.map +1 -0
  67. package/build/layouts/index.js +3 -1
  68. package/build/layouts/index.js.map +1 -1
  69. package/build/private-apis.js +4 -1
  70. package/build/private-apis.js.map +1 -1
  71. package/build/utils/object.js +76 -0
  72. package/build/utils/object.js.map +1 -0
  73. package/build-module/components/block-list/block-html.js +1 -3
  74. package/build-module/components/block-list/block-html.js.map +1 -1
  75. package/build-module/components/block-preview/auto.js +6 -22
  76. package/build-module/components/block-preview/auto.js.map +1 -1
  77. package/build-module/components/editor-styles/index.js +19 -2
  78. package/build-module/components/editor-styles/index.js.map +1 -1
  79. package/build-module/components/global-styles/color-panel.js +554 -0
  80. package/build-module/components/global-styles/color-panel.js.map +1 -0
  81. package/build-module/components/global-styles/dimensions-panel.js +7 -30
  82. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  83. package/build-module/components/global-styles/get-block-css-selector.js +120 -0
  84. package/build-module/components/global-styles/get-block-css-selector.js.map +1 -0
  85. package/build-module/components/global-styles/hooks.js +51 -1
  86. package/build-module/components/global-styles/hooks.js.map +1 -1
  87. package/build-module/components/global-styles/index.js +3 -1
  88. package/build-module/components/global-styles/index.js.map +1 -1
  89. package/build-module/components/global-styles/typography-panel.js +8 -35
  90. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  91. package/build-module/components/global-styles/use-global-styles-output.js +161 -87
  92. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  93. package/build-module/components/global-styles/utils.js +2 -1
  94. package/build-module/components/global-styles/utils.js.map +1 -1
  95. package/build-module/components/image-size-control/index.js +8 -5
  96. package/build-module/components/image-size-control/index.js.map +1 -1
  97. package/build-module/components/inspector-controls-tabs/position-controls-panel.js +42 -7
  98. package/build-module/components/inspector-controls-tabs/position-controls-panel.js.map +1 -1
  99. package/build-module/components/line-height-control/index.js +15 -1
  100. package/build-module/components/line-height-control/index.js.map +1 -1
  101. package/build-module/components/list-view/appender.js +88 -0
  102. package/build-module/components/list-view/appender.js.map +1 -0
  103. package/build-module/components/list-view/block.js +5 -4
  104. package/build-module/components/list-view/block.js.map +1 -1
  105. package/build-module/components/list-view/branch.js +22 -5
  106. package/build-module/components/list-view/branch.js.map +1 -1
  107. package/build-module/components/list-view/index.js +32 -12
  108. package/build-module/components/list-view/index.js.map +1 -1
  109. package/build-module/components/media-replace-flow/index.js +12 -4
  110. package/build-module/components/media-replace-flow/index.js.map +1 -1
  111. package/build-module/components/rich-text/format-edit.js +3 -31
  112. package/build-module/components/rich-text/format-edit.js.map +1 -1
  113. package/build-module/components/writing-flow/use-input.js +4 -8
  114. package/build-module/components/writing-flow/use-input.js.map +1 -1
  115. package/build-module/hooks/border.js +0 -1
  116. package/build-module/hooks/border.js.map +1 -1
  117. package/build-module/hooks/color.js +90 -232
  118. package/build-module/hooks/color.js.map +1 -1
  119. package/build-module/hooks/content-lock-ui.js +4 -2
  120. package/build-module/hooks/content-lock-ui.js.map +1 -1
  121. package/build-module/hooks/{color-panel.js → contrast-checker.js} +10 -44
  122. package/build-module/hooks/contrast-checker.js.map +1 -0
  123. package/build-module/hooks/dimensions.js +0 -1
  124. package/build-module/hooks/dimensions.js.map +1 -1
  125. package/build-module/hooks/duotone.js +4 -2
  126. package/build-module/hooks/duotone.js.map +1 -1
  127. package/build-module/hooks/position.js +3 -3
  128. package/build-module/hooks/position.js.map +1 -1
  129. package/build-module/hooks/style.js +23 -26
  130. package/build-module/hooks/style.js.map +1 -1
  131. package/build-module/hooks/typography.js +0 -1
  132. package/build-module/hooks/typography.js.map +1 -1
  133. package/build-module/hooks/utils.js +23 -73
  134. package/build-module/hooks/utils.js.map +1 -1
  135. package/build-module/layouts/grid.js +151 -0
  136. package/build-module/layouts/grid.js.map +1 -0
  137. package/build-module/layouts/index.js +2 -1
  138. package/build-module/layouts/index.js.map +1 -1
  139. package/build-module/private-apis.js +3 -1
  140. package/build-module/private-apis.js.map +1 -1
  141. package/build-module/utils/object.js +69 -0
  142. package/build-module/utils/object.js.map +1 -0
  143. package/build-style/style-rtl.css +26 -6
  144. package/build-style/style.css +26 -6
  145. package/package.json +31 -31
  146. package/src/components/block-draggable/content.scss +1 -1
  147. package/src/components/block-list/block-html.js +1 -1
  148. package/src/components/block-preview/auto.js +2 -17
  149. package/src/components/colors-gradients/style.scss +8 -8
  150. package/src/components/editor-styles/index.js +29 -1
  151. package/src/components/global-styles/color-panel.js +706 -0
  152. package/src/components/global-styles/dimensions-panel.js +13 -42
  153. package/src/components/global-styles/get-block-css-selector.js +129 -0
  154. package/src/components/global-styles/hooks.js +80 -0
  155. package/src/components/global-styles/index.js +2 -1
  156. package/src/components/global-styles/test/use-global-styles-output.js +30 -1
  157. package/src/components/global-styles/typography-panel.js +26 -51
  158. package/src/components/global-styles/use-global-styles-output.js +163 -80
  159. package/src/components/global-styles/utils.js +3 -0
  160. package/src/components/image-size-control/index.js +4 -3
  161. package/src/components/image-size-control/test/index.js +2 -2
  162. package/src/components/inner-blocks/README.md +1 -1
  163. package/src/components/inspector-controls-tabs/position-controls-panel.js +40 -9
  164. package/src/components/line-height-control/index.js +10 -1
  165. package/src/components/list-view/appender.js +101 -0
  166. package/src/components/list-view/block.js +5 -4
  167. package/src/components/list-view/branch.js +30 -1
  168. package/src/components/list-view/index.js +43 -10
  169. package/src/components/list-view/style.scss +19 -0
  170. package/src/components/media-replace-flow/index.js +36 -24
  171. package/src/components/media-replace-flow/style.scss +5 -2
  172. package/src/components/rich-text/format-edit.js +2 -32
  173. package/src/components/writing-flow/use-input.js +4 -5
  174. package/src/hooks/border.js +0 -1
  175. package/src/hooks/color.js +120 -296
  176. package/src/hooks/content-lock-ui.js +6 -2
  177. package/src/hooks/{color-panel.js → contrast-checker.js} +10 -46
  178. package/src/hooks/dimensions.js +0 -1
  179. package/src/hooks/duotone.js +8 -5
  180. package/src/hooks/position.js +3 -3
  181. package/src/hooks/style.js +29 -28
  182. package/src/hooks/test/utils.js +0 -104
  183. package/src/hooks/typography.js +0 -1
  184. package/src/hooks/utils.js +27 -70
  185. package/src/layouts/grid.js +172 -0
  186. package/src/layouts/index.js +2 -1
  187. package/src/layouts/test/grid.js +21 -0
  188. package/src/private-apis.js +2 -0
  189. package/src/utils/object.js +69 -0
  190. package/src/utils/test/object.js +107 -0
  191. package/tsconfig.tsbuildinfo +1 -1
  192. package/build/hooks/color-panel.js.map +0 -1
  193. package/build-module/hooks/color-panel.js.map +0 -1
@@ -10,13 +10,14 @@ import { get, isEmpty, kebabCase, set } from 'lodash';
10
10
 
11
11
  import { __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY, __EXPERIMENTAL_ELEMENTS as ELEMENTS, getBlockTypes, store as blocksStore } from '@wordpress/blocks';
12
12
  import { useSelect } from '@wordpress/data';
13
- import { useContext, useMemo } from '@wordpress/element';
13
+ import { renderToString, useContext, useMemo } from '@wordpress/element';
14
14
  import { getCSSRules } from '@wordpress/style-engine';
15
15
  /**
16
16
  * Internal dependencies
17
17
  */
18
18
 
19
19
  import { PRESET_METADATA, ROOT_BLOCK_SELECTOR, scopeSelector } from './utils';
20
+ import { getBlockCSSSelector } from './get-block-css-selector';
20
21
  import { getTypographyFontSizeValue } from './typography-utils';
21
22
  import { GlobalStylesContext } from './context';
22
23
  import { useGlobalSetting } from './hooks';
@@ -134,10 +135,10 @@ function getPresetsSvgFilters() {
134
135
  return PRESET_METADATA.filter( // Duotone are the only type of filters for now.
135
136
  metadata => metadata.path.at(-1) === 'duotone').flatMap(metadata => {
136
137
  const presetByOrigin = get(blockPresets, metadata.path, {});
137
- return ['default', 'theme'].filter(origin => presetByOrigin[origin]).flatMap(origin => presetByOrigin[origin].map(preset => createElement(PresetDuotoneFilter, {
138
+ return ['default', 'theme'].filter(origin => presetByOrigin[origin]).flatMap(origin => presetByOrigin[origin].map(preset => renderToString(createElement(PresetDuotoneFilter, {
138
139
  preset: preset,
139
140
  key: preset.slug
140
- })));
141
+ })))).join('');
141
142
  });
142
143
  }
143
144
 
@@ -178,6 +179,76 @@ function concatFeatureVariationSelectorString(featureSelector, styleVariationSel
178
179
  });
179
180
  return combinedSelectors.join(', ');
180
181
  }
182
+ /**
183
+ * Generate style declarations for a block's custom feature and subfeature
184
+ * selectors.
185
+ *
186
+ * NOTE: The passed `styles` object will be mutated by this function.
187
+ *
188
+ * @param {Object} selectors Custom selectors object for a block.
189
+ * @param {Object} styles A block's styles object.
190
+ *
191
+ * @return {Object} Style declarations.
192
+ */
193
+
194
+
195
+ const getFeatureDeclarations = (selectors, styles) => {
196
+ const declarations = {};
197
+ Object.entries(selectors).forEach(_ref5 => {
198
+ let [feature, selector] = _ref5;
199
+
200
+ // We're only processing features/subfeatures that have styles.
201
+ if (feature === 'root' || !(styles !== null && styles !== void 0 && styles[feature])) {
202
+ return;
203
+ }
204
+
205
+ const isShorthand = typeof selector === 'string'; // If we have a selector object instead of shorthand process it.
206
+
207
+ if (!isShorthand) {
208
+ Object.entries(selector).forEach(_ref6 => {
209
+ let [subfeature, subfeatureSelector] = _ref6;
210
+
211
+ // Don't process root feature selector yet or any
212
+ // subfeature that doesn't have a style.
213
+ if (subfeature === 'root' || !(styles !== null && styles !== void 0 && styles[feature][subfeature])) {
214
+ return;
215
+ } // Create a temporary styles object and build
216
+ // declarations for subfeature.
217
+
218
+
219
+ const subfeatureStyles = {
220
+ [feature]: {
221
+ [subfeature]: styles[feature][subfeature]
222
+ }
223
+ };
224
+ const newDeclarations = getStylesDeclarations(subfeatureStyles); // Merge new declarations in with any others that
225
+ // share the same selector.
226
+
227
+ declarations[subfeatureSelector] = [...(declarations[subfeatureSelector] || []), ...newDeclarations]; // Remove the subfeature's style now it will be
228
+ // included under its own selector not the block's.
229
+
230
+ delete styles[feature][subfeature];
231
+ });
232
+ } // Now subfeatures have been processed and removed, we can
233
+ // process root, or shorthand, feature selectors.
234
+
235
+
236
+ if (isShorthand || selector.root) {
237
+ const featureSelector = isShorthand ? selector : selector.root; // Create temporary style object and build declarations for feature.
238
+
239
+ const featureStyles = {
240
+ [feature]: styles[feature]
241
+ };
242
+ const newDeclarations = getStylesDeclarations(featureStyles); // Merge new declarations with any others that share the selector.
243
+
244
+ declarations[featureSelector] = [...(declarations[featureSelector] || []), ...newDeclarations]; // Remove the feature from the block's styles now as it will be
245
+ // included under its own selector not the block's.
246
+
247
+ delete styles[feature];
248
+ }
249
+ });
250
+ return declarations;
251
+ };
181
252
  /**
182
253
  * Transform given style tree into a set of style declarations.
183
254
  *
@@ -199,13 +270,13 @@ export function getStylesDeclarations() {
199
270
  let useRootPaddingAlign = arguments.length > 2 ? arguments[2] : undefined;
200
271
  let tree = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
201
272
  const isRoot = ROOT_BLOCK_SELECTOR === selector;
202
- const output = Object.entries(STYLE_PROPERTY).reduce((declarations, _ref5) => {
273
+ const output = Object.entries(STYLE_PROPERTY).reduce((declarations, _ref7) => {
203
274
  let [key, {
204
275
  value,
205
276
  properties,
206
277
  useEngine,
207
278
  rootOnly
208
- }] = _ref5;
279
+ }] = _ref7;
209
280
 
210
281
  if (rootOnly && !isRoot) {
211
282
  return declarations;
@@ -304,7 +375,7 @@ export function getStylesDeclarations() {
304
375
  * @return {string} Generated CSS rules for the layout styles.
305
376
  */
306
377
 
307
- export function getLayoutStyles(_ref6) {
378
+ export function getLayoutStyles(_ref8) {
308
379
  var _style$spacing, _tree$settings2, _tree$settings2$layou, _tree$settings3, _tree$settings3$layou;
309
380
 
310
381
  let {
@@ -314,7 +385,7 @@ export function getLayoutStyles(_ref6) {
314
385
  hasBlockGapSupport,
315
386
  hasFallbackGapSupport,
316
387
  fallbackGapValue
317
- } = _ref6;
388
+ } = _ref8;
318
389
  let ruleset = '';
319
390
  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,
320
391
  // and use a fallback value if one is provided for the current block.
@@ -328,12 +399,12 @@ export function getLayoutStyles(_ref6) {
328
399
  }
329
400
 
330
401
  if (gapValue && 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) {
331
- Object.values(tree.settings.layout.definitions).forEach(_ref7 => {
402
+ Object.values(tree.settings.layout.definitions).forEach(_ref9 => {
332
403
  let {
333
404
  className,
334
405
  name,
335
406
  spacingStyles
336
- } = _ref7;
407
+ } = _ref9;
337
408
 
338
409
  // Allow outputting fallback gap styles for flex layout type when block gap support isn't available.
339
410
  if (!hasBlockGapSupport && 'flex' !== name) {
@@ -345,8 +416,8 @@ export function getLayoutStyles(_ref6) {
345
416
  const declarations = [];
346
417
 
347
418
  if (spacingStyle.rules) {
348
- Object.entries(spacingStyle.rules).forEach(_ref8 => {
349
- let [cssProperty, cssValue] = _ref8;
419
+ Object.entries(spacingStyle.rules).forEach(_ref10 => {
420
+ let [cssProperty, cssValue] = _ref10;
350
421
  declarations.push(`${cssProperty}: ${cssValue ? cssValue : gapValue}`);
351
422
  });
352
423
  }
@@ -375,12 +446,12 @@ export function getLayoutStyles(_ref6) {
375
446
 
376
447
  if (selector === ROOT_BLOCK_SELECTOR && tree !== null && tree !== void 0 && (_tree$settings3 = tree.settings) !== null && _tree$settings3 !== void 0 && (_tree$settings3$layou = _tree$settings3.layout) !== null && _tree$settings3$layou !== void 0 && _tree$settings3$layou.definitions) {
377
448
  const validDisplayModes = ['block', 'flex', 'grid'];
378
- Object.values(tree.settings.layout.definitions).forEach(_ref9 => {
449
+ Object.values(tree.settings.layout.definitions).forEach(_ref11 => {
379
450
  let {
380
451
  className,
381
452
  displayMode,
382
453
  baseStyles
383
- } = _ref9;
454
+ } = _ref11;
384
455
 
385
456
  if (displayMode && validDisplayModes.includes(displayMode)) {
386
457
  ruleset += `${selector} .${className} { display:${displayMode}; }`;
@@ -391,8 +462,8 @@ export function getLayoutStyles(_ref6) {
391
462
  const declarations = [];
392
463
 
393
464
  if (baseStyle.rules) {
394
- Object.entries(baseStyle.rules).forEach(_ref10 => {
395
- let [cssProperty, cssValue] = _ref10;
465
+ Object.entries(baseStyle.rules).forEach(_ref12 => {
466
+ let [cssProperty, cssValue] = _ref12;
396
467
  declarations.push(`${cssProperty}: ${cssValue}`);
397
468
  });
398
469
  }
@@ -417,8 +488,8 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
417
488
  return nodes;
418
489
  }
419
490
 
420
- const pickStyleKeys = treeToPickFrom => Object.fromEntries(Object.entries(treeToPickFrom !== null && treeToPickFrom !== void 0 ? treeToPickFrom : {}).filter(_ref11 => {
421
- let [key] = _ref11;
491
+ const pickStyleKeys = treeToPickFrom => Object.fromEntries(Object.entries(treeToPickFrom !== null && treeToPickFrom !== void 0 ? treeToPickFrom : {}).filter(_ref13 => {
492
+ let [key] = _ref13;
422
493
  return ['border', 'color', 'dimensions', 'spacing', 'typography', 'filter', 'outline', 'shadow'].includes(key);
423
494
  })); // Top-level.
424
495
 
@@ -432,10 +503,10 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
432
503
  });
433
504
  }
434
505
 
435
- Object.entries(ELEMENTS).forEach(_ref12 => {
506
+ Object.entries(ELEMENTS).forEach(_ref14 => {
436
507
  var _tree$styles, _tree$styles$elements;
437
508
 
438
- let [name, selector] = _ref12;
509
+ let [name, selector] = _ref14;
439
510
 
440
511
  if (!!((_tree$styles = tree.styles) !== null && _tree$styles !== void 0 && (_tree$styles$elements = _tree$styles.elements) !== null && _tree$styles$elements !== void 0 && _tree$styles$elements[name])) {
441
512
  var _tree$styles2, _tree$styles2$element;
@@ -447,10 +518,10 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
447
518
  }
448
519
  }); // Iterate over blocks: they can have styles & elements.
449
520
 
450
- Object.entries((_tree$styles$blocks = (_tree$styles3 = tree.styles) === null || _tree$styles3 === void 0 ? void 0 : _tree$styles3.blocks) !== null && _tree$styles$blocks !== void 0 ? _tree$styles$blocks : {}).forEach(_ref13 => {
521
+ Object.entries((_tree$styles$blocks = (_tree$styles3 = tree.styles) === null || _tree$styles3 === void 0 ? void 0 : _tree$styles3.blocks) !== null && _tree$styles$blocks !== void 0 ? _tree$styles$blocks : {}).forEach(_ref15 => {
451
522
  var _blockSelectors$block, _node$elements;
452
523
 
453
- let [blockName, node] = _ref13;
524
+ let [blockName, node] = _ref15;
454
525
  const blockStyles = pickStyleKeys(node);
455
526
 
456
527
  if (node !== null && node !== void 0 && node.variations) {
@@ -475,8 +546,8 @@ export const getNodesWithStyles = (tree, blockSelectors) => {
475
546
  });
476
547
  }
477
548
 
478
- Object.entries((_node$elements = node === null || node === void 0 ? void 0 : node.elements) !== null && _node$elements !== void 0 ? _node$elements : {}).forEach(_ref14 => {
479
- let [elementName, value] = _ref14;
549
+ Object.entries((_node$elements = node === null || node === void 0 ? void 0 : node.elements) !== null && _node$elements !== void 0 ? _node$elements : {}).forEach(_ref16 => {
550
+ let [elementName, value] = _ref16;
480
551
 
481
552
  if (!!value && !!(blockSelectors !== null && blockSelectors !== void 0 && blockSelectors[blockName]) && !!(ELEMENTS !== null && ELEMENTS !== void 0 && ELEMENTS[elementName])) {
482
553
  var _blockSelectors$block3;
@@ -504,10 +575,10 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
504
575
 
505
576
  const pickPresets = treeToPickFrom => {
506
577
  const presets = {};
507
- PRESET_METADATA.forEach(_ref15 => {
578
+ PRESET_METADATA.forEach(_ref17 => {
508
579
  let {
509
580
  path
510
- } = _ref15;
581
+ } = _ref17;
511
582
  const value = get(treeToPickFrom, path, false);
512
583
 
513
584
  if (value !== false) {
@@ -530,8 +601,8 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
530
601
  } // Blocks.
531
602
 
532
603
 
533
- Object.entries((_tree$settings$blocks = (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.blocks) !== null && _tree$settings$blocks !== void 0 ? _tree$settings$blocks : {}).forEach(_ref16 => {
534
- let [blockName, node] = _ref16;
604
+ Object.entries((_tree$settings$blocks = (_tree$settings5 = tree.settings) === null || _tree$settings5 === void 0 ? void 0 : _tree$settings5.blocks) !== null && _tree$settings$blocks !== void 0 ? _tree$settings$blocks : {}).forEach(_ref18 => {
605
+ let [blockName, node] = _ref18;
535
606
  const blockPresets = pickPresets(node);
536
607
  const blockCustom = node.custom;
537
608
 
@@ -550,12 +621,12 @@ export const getNodesWithSettings = (tree, blockSelectors) => {
550
621
  export const toCustomProperties = (tree, blockSelectors) => {
551
622
  const settings = getNodesWithSettings(tree, blockSelectors);
552
623
  let ruleset = '';
553
- settings.forEach(_ref17 => {
624
+ settings.forEach(_ref19 => {
554
625
  let {
555
626
  presets,
556
627
  custom,
557
628
  selector
558
- } = _ref17;
629
+ } = _ref19;
559
630
  const declarations = getPresetsDeclarations(presets, tree === null || tree === void 0 ? void 0 : tree.settings);
560
631
  const customProps = flattenTree(custom, '--wp--custom--', '--');
561
632
 
@@ -614,7 +685,7 @@ export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasF
614
685
  }
615
686
 
616
687
  ruleset += '}';
617
- nodesWithStyles.forEach(_ref18 => {
688
+ nodesWithStyles.forEach(_ref20 => {
618
689
  let {
619
690
  selector,
620
691
  duotoneSelector,
@@ -623,54 +694,43 @@ export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasF
623
694
  hasLayoutSupport,
624
695
  featureSelectors,
625
696
  styleVariationSelectors
626
- } = _ref18;
697
+ } = _ref20;
627
698
 
628
699
  // Process styles for block support features with custom feature level
629
700
  // CSS selectors set.
630
701
  if (featureSelectors) {
631
- Object.entries(featureSelectors).forEach(_ref19 => {
632
- let [featureName, featureSelector] = _ref19;
633
-
634
- if (styles !== null && styles !== void 0 && styles[featureName]) {
635
- const featureStyles = {
636
- [featureName]: styles[featureName]
637
- };
638
- const featureDeclarations = getStylesDeclarations(featureStyles);
639
- delete styles[featureName];
640
-
641
- if (!!featureDeclarations.length) {
642
- ruleset = ruleset + `${featureSelector}{${featureDeclarations.join(';')} }`;
643
- }
702
+ const featureDeclarations = getFeatureDeclarations(featureSelectors, styles);
703
+ Object.entries(featureDeclarations).forEach(_ref21 => {
704
+ let [cssSelector, declarations] = _ref21;
705
+
706
+ if (!!declarations.length) {
707
+ const rules = declarations.join(';');
708
+ ruleset = ruleset + `${cssSelector}{${rules}}`;
644
709
  }
645
710
  });
646
711
  }
647
712
 
648
713
  if (styleVariationSelectors) {
649
- Object.entries(styleVariationSelectors).forEach(_ref20 => {
714
+ Object.entries(styleVariationSelectors).forEach(_ref22 => {
650
715
  var _styles$variations;
651
716
 
652
- let [styleVariationName, styleVariationSelector] = _ref20;
717
+ let [styleVariationName, styleVariationSelector] = _ref22;
653
718
 
654
719
  if (styles !== null && styles !== void 0 && (_styles$variations = styles.variations) !== null && _styles$variations !== void 0 && _styles$variations[styleVariationName]) {
655
720
  var _styles$variations3;
656
721
 
657
722
  // If the block uses any custom selectors for block support, add those first.
658
723
  if (featureSelectors) {
659
- Object.entries(featureSelectors).forEach(_ref21 => {
660
- var _styles$variations2, _styles$variations2$s;
724
+ var _styles$variations2;
661
725
 
662
- let [featureName, featureSelector] = _ref21;
726
+ const featureDeclarations = getFeatureDeclarations(featureSelectors, styles === null || styles === void 0 ? void 0 : (_styles$variations2 = styles.variations) === null || _styles$variations2 === void 0 ? void 0 : _styles$variations2[styleVariationName]);
727
+ Object.entries(featureDeclarations).forEach(_ref23 => {
728
+ let [baseSelector, declarations] = _ref23;
663
729
 
664
- if (styles !== null && styles !== void 0 && (_styles$variations2 = styles.variations) !== null && _styles$variations2 !== void 0 && (_styles$variations2$s = _styles$variations2[styleVariationName]) !== null && _styles$variations2$s !== void 0 && _styles$variations2$s[featureName]) {
665
- const featureStyles = {
666
- [featureName]: styles.variations[styleVariationName][featureName]
667
- };
668
- const featureDeclarations = getStylesDeclarations(featureStyles);
669
- delete styles.variations[styleVariationName][featureName];
670
-
671
- if (!!featureDeclarations.length) {
672
- ruleset = ruleset + `${concatFeatureVariationSelectorString(featureSelector, styleVariationSelector)}{${featureDeclarations.join(';')} }`;
673
- }
730
+ if (!!declarations.length) {
731
+ const cssSelector = concatFeatureVariationSelectorString(baseSelector, styleVariationSelector);
732
+ const rules = declarations.join(';');
733
+ ruleset = ruleset + `${cssSelector}{${rules}}`;
674
734
  }
675
735
  });
676
736
  } // Otherwise add regular selectors.
@@ -721,14 +781,14 @@ export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasF
721
781
  } // Check for pseudo selector in `styles` and handle separately.
722
782
 
723
783
 
724
- const pseudoSelectorStyles = Object.entries(styles).filter(_ref22 => {
725
- let [key] = _ref22;
784
+ const pseudoSelectorStyles = Object.entries(styles).filter(_ref24 => {
785
+ let [key] = _ref24;
726
786
  return key.startsWith(':');
727
787
  });
728
788
 
729
789
  if (pseudoSelectorStyles !== null && pseudoSelectorStyles !== void 0 && pseudoSelectorStyles.length) {
730
- pseudoSelectorStyles.forEach(_ref23 => {
731
- let [pseudoKey, pseudoStyle] = _ref23;
790
+ pseudoSelectorStyles.forEach(_ref25 => {
791
+ let [pseudoKey, pseudoStyle] = _ref25;
732
792
  const pseudoDeclarations = getStylesDeclarations(pseudoStyle);
733
793
 
734
794
  if (!(pseudoDeclarations !== null && pseudoDeclarations !== void 0 && pseudoDeclarations.length)) {
@@ -764,11 +824,11 @@ export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasF
764
824
  ruleset = ruleset + `.wp-site-blocks > * + * { margin-block-start: ${gapValue}; }`;
765
825
  }
766
826
 
767
- nodesWithSettings.forEach(_ref24 => {
827
+ nodesWithSettings.forEach(_ref26 => {
768
828
  let {
769
829
  selector,
770
830
  presets
771
- } = _ref24;
831
+ } = _ref26;
772
832
 
773
833
  if (ROOT_BLOCK_SELECTOR === selector) {
774
834
  // Do not add extra specificity for top-level classes.
@@ -785,23 +845,43 @@ export const toStyles = function (tree, blockSelectors, hasBlockGapSupport, hasF
785
845
  };
786
846
  export function toSvgFilters(tree, blockSelectors) {
787
847
  const nodesWithSettings = getNodesWithSettings(tree, blockSelectors);
788
- return nodesWithSettings.flatMap(_ref25 => {
848
+ return nodesWithSettings.flatMap(_ref27 => {
789
849
  let {
790
850
  presets
791
- } = _ref25;
851
+ } = _ref27;
792
852
  return getPresetsSvgFilters(presets);
793
853
  });
794
854
  }
855
+
856
+ const getSelectorsConfig = (blockType, rootSelector) => {
857
+ if (!isEmpty(blockType === null || blockType === void 0 ? void 0 : blockType.selectors)) {
858
+ return blockType.selectors;
859
+ }
860
+
861
+ const config = {
862
+ root: rootSelector
863
+ };
864
+ Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(_ref28 => {
865
+ let [featureKey, featureName] = _ref28;
866
+ const featureSelector = getBlockCSSSelector(blockType, featureKey);
867
+
868
+ if (featureSelector) {
869
+ config[featureName] = featureSelector;
870
+ }
871
+ });
872
+ return config;
873
+ };
874
+
795
875
  export const getBlockSelectors = (blockTypes, getBlockStyles) => {
796
876
  const result = {};
797
877
  blockTypes.forEach(blockType => {
798
- var _blockType$supports$_, _blockType$supports, _blockType$supports$c, _blockType$supports2, _blockType$supports2$, _blockType$supports3, _blockType$supports4, _blockType$supports4$, _blockType$supports4$2;
878
+ var _blockType$supports, _blockType$supports2, _blockType$supports2$, _blockType$supports2$2;
799
879
 
800
880
  const name = blockType.name;
801
- 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('/', '-');
802
- 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;
803
- const hasLayoutSupport = !!(blockType !== null && blockType !== void 0 && (_blockType$supports3 = blockType.supports) !== null && _blockType$supports3 !== void 0 && _blockType$supports3.__experimentalLayout);
804
- 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;
881
+ const selector = getBlockCSSSelector(blockType, 'root');
882
+ const duotoneSelector = getBlockCSSSelector(blockType, 'filter.duotone');
883
+ const hasLayoutSupport = !!(blockType !== null && blockType !== void 0 && (_blockType$supports = blockType.supports) !== null && _blockType$supports !== void 0 && _blockType$supports.__experimentalLayout);
884
+ const fallbackGapValue = blockType === null || blockType === void 0 ? void 0 : (_blockType$supports2 = blockType.supports) === null || _blockType$supports2 === void 0 ? void 0 : (_blockType$supports2$ = _blockType$supports2.spacing) === null || _blockType$supports2$ === void 0 ? void 0 : (_blockType$supports2$2 = _blockType$supports2$.blockGap) === null || _blockType$supports2$2 === void 0 ? void 0 : _blockType$supports2$2.__experimentalDefault;
805
885
  const blockStyleVariations = getBlockStyles(name);
806
886
  const styleVariationSelectors = {};
807
887
 
@@ -813,17 +893,7 @@ export const getBlockSelectors = (blockTypes, getBlockStyles) => {
813
893
  } // For each block support feature add any custom selectors.
814
894
 
815
895
 
816
- const featureSelectors = {};
817
- Object.entries(BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS).forEach(_ref26 => {
818
- var _blockType$supports5, _blockType$supports5$;
819
-
820
- let [featureKey, featureName] = _ref26;
821
- 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;
822
-
823
- if (featureSelector) {
824
- featureSelectors[featureName] = scopeSelector(selector, featureSelector);
825
- }
826
- });
896
+ const featureSelectors = getSelectorsConfig(blockType, selector);
827
897
  result[name] = {
828
898
  duotoneSelector,
829
899
  fallbackGapValue,
@@ -907,8 +977,8 @@ export function useGlobalStylesOutput() {
907
977
  const blockSelectors = getBlockSelectors(getBlockTypes(), getBlockStyles);
908
978
  const customProperties = toCustomProperties(mergedConfig, blockSelectors);
909
979
  const globalStyles = toStyles(mergedConfig, blockSelectors, hasBlockGapSupport, hasFallbackGapSupport, disableLayoutStyles);
910
- const filters = toSvgFilters(mergedConfig, blockSelectors);
911
- const stylesheets = [{
980
+ const svgs = toSvgFilters(mergedConfig, blockSelectors);
981
+ const styles = [{
912
982
  css: customProperties,
913
983
  isGlobalStyles: true
914
984
  }, {
@@ -918,6 +988,10 @@ export function useGlobalStylesOutput() {
918
988
  {
919
989
  css: (_mergedConfig$styles$ = mergedConfig.styles.css) !== null && _mergedConfig$styles$ !== void 0 ? _mergedConfig$styles$ : '',
920
990
  isGlobalStyles: true
991
+ }, {
992
+ assets: svgs,
993
+ __unstableType: 'svg',
994
+ isGlobalStyles: true
921
995
  }]; // Loop through the blocks to check if there are custom CSS values.
922
996
  // If there are, get the block selector and push the selector together with
923
997
  // the CSS value to the 'stylesheets' array.
@@ -929,13 +1003,13 @@ export function useGlobalStylesOutput() {
929
1003
  var _mergedConfig$styles$3;
930
1004
 
931
1005
  const selector = blockSelectors[blockType.name].selector;
932
- stylesheets.push({
1006
+ styles.push({
933
1007
  css: processCSSNesting((_mergedConfig$styles$3 = mergedConfig.styles.blocks[blockType.name]) === null || _mergedConfig$styles$3 === void 0 ? void 0 : _mergedConfig$styles$3.css, selector),
934
1008
  isGlobalStyles: true
935
1009
  });
936
1010
  }
937
1011
  });
938
- return [stylesheets, mergedConfig.settings, filters];
1012
+ return [styles, mergedConfig.settings];
939
1013
  }, [hasBlockGapSupport, hasFallbackGapSupport, mergedConfig, disableLayoutStyles]);
940
1014
  }
941
1015
  //# sourceMappingURL=use-global-styles-output.js.map