@wordpress/edit-site 5.0.0 → 5.2.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 (262) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/LICENSE.md +1 -1
  3. package/build/components/add-new-template/new-template-part.js +21 -1
  4. package/build/components/add-new-template/new-template-part.js.map +1 -1
  5. package/build/components/add-new-template/utils.js +9 -1
  6. package/build/components/add-new-template/utils.js.map +1 -1
  7. package/build/components/block-editor/editor-canvas.js +0 -1
  8. package/build/components/block-editor/editor-canvas.js.map +1 -1
  9. package/build/components/block-editor/index.js +17 -52
  10. package/build/components/block-editor/index.js.map +1 -1
  11. package/build/components/block-editor/resize-handle.js +2 -1
  12. package/build/components/block-editor/resize-handle.js.map +1 -1
  13. package/build/components/editor/index.js +5 -17
  14. package/build/components/editor/index.js.map +1 -1
  15. package/build/components/global-styles/block-preview-panel.js +27 -6
  16. package/build/components/global-styles/block-preview-panel.js.map +1 -1
  17. package/build/components/global-styles/border-panel.js +5 -5
  18. package/build/components/global-styles/border-panel.js.map +1 -1
  19. package/build/components/global-styles/context-menu.js +9 -1
  20. package/build/components/global-styles/context-menu.js.map +1 -1
  21. package/build/components/global-styles/custom-css.js +1 -0
  22. package/build/components/global-styles/custom-css.js.map +1 -1
  23. package/build/components/global-styles/dimensions-panel.js +16 -11
  24. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  25. package/build/components/global-styles/global-styles-provider.js +3 -2
  26. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  27. package/build/components/global-styles/screen-background-color.js +6 -6
  28. package/build/components/global-styles/screen-background-color.js.map +1 -1
  29. package/build/components/global-styles/screen-block-list.js +4 -1
  30. package/build/components/global-styles/screen-block-list.js.map +1 -1
  31. package/build/components/global-styles/screen-block.js +2 -6
  32. package/build/components/global-styles/screen-block.js.map +1 -1
  33. package/build/components/global-styles/screen-border.js +12 -2
  34. package/build/components/global-styles/screen-border.js.map +1 -1
  35. package/build/components/global-styles/screen-button-color.js +3 -4
  36. package/build/components/global-styles/screen-button-color.js.map +1 -1
  37. package/build/components/global-styles/screen-colors.js +53 -25
  38. package/build/components/global-styles/screen-colors.js.map +1 -1
  39. package/build/components/global-styles/screen-heading-color.js +9 -10
  40. package/build/components/global-styles/screen-heading-color.js.map +1 -1
  41. package/build/components/global-styles/screen-layout.js +12 -2
  42. package/build/components/global-styles/screen-layout.js.map +1 -1
  43. package/build/components/global-styles/screen-link-color.js +8 -8
  44. package/build/components/global-styles/screen-link-color.js.map +1 -1
  45. package/build/components/global-styles/screen-root.js +7 -2
  46. package/build/components/global-styles/screen-root.js.map +1 -1
  47. package/build/components/global-styles/screen-text-color.js +4 -4
  48. package/build/components/global-styles/screen-text-color.js.map +1 -1
  49. package/build/components/global-styles/screen-typography.js +11 -1
  50. package/build/components/global-styles/screen-typography.js.map +1 -1
  51. package/build/components/global-styles/screen-variations.js +71 -0
  52. package/build/components/global-styles/screen-variations.js.map +1 -0
  53. package/build/components/global-styles/typography-panel.js +9 -8
  54. package/build/components/global-styles/typography-panel.js.map +1 -1
  55. package/build/components/global-styles/typography-utils.js +17 -5
  56. package/build/components/global-styles/typography-utils.js.map +1 -1
  57. package/build/components/global-styles/ui.js +85 -18
  58. package/build/components/global-styles/ui.js.map +1 -1
  59. package/build/components/global-styles/use-global-styles-output.js +119 -33
  60. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  61. package/build/components/global-styles/utils.js +60 -3
  62. package/build/components/global-styles/utils.js.map +1 -1
  63. package/build/components/global-styles/variations-panel.js +85 -0
  64. package/build/components/global-styles/variations-panel.js.map +1 -0
  65. package/build/components/header-edit-mode/document-actions/index.js +10 -41
  66. package/build/components/header-edit-mode/document-actions/index.js.map +1 -1
  67. package/build/components/layout/index.js +129 -87
  68. package/build/components/layout/index.js.map +1 -1
  69. package/build/components/sidebar/index.js +5 -1
  70. package/build/components/sidebar/index.js.map +1 -1
  71. package/build/components/sidebar-edit-mode/index.js +3 -1
  72. package/build/components/sidebar-edit-mode/index.js.map +1 -1
  73. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js +2 -0
  74. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +1 -1
  75. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js +10 -0
  76. package/build/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  77. package/build/components/sidebar-navigation-screen-main/index.js +1 -31
  78. package/build/components/sidebar-navigation-screen-main/index.js.map +1 -1
  79. package/build/components/sidebar-navigation-screen-templates/index.js +3 -22
  80. package/build/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  81. package/build/components/site-hub/index.js +149 -0
  82. package/build/components/site-hub/index.js.map +1 -0
  83. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +54 -0
  84. package/build/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -0
  85. package/build/components/template-details/edit-template-title.js +1 -0
  86. package/build/components/template-details/edit-template-title.js.map +1 -1
  87. package/build/components/template-details/template-part-area-selector.js +1 -0
  88. package/build/components/template-details/template-part-area-selector.js.map +1 -1
  89. package/build/components/use-edited-entity-record/index.js +60 -0
  90. package/build/components/use-edited-entity-record/index.js.map +1 -0
  91. package/build/hooks/index.js +2 -0
  92. package/build/hooks/index.js.map +1 -1
  93. package/build/hooks/push-changes-to-global-styles/index.js +144 -0
  94. package/build/hooks/push-changes-to-global-styles/index.js.map +1 -0
  95. package/build/index.js +5 -0
  96. package/build/index.js.map +1 -1
  97. package/build/store/reducer.js +1 -1
  98. package/build/store/reducer.js.map +1 -1
  99. package/build-module/components/add-new-template/new-template-part.js +20 -1
  100. package/build-module/components/add-new-template/new-template-part.js.map +1 -1
  101. package/build-module/components/add-new-template/utils.js +5 -0
  102. package/build-module/components/add-new-template/utils.js.map +1 -1
  103. package/build-module/components/block-editor/editor-canvas.js +0 -1
  104. package/build-module/components/block-editor/editor-canvas.js.map +1 -1
  105. package/build-module/components/block-editor/index.js +19 -50
  106. package/build-module/components/block-editor/index.js.map +1 -1
  107. package/build-module/components/block-editor/resize-handle.js +2 -1
  108. package/build-module/components/block-editor/resize-handle.js.map +1 -1
  109. package/build-module/components/editor/index.js +2 -13
  110. package/build-module/components/editor/index.js.map +1 -1
  111. package/build-module/components/global-styles/block-preview-panel.js +26 -6
  112. package/build-module/components/global-styles/block-preview-panel.js.map +1 -1
  113. package/build-module/components/global-styles/border-panel.js +5 -5
  114. package/build-module/components/global-styles/border-panel.js.map +1 -1
  115. package/build-module/components/global-styles/context-menu.js +7 -1
  116. package/build-module/components/global-styles/context-menu.js.map +1 -1
  117. package/build-module/components/global-styles/custom-css.js +1 -0
  118. package/build-module/components/global-styles/custom-css.js.map +1 -1
  119. package/build-module/components/global-styles/dimensions-panel.js +16 -11
  120. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  121. package/build-module/components/global-styles/global-styles-provider.js +3 -2
  122. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  123. package/build-module/components/global-styles/screen-background-color.js +6 -6
  124. package/build-module/components/global-styles/screen-background-color.js.map +1 -1
  125. package/build-module/components/global-styles/screen-block-list.js +3 -1
  126. package/build-module/components/global-styles/screen-block-list.js.map +1 -1
  127. package/build-module/components/global-styles/screen-block.js +2 -5
  128. package/build-module/components/global-styles/screen-block.js.map +1 -1
  129. package/build-module/components/global-styles/screen-border.js +10 -2
  130. package/build-module/components/global-styles/screen-border.js.map +1 -1
  131. package/build-module/components/global-styles/screen-button-color.js +3 -4
  132. package/build-module/components/global-styles/screen-button-color.js.map +1 -1
  133. package/build-module/components/global-styles/screen-colors.js +51 -25
  134. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  135. package/build-module/components/global-styles/screen-heading-color.js +9 -10
  136. package/build-module/components/global-styles/screen-heading-color.js.map +1 -1
  137. package/build-module/components/global-styles/screen-layout.js +10 -2
  138. package/build-module/components/global-styles/screen-layout.js.map +1 -1
  139. package/build-module/components/global-styles/screen-link-color.js +8 -8
  140. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  141. package/build-module/components/global-styles/screen-root.js +8 -3
  142. package/build-module/components/global-styles/screen-root.js.map +1 -1
  143. package/build-module/components/global-styles/screen-text-color.js +4 -4
  144. package/build-module/components/global-styles/screen-text-color.js.map +1 -1
  145. package/build-module/components/global-styles/screen-typography.js +9 -1
  146. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  147. package/build-module/components/global-styles/screen-variations.js +54 -0
  148. package/build-module/components/global-styles/screen-variations.js.map +1 -0
  149. package/build-module/components/global-styles/typography-panel.js +9 -8
  150. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  151. package/build-module/components/global-styles/typography-utils.js +17 -5
  152. package/build-module/components/global-styles/typography-utils.js.map +1 -1
  153. package/build-module/components/global-styles/ui.js +84 -19
  154. package/build-module/components/global-styles/ui.js.map +1 -1
  155. package/build-module/components/global-styles/use-global-styles-output.js +121 -35
  156. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  157. package/build-module/components/global-styles/utils.js +56 -3
  158. package/build-module/components/global-styles/utils.js.map +1 -1
  159. package/build-module/components/global-styles/variations-panel.js +68 -0
  160. package/build-module/components/global-styles/variations-panel.js.map +1 -0
  161. package/build-module/components/header-edit-mode/document-actions/index.js +10 -38
  162. package/build-module/components/header-edit-mode/document-actions/index.js.map +1 -1
  163. package/build-module/components/layout/index.js +129 -88
  164. package/build-module/components/layout/index.js.map +1 -1
  165. package/build-module/components/sidebar/index.js +4 -1
  166. package/build-module/components/sidebar/index.js.map +1 -1
  167. package/build-module/components/sidebar-edit-mode/index.js +3 -1
  168. package/build-module/components/sidebar-edit-mode/index.js.map +1 -1
  169. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js +2 -0
  170. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js.map +1 -1
  171. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js +11 -1
  172. package/build-module/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  173. package/build-module/components/sidebar-navigation-screen-main/index.js +2 -27
  174. package/build-module/components/sidebar-navigation-screen-main/index.js.map +1 -1
  175. package/build-module/components/sidebar-navigation-screen-templates/index.js +5 -23
  176. package/build-module/components/sidebar-navigation-screen-templates/index.js.map +1 -1
  177. package/build-module/components/site-hub/index.js +127 -0
  178. package/build-module/components/site-hub/index.js.map +1 -0
  179. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +43 -0
  180. package/build-module/components/sync-state-with-url/use-sync-canvas-mode-with-url.js.map +1 -0
  181. package/build-module/components/template-details/edit-template-title.js +1 -0
  182. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  183. package/build-module/components/template-details/template-part-area-selector.js +1 -0
  184. package/build-module/components/template-details/template-part-area-selector.js.map +1 -1
  185. package/build-module/components/use-edited-entity-record/index.js +48 -0
  186. package/build-module/components/use-edited-entity-record/index.js.map +1 -0
  187. package/build-module/hooks/index.js +1 -0
  188. package/build-module/hooks/index.js.map +1 -1
  189. package/build-module/hooks/push-changes-to-global-styles/index.js +132 -0
  190. package/build-module/hooks/push-changes-to-global-styles/index.js.map +1 -0
  191. package/build-module/index.js +4 -0
  192. package/build-module/index.js.map +1 -1
  193. package/build-module/store/reducer.js +1 -1
  194. package/build-module/store/reducer.js.map +1 -1
  195. package/build-style/style-rtl.css +190 -125
  196. package/build-style/style.css +190 -125
  197. package/package.json +30 -29
  198. package/src/components/add-new-template/new-template-part.js +23 -1
  199. package/src/components/add-new-template/utils.js +14 -0
  200. package/src/components/block-editor/editor-canvas.js +0 -1
  201. package/src/components/block-editor/index.js +14 -59
  202. package/src/components/block-editor/resize-handle.js +6 -2
  203. package/src/components/block-editor/style.scss +43 -7
  204. package/src/components/editor/index.js +2 -17
  205. package/src/components/global-styles/block-preview-panel.js +37 -10
  206. package/src/components/global-styles/border-panel.js +8 -5
  207. package/src/components/global-styles/context-menu.js +6 -0
  208. package/src/components/global-styles/custom-css.js +1 -0
  209. package/src/components/global-styles/dimensions-panel.js +32 -15
  210. package/src/components/global-styles/global-styles-provider.js +11 -5
  211. package/src/components/global-styles/screen-background-color.js +12 -6
  212. package/src/components/global-styles/screen-block-list.js +6 -1
  213. package/src/components/global-styles/screen-block.js +1 -4
  214. package/src/components/global-styles/screen-border.js +8 -3
  215. package/src/components/global-styles/screen-button-color.js +2 -4
  216. package/src/components/global-styles/screen-colors.js +84 -20
  217. package/src/components/global-styles/screen-heading-color.js +8 -10
  218. package/src/components/global-styles/screen-layout.js +11 -3
  219. package/src/components/global-styles/screen-link-color.js +19 -8
  220. package/src/components/global-styles/screen-root.js +34 -27
  221. package/src/components/global-styles/screen-text-color.js +7 -4
  222. package/src/components/global-styles/screen-typography.js +13 -3
  223. package/src/components/global-styles/screen-variations.js +47 -0
  224. package/src/components/global-styles/style.scss +9 -0
  225. package/src/components/global-styles/test/typography-utils.js +72 -23
  226. package/src/components/global-styles/test/use-global-styles-output.js +1 -1
  227. package/src/components/global-styles/typography-panel.js +31 -8
  228. package/src/components/global-styles/typography-utils.js +24 -4
  229. package/src/components/global-styles/ui.js +101 -13
  230. package/src/components/global-styles/use-global-styles-output.js +137 -14
  231. package/src/components/global-styles/utils.js +56 -3
  232. package/src/components/global-styles/variations-panel.js +78 -0
  233. package/src/components/header-edit-mode/document-actions/index.js +18 -37
  234. package/src/components/header-edit-mode/style.scss +1 -0
  235. package/src/components/layout/index.js +217 -172
  236. package/src/components/layout/style.scss +98 -66
  237. package/src/components/list/style.scss +1 -8
  238. package/src/components/sidebar/index.js +4 -1
  239. package/src/components/sidebar-edit-mode/index.js +1 -1
  240. package/src/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-inspector.js +2 -0
  241. package/src/components/sidebar-edit-mode/navigation-menu-sidebar/navigation-menu.js +10 -0
  242. package/src/components/sidebar-edit-mode/navigation-menu-sidebar/style.scss +4 -0
  243. package/src/components/sidebar-navigation-screen/style.scss +2 -4
  244. package/src/components/sidebar-navigation-screen-main/index.js +1 -29
  245. package/src/components/sidebar-navigation-screen-templates/index.js +9 -27
  246. package/src/components/site-hub/index.js +161 -0
  247. package/src/components/site-hub/style.scss +31 -0
  248. package/src/components/sync-state-with-url/use-sync-canvas-mode-with-url.js +40 -0
  249. package/src/components/template-details/edit-template-title.js +1 -0
  250. package/src/components/template-details/template-part-area-selector.js +1 -0
  251. package/src/components/use-edited-entity-record/index.js +37 -0
  252. package/src/hooks/index.js +1 -0
  253. package/src/hooks/push-changes-to-global-styles/index.js +162 -0
  254. package/src/hooks/push-changes-to-global-styles/style.scss +4 -0
  255. package/src/index.js +2 -0
  256. package/src/store/reducer.js +1 -1
  257. package/src/style.scss +2 -0
  258. package/build/components/site-title/index.js +0 -55
  259. package/build/components/site-title/index.js.map +0 -1
  260. package/build-module/components/site-title/index.js +0 -43
  261. package/build-module/components/site-title/index.js.map +0 -1
  262. package/src/components/site-title/index.js +0 -39
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { get, isEmpty, kebabCase, pickBy, set } from 'lodash';
4
+ import { get, isEmpty, kebabCase, set } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -10,6 +10,7 @@ import {
10
10
  __EXPERIMENTAL_STYLE_PROPERTY as STYLE_PROPERTY,
11
11
  __EXPERIMENTAL_ELEMENTS as ELEMENTS,
12
12
  getBlockTypes,
13
+ store as blocksStore,
13
14
  } from '@wordpress/blocks';
14
15
  import { useSelect } from '@wordpress/data';
15
16
  import { useContext, useMemo } from '@wordpress/element';
@@ -171,6 +172,29 @@ function flattenTree( input = {}, prefix, token ) {
171
172
  return result;
172
173
  }
173
174
 
175
+ /**
176
+ * Gets variation selector string from feature selector.
177
+ *
178
+ * @param {string} featureSelector The feature selector.
179
+ *
180
+ * @param {string} styleVariationSelector The style variation selector.
181
+ * @return {string} Combined selector string.
182
+ *
183
+ */
184
+ function concatFeatureVariationSelectorString(
185
+ featureSelector,
186
+ styleVariationSelector
187
+ ) {
188
+ const featureSelectors = featureSelector.split( ',' );
189
+ const combinedSelectors = [];
190
+ featureSelectors.forEach( ( selector ) => {
191
+ combinedSelectors.push(
192
+ `${ styleVariationSelector.trim() }${ selector.trim() }`
193
+ );
194
+ } );
195
+ return combinedSelectors.join( ', ' );
196
+ }
197
+
174
198
  /**
175
199
  * Transform given style tree into a set of style declarations.
176
200
  *
@@ -449,17 +473,19 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
449
473
  }
450
474
 
451
475
  const pickStyleKeys = ( treeToPickFrom ) =>
452
- pickBy( treeToPickFrom, ( value, key ) =>
453
- [
454
- 'border',
455
- 'color',
456
- 'dimensions',
457
- 'spacing',
458
- 'typography',
459
- 'filter',
460
- 'outline',
461
- 'shadow',
462
- ].includes( key )
476
+ Object.fromEntries(
477
+ Object.entries( treeToPickFrom ?? {} ).filter( ( [ key ] ) =>
478
+ [
479
+ 'border',
480
+ 'color',
481
+ 'dimensions',
482
+ 'spacing',
483
+ 'typography',
484
+ 'filter',
485
+ 'outline',
486
+ 'shadow',
487
+ ].includes( key )
488
+ )
463
489
  );
464
490
 
465
491
  // Top-level.
@@ -484,6 +510,16 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
484
510
  Object.entries( tree.styles?.blocks ?? {} ).forEach(
485
511
  ( [ blockName, node ] ) => {
486
512
  const blockStyles = pickStyleKeys( node );
513
+
514
+ if ( node?.variations ) {
515
+ const variations = {};
516
+ Object.keys( node.variations ).forEach( ( variation ) => {
517
+ variations[ variation ] = pickStyleKeys(
518
+ node.variations[ variation ]
519
+ );
520
+ } );
521
+ blockStyles.variations = variations;
522
+ }
487
523
  if (
488
524
  !! blockStyles &&
489
525
  !! blockSelectors?.[ blockName ]?.selector
@@ -499,6 +535,8 @@ export const getNodesWithStyles = ( tree, blockSelectors ) => {
499
535
  styles: blockStyles,
500
536
  featureSelectors:
501
537
  blockSelectors[ blockName ].featureSelectors,
538
+ styleVariationSelectors:
539
+ blockSelectors[ blockName ].styleVariationSelectors,
502
540
  } );
503
541
  }
504
542
 
@@ -647,6 +685,7 @@ export const toStyles = (
647
685
  fallbackGapValue,
648
686
  hasLayoutSupport,
649
687
  featureSelectors,
688
+ styleVariationSelectors,
650
689
  } ) => {
651
690
  // Process styles for block support features with custom feature level
652
691
  // CSS selectors set.
@@ -673,6 +712,69 @@ export const toStyles = (
673
712
  );
674
713
  }
675
714
 
715
+ if ( styleVariationSelectors ) {
716
+ Object.entries( styleVariationSelectors ).forEach(
717
+ ( [ styleVariationName, styleVariationSelector ] ) => {
718
+ if ( styles?.variations?.[ styleVariationName ] ) {
719
+ // If the block uses any custom selectors for block support, add those first.
720
+ if ( featureSelectors ) {
721
+ Object.entries( featureSelectors ).forEach(
722
+ ( [ featureName, featureSelector ] ) => {
723
+ if (
724
+ styles?.variations?.[
725
+ styleVariationName
726
+ ]?.[ featureName ]
727
+ ) {
728
+ const featureStyles = {
729
+ [ featureName ]:
730
+ styles.variations[
731
+ styleVariationName
732
+ ][ featureName ],
733
+ };
734
+ const featureDeclarations =
735
+ getStylesDeclarations(
736
+ featureStyles
737
+ );
738
+ delete styles.variations[
739
+ styleVariationName
740
+ ][ featureName ];
741
+
742
+ if (
743
+ !! featureDeclarations.length
744
+ ) {
745
+ ruleset =
746
+ ruleset +
747
+ `${ concatFeatureVariationSelectorString(
748
+ featureSelector,
749
+ styleVariationSelector
750
+ ) }{${ featureDeclarations.join(
751
+ ';'
752
+ ) } }`;
753
+ }
754
+ }
755
+ }
756
+ );
757
+ }
758
+ // Otherwise add regular selectors.
759
+ const styleVariationDeclarations =
760
+ getStylesDeclarations(
761
+ styles?.variations?.[ styleVariationName ],
762
+ styleVariationSelector,
763
+ useRootPaddingAlign,
764
+ tree
765
+ );
766
+ if ( !! styleVariationDeclarations.length ) {
767
+ ruleset =
768
+ ruleset +
769
+ `${ styleVariationSelector }{${ styleVariationDeclarations.join(
770
+ ';'
771
+ ) }}`;
772
+ }
773
+ }
774
+ }
775
+ );
776
+ }
777
+
676
778
  const duotoneStyles = {};
677
779
  if ( styles?.filter ) {
678
780
  duotoneStyles.filter = styles.filter;
@@ -802,7 +904,7 @@ export function toSvgFilters( tree, blockSelectors ) {
802
904
  } );
803
905
  }
804
906
 
805
- export const getBlockSelectors = ( blockTypes ) => {
907
+ export const getBlockSelectors = ( blockTypes, getBlockStyles ) => {
806
908
  const result = {};
807
909
  blockTypes.forEach( ( blockType ) => {
808
910
  const name = blockType.name;
@@ -815,6 +917,15 @@ export const getBlockSelectors = ( blockTypes ) => {
815
917
  const fallbackGapValue =
816
918
  blockType?.supports?.spacing?.blockGap?.__experimentalDefault;
817
919
 
920
+ const blockStyleVariations = getBlockStyles( name );
921
+ const styleVariationSelectors = {};
922
+ if ( blockStyleVariations?.length ) {
923
+ blockStyleVariations.forEach( ( variation ) => {
924
+ const styleVariationSelector = `.is-style-${ variation.name }${ selector }`;
925
+ styleVariationSelectors[ variation.name ] =
926
+ styleVariationSelector;
927
+ } );
928
+ }
818
929
  // For each block support feature add any custom selectors.
819
930
  const featureSelectors = {};
820
931
  Object.entries( BLOCK_SUPPORT_FEATURE_LEVEL_SELECTORS ).forEach(
@@ -840,6 +951,10 @@ export const getBlockSelectors = ( blockTypes ) => {
840
951
  hasLayoutSupport,
841
952
  name,
842
953
  selector,
954
+ styleVariationSelectors: Object.keys( styleVariationSelectors )
955
+ .length
956
+ ? styleVariationSelectors
957
+ : undefined,
843
958
  };
844
959
  } );
845
960
 
@@ -892,12 +1007,19 @@ export function useGlobalStylesOutput() {
892
1007
  return !! getSettings().disableLayoutStyles;
893
1008
  } );
894
1009
 
1010
+ const getBlockStyles = useSelect( ( select ) => {
1011
+ return select( blocksStore ).getBlockStyles;
1012
+ }, [] );
1013
+
895
1014
  return useMemo( () => {
896
1015
  if ( ! mergedConfig?.styles || ! mergedConfig?.settings ) {
897
1016
  return [];
898
1017
  }
899
1018
  mergedConfig = updateConfigWithSeparator( mergedConfig );
900
- const blockSelectors = getBlockSelectors( getBlockTypes() );
1019
+ const blockSelectors = getBlockSelectors(
1020
+ getBlockTypes(),
1021
+ getBlockStyles
1022
+ );
901
1023
  const customProperties = toCustomProperties(
902
1024
  mergedConfig,
903
1025
  blockSelectors
@@ -909,6 +1031,7 @@ export function useGlobalStylesOutput() {
909
1031
  hasFallbackGapSupport,
910
1032
  disableLayoutStyles
911
1033
  );
1034
+
912
1035
  const filters = toSvgFilters( mergedConfig, blockSelectors );
913
1036
  const stylesheets = [
914
1037
  {
@@ -86,20 +86,60 @@ export const PRESET_METADATA = [
86
86
  },
87
87
  ];
88
88
 
89
- const STYLE_PATH_TO_CSS_VAR_INFIX = {
89
+ export const STYLE_PATH_TO_CSS_VAR_INFIX = {
90
90
  'color.background': 'color',
91
91
  'color.text': 'color',
92
92
  'elements.link.color.text': 'color',
93
+ 'elements.link.:hover.color.text': 'color',
94
+ 'elements.link.typography.fontFamily': 'font-family',
95
+ 'elements.link.typography.fontSize': 'font-size',
93
96
  'elements.button.color.text': 'color',
94
- 'elements.button.backgroundColor': 'background-color',
97
+ 'elements.button.color.background': 'color',
98
+ 'elements.button.typography.fontFamily': 'font-family',
99
+ 'elements.button.typography.fontSize': 'font-size',
95
100
  'elements.heading.color': 'color',
96
- 'elements.heading.backgroundColor': 'background-color',
101
+ 'elements.heading.color.background': 'color',
102
+ 'elements.heading.typography.fontFamily': 'font-family',
97
103
  'elements.heading.gradient': 'gradient',
104
+ 'elements.heading.color.gradient': 'gradient',
105
+ 'elements.h1.color': 'color',
106
+ 'elements.h1.color.background': 'color',
107
+ 'elements.h1.typography.fontFamily': 'font-family',
108
+ 'elements.h1.color.gradient': 'gradient',
109
+ 'elements.h2.color': 'color',
110
+ 'elements.h2.color.background': 'color',
111
+ 'elements.h2.typography.fontFamily': 'font-family',
112
+ 'elements.h2.color.gradient': 'gradient',
113
+ 'elements.h3.color': 'color',
114
+ 'elements.h3.color.background': 'color',
115
+ 'elements.h3.typography.fontFamily': 'font-family',
116
+ 'elements.h3.color.gradient': 'gradient',
117
+ 'elements.h4.color': 'color',
118
+ 'elements.h4.color.background': 'color',
119
+ 'elements.h4.typography.fontFamily': 'font-family',
120
+ 'elements.h4.color.gradient': 'gradient',
121
+ 'elements.h5.color': 'color',
122
+ 'elements.h5.color.background': 'color',
123
+ 'elements.h5.typography.fontFamily': 'font-family',
124
+ 'elements.h5.color.gradient': 'gradient',
125
+ 'elements.h6.color': 'color',
126
+ 'elements.h6.color.background': 'color',
127
+ 'elements.h6.typography.fontFamily': 'font-family',
128
+ 'elements.h6.color.gradient': 'gradient',
98
129
  'color.gradient': 'gradient',
99
130
  'typography.fontSize': 'font-size',
100
131
  'typography.fontFamily': 'font-family',
101
132
  };
102
133
 
134
+ // A static list of block attributes that store global style preset slugs.
135
+ export const STYLE_PATH_TO_PRESET_BLOCK_ATTRIBUTE = {
136
+ 'color.background': 'backgroundColor',
137
+ 'color.text': 'textColor',
138
+ 'color.gradient': 'gradient',
139
+ 'typography.fontSize': 'fontSize',
140
+ 'typography.fontFamily': 'fontFamily',
141
+ };
142
+
103
143
  function findInPresetsBy(
104
144
  features,
105
145
  blockName,
@@ -324,3 +364,16 @@ export function scopeSelector( scope, selector ) {
324
364
 
325
365
  return selectorsScoped.join( ', ' );
326
366
  }
367
+
368
+ /**
369
+ *
370
+ * @param {string} path The variation path in the Global Styles tree.
371
+ *
372
+ * @return {string} The variation class name.
373
+ */
374
+ export function getVariationClassNameFromPath( path ) {
375
+ if ( ! path ) {
376
+ return '';
377
+ }
378
+ return `is-style-${ path.split( '.' )[ 1 ] }`;
379
+ }
@@ -0,0 +1,78 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { store as blocksStore } from '@wordpress/blocks';
5
+ import { useSelect } from '@wordpress/data';
6
+ import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
7
+ /**
8
+ * Internal dependencies
9
+ */
10
+
11
+ import { NavigationButtonAsItem } from './navigation-button';
12
+ import ContextMenu from './context-menu';
13
+
14
+ function getCoreBlockStyles( blockStyles ) {
15
+ return blockStyles?.filter( ( style ) => style.source === 'block' );
16
+ }
17
+
18
+ export function useHasVariationsPanel( name, parentMenu = '' ) {
19
+ const isInsideVariationsPanel = parentMenu.includes( 'variations' );
20
+ const blockStyles = useSelect(
21
+ ( select ) => {
22
+ const { getBlockStyles } = select( blocksStore );
23
+ return getBlockStyles( name );
24
+ },
25
+ [ name ]
26
+ );
27
+ const coreBlockStyles = getCoreBlockStyles( blockStyles );
28
+ return !! coreBlockStyles?.length && ! isInsideVariationsPanel;
29
+ }
30
+
31
+ export function VariationsPanel( { name } ) {
32
+ const blockStyles = useSelect(
33
+ ( select ) => {
34
+ const { getBlockStyles } = select( blocksStore );
35
+ return getBlockStyles( name );
36
+ },
37
+ [ name ]
38
+ );
39
+ const coreBlockStyles = getCoreBlockStyles( blockStyles );
40
+
41
+ return (
42
+ <ItemGroup isBordered isSeparated>
43
+ { coreBlockStyles.map( ( style, index ) => {
44
+ if ( style?.isDefault ) {
45
+ return null;
46
+ }
47
+ return (
48
+ <NavigationButtonAsItem
49
+ key={ index }
50
+ path={
51
+ '/blocks/' +
52
+ encodeURIComponent( name ) +
53
+ '/variations/' +
54
+ encodeURIComponent( style.name )
55
+ }
56
+ aria-label={ style.label }
57
+ >
58
+ { style.label }
59
+ </NavigationButtonAsItem>
60
+ );
61
+ } ) }
62
+ </ItemGroup>
63
+ );
64
+ }
65
+
66
+ export function VariationPanel( { blockName, styleName } ) {
67
+ return (
68
+ <ContextMenu
69
+ parentMenu={
70
+ '/blocks/' +
71
+ encodeURIComponent( blockName ) +
72
+ '/variations/' +
73
+ encodeURIComponent( styleName )
74
+ }
75
+ name={ blockName }
76
+ />
77
+ );
78
+ }
@@ -25,16 +25,13 @@ import {
25
25
  useBlockDisplayInformation,
26
26
  BlockIcon,
27
27
  } from '@wordpress/block-editor';
28
- import { store as coreStore } from '@wordpress/core-data';
29
- import { store as editorStore } from '@wordpress/editor';
30
28
  import { store as preferencesStore } from '@wordpress/preferences';
31
- import { decodeEntities } from '@wordpress/html-entities';
32
29
 
33
30
  /**
34
31
  * Internal dependencies
35
32
  */
36
33
  import TemplateDetails from '../../template-details';
37
- import { store as editSiteStore } from '../../../store';
34
+ import useEditedEntityRecord from '../../use-edited-entity-record';
38
35
 
39
36
  function getBlockDisplayText( block ) {
40
37
  if ( block ) {
@@ -70,36 +67,15 @@ function useSecondaryText() {
70
67
  }
71
68
 
72
69
  export default function DocumentActions() {
73
- const { showIconLabels, entityTitle, template, templateType, isLoaded } =
74
- useSelect( ( select ) => {
75
- const { getEditedPostType, getEditedPostId } =
76
- select( editSiteStore );
77
- const { getEditedEntityRecord } = select( coreStore );
78
- const { __experimentalGetTemplateInfo: getTemplateInfo } =
79
- select( editorStore );
80
- const postType = getEditedPostType();
81
- const postId = getEditedPostId();
82
- const record = getEditedEntityRecord(
83
- 'postType',
84
- postType,
85
- postId
86
- );
87
- const _isLoaded = !! postId;
88
-
89
- return {
90
- showIconLabels: select( preferencesStore ).get(
91
- 'core/edit-site',
92
- 'showIconLabels'
93
- ),
94
- entityTitle: getTemplateInfo( record ).title,
95
- isLoaded: _isLoaded,
96
- template: record,
97
- templateType: postType,
98
- };
99
- }, [] );
100
-
101
- const entityLabel =
102
- templateType === 'wp_template_part' ? 'template part' : 'template';
70
+ const showIconLabels = useSelect(
71
+ ( select ) =>
72
+ select( preferencesStore ).get(
73
+ 'core/edit-site',
74
+ 'showIconLabels'
75
+ ),
76
+ []
77
+ );
78
+ const { isLoaded, record, getTitle } = useEditedEntityRecord();
103
79
  const { label, icon } = useSecondaryText();
104
80
 
105
81
  // Use internal state instead of a ref to make sure that the component
@@ -126,7 +102,7 @@ export default function DocumentActions() {
126
102
  }
127
103
 
128
104
  // Return feedback that the template does not seem to exist.
129
- if ( ! entityTitle ) {
105
+ if ( ! record ) {
130
106
  return (
131
107
  <div className="edit-site-document-actions">
132
108
  { __( 'Template not found' ) }
@@ -134,6 +110,11 @@ export default function DocumentActions() {
134
110
  );
135
111
  }
136
112
 
113
+ const entityLabel =
114
+ record.type === 'wp_template_part'
115
+ ? __( 'template part' )
116
+ : __( 'template' );
117
+
137
118
  return (
138
119
  <div
139
120
  className={ classnames( 'edit-site-document-actions', {
@@ -156,7 +137,7 @@ export default function DocumentActions() {
156
137
  entityLabel
157
138
  ) }
158
139
  </VisuallyHidden>
159
- { decodeEntities( entityTitle ) }
140
+ { getTitle() }
160
141
  </Text>
161
142
  <div className="edit-site-document-actions__secondary-item">
162
143
  <BlockIcon icon={ icon } showColors />
@@ -186,7 +167,7 @@ export default function DocumentActions() {
186
167
  contentClassName="edit-site-document-actions__info-dropdown"
187
168
  renderContent={ ( { onClose } ) => (
188
169
  <TemplateDetails
189
- template={ template }
170
+ template={ record }
190
171
  onClose={ onClose }
191
172
  />
192
173
  ) }
@@ -10,6 +10,7 @@ $header-toolbar-min-width: 335px;
10
10
  width: 100%;
11
11
  justify-content: space-between;
12
12
  border-bottom: $border-width solid $gray-200;
13
+ padding-left: $header-height;
13
14
 
14
15
  .edit-site-header-edit-mode__start {
15
16
  display: flex;