@wordpress/edit-site 4.9.0 → 4.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (199) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/components/add-new-template/add-custom-generic-template-modal.js +84 -0
  3. package/build/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  4. package/build/components/add-new-template/add-custom-template-modal.js +82 -61
  5. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  6. package/build/components/add-new-template/new-template.js +94 -81
  7. package/build/components/add-new-template/new-template.js.map +1 -1
  8. package/build/components/add-new-template/utils.js +574 -57
  9. package/build/components/add-new-template/utils.js.map +1 -1
  10. package/build/components/block-editor/index.js +1 -3
  11. package/build/components/block-editor/index.js.map +1 -1
  12. package/build/components/code-editor/index.js +17 -4
  13. package/build/components/code-editor/index.js.map +1 -1
  14. package/build/components/editor/index.js +16 -0
  15. package/build/components/editor/index.js.map +1 -1
  16. package/build/components/error-boundary/index.js +6 -0
  17. package/build/components/error-boundary/index.js.map +1 -1
  18. package/build/components/global-styles/dimensions-panel.js +191 -21
  19. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  20. package/build/components/global-styles/global-styles-provider.js +4 -2
  21. package/build/components/global-styles/global-styles-provider.js.map +1 -1
  22. package/build/components/global-styles/hooks.js +11 -2
  23. package/build/components/global-styles/hooks.js.map +1 -1
  24. package/build/components/global-styles/screen-color-palette.js +13 -17
  25. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  26. package/build/components/global-styles/screen-colors.js +59 -7
  27. package/build/components/global-styles/screen-colors.js.map +1 -1
  28. package/build/components/global-styles/screen-heading-color.js +157 -0
  29. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  30. package/build/components/global-styles/screen-link-color.js +48 -14
  31. package/build/components/global-styles/screen-link-color.js.map +1 -1
  32. package/build/components/global-styles/screen-typography-element.js +4 -0
  33. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  34. package/build/components/global-styles/screen-typography.js +5 -0
  35. package/build/components/global-styles/screen-typography.js.map +1 -1
  36. package/build/components/global-styles/typography-panel.js +73 -12
  37. package/build/components/global-styles/typography-panel.js.map +1 -1
  38. package/build/components/global-styles/typography-utils.js +217 -0
  39. package/build/components/global-styles/typography-utils.js.map +1 -0
  40. package/build/components/global-styles/ui.js +11 -0
  41. package/build/components/global-styles/ui.js.map +1 -1
  42. package/build/components/global-styles/use-global-styles-output.js +298 -61
  43. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  44. package/build/components/global-styles/utils.js +49 -3
  45. package/build/components/global-styles/utils.js.map +1 -1
  46. package/build/components/header/index.js +22 -10
  47. package/build/components/header/index.js.map +1 -1
  48. package/build/components/header/undo-redo/redo.js +2 -1
  49. package/build/components/header/undo-redo/redo.js.map +1 -1
  50. package/build/components/keyboard-shortcut-help-modal/index.js +1 -3
  51. package/build/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  52. package/build/components/list/actions/index.js +1 -1
  53. package/build/components/list/actions/index.js.map +1 -1
  54. package/build/components/save-button/index.js +2 -3
  55. package/build/components/save-button/index.js.map +1 -1
  56. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  57. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  58. package/build/components/sidebar/template-card/template-actions.js +1 -1
  59. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  60. package/build/components/template-details/edit-template-title.js +11 -3
  61. package/build/components/template-details/edit-template-title.js.map +1 -1
  62. package/build/components/template-details/index.js +2 -21
  63. package/build/components/template-details/index.js.map +1 -1
  64. package/build/components/template-details/template-areas.js +1 -1
  65. package/build/components/template-details/template-areas.js.map +1 -1
  66. package/build/components/template-part-converter/convert-to-template-part.js +4 -1
  67. package/build/components/template-part-converter/convert-to-template-part.js.map +1 -1
  68. package/build/hooks/index.js +2 -0
  69. package/build/hooks/index.js.map +1 -1
  70. package/build/hooks/template-part-edit.js +86 -0
  71. package/build/hooks/template-part-edit.js.map +1 -0
  72. package/build/store/selectors.js +4 -1
  73. package/build/store/selectors.js.map +1 -1
  74. package/build-module/components/add-new-template/add-custom-generic-template-modal.js +77 -0
  75. package/build-module/components/add-new-template/add-custom-generic-template-modal.js.map +1 -0
  76. package/build-module/components/add-new-template/add-custom-template-modal.js +82 -61
  77. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  78. package/build-module/components/add-new-template/new-template.js +96 -84
  79. package/build-module/components/add-new-template/new-template.js.map +1 -1
  80. package/build-module/components/add-new-template/utils.js +555 -50
  81. package/build-module/components/add-new-template/utils.js.map +1 -1
  82. package/build-module/components/block-editor/index.js +1 -2
  83. package/build-module/components/block-editor/index.js.map +1 -1
  84. package/build-module/components/code-editor/index.js +18 -5
  85. package/build-module/components/code-editor/index.js.map +1 -1
  86. package/build-module/components/editor/index.js +16 -0
  87. package/build-module/components/editor/index.js.map +1 -1
  88. package/build-module/components/error-boundary/index.js +5 -0
  89. package/build-module/components/error-boundary/index.js.map +1 -1
  90. package/build-module/components/global-styles/dimensions-panel.js +191 -22
  91. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  92. package/build-module/components/global-styles/global-styles-provider.js +4 -2
  93. package/build-module/components/global-styles/global-styles-provider.js.map +1 -1
  94. package/build-module/components/global-styles/hooks.js +11 -2
  95. package/build-module/components/global-styles/hooks.js.map +1 -1
  96. package/build-module/components/global-styles/screen-color-palette.js +14 -19
  97. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  98. package/build-module/components/global-styles/screen-colors.js +59 -7
  99. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  100. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  101. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  102. package/build-module/components/global-styles/screen-link-color.js +47 -14
  103. package/build-module/components/global-styles/screen-link-color.js.map +1 -1
  104. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  105. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  106. package/build-module/components/global-styles/screen-typography.js +5 -0
  107. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  108. package/build-module/components/global-styles/typography-panel.js +74 -13
  109. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  110. package/build-module/components/global-styles/typography-utils.js +204 -0
  111. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  112. package/build-module/components/global-styles/ui.js +10 -0
  113. package/build-module/components/global-styles/ui.js.map +1 -1
  114. package/build-module/components/global-styles/use-global-styles-output.js +294 -69
  115. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  116. package/build-module/components/global-styles/utils.js +47 -4
  117. package/build-module/components/global-styles/utils.js.map +1 -1
  118. package/build-module/components/header/index.js +25 -12
  119. package/build-module/components/header/index.js.map +1 -1
  120. package/build-module/components/header/undo-redo/redo.js +3 -2
  121. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  122. package/build-module/components/keyboard-shortcut-help-modal/index.js +1 -2
  123. package/build-module/components/keyboard-shortcut-help-modal/index.js.map +1 -1
  124. package/build-module/components/list/actions/index.js +1 -1
  125. package/build-module/components/list/actions/index.js.map +1 -1
  126. package/build-module/components/save-button/index.js +3 -4
  127. package/build-module/components/save-button/index.js.map +1 -1
  128. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  129. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  130. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  131. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  132. package/build-module/components/template-details/edit-template-title.js +12 -3
  133. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  134. package/build-module/components/template-details/index.js +3 -22
  135. package/build-module/components/template-details/index.js.map +1 -1
  136. package/build-module/components/template-details/template-areas.js +1 -1
  137. package/build-module/components/template-details/template-areas.js.map +1 -1
  138. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  139. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  140. package/build-module/hooks/index.js +1 -0
  141. package/build-module/hooks/index.js.map +1 -1
  142. package/build-module/hooks/template-part-edit.js +67 -0
  143. package/build-module/hooks/template-part-edit.js.map +1 -0
  144. package/build-module/store/selectors.js +5 -2
  145. package/build-module/store/selectors.js.map +1 -1
  146. package/build-style/style-rtl.css +55 -48
  147. package/build-style/style.css +55 -48
  148. package/package.json +29 -29
  149. package/src/components/add-new-template/add-custom-generic-template-modal.js +97 -0
  150. package/src/components/add-new-template/add-custom-template-modal.js +93 -68
  151. package/src/components/add-new-template/new-template.js +126 -95
  152. package/src/components/add-new-template/style.scss +41 -8
  153. package/src/components/add-new-template/utils.js +622 -80
  154. package/src/components/block-editor/index.js +0 -2
  155. package/src/components/code-editor/index.js +15 -5
  156. package/src/components/editor/index.js +11 -0
  157. package/src/components/error-boundary/index.js +5 -0
  158. package/src/components/global-styles/dimensions-panel.js +214 -24
  159. package/src/components/global-styles/global-styles-provider.js +8 -9
  160. package/src/components/global-styles/hooks.js +18 -0
  161. package/src/components/global-styles/screen-color-palette.js +25 -27
  162. package/src/components/global-styles/screen-colors.js +55 -7
  163. package/src/components/global-styles/screen-heading-color.js +201 -0
  164. package/src/components/global-styles/screen-link-color.js +65 -23
  165. package/src/components/global-styles/screen-typography-element.js +4 -0
  166. package/src/components/global-styles/screen-typography.js +6 -0
  167. package/src/components/global-styles/style.scss +14 -11
  168. package/src/components/global-styles/test/typography-utils.js +130 -0
  169. package/src/components/global-styles/test/use-global-styles-output.js +296 -2
  170. package/src/components/global-styles/typography-panel.js +85 -16
  171. package/src/components/global-styles/typography-utils.js +228 -0
  172. package/src/components/global-styles/ui.js +13 -0
  173. package/src/components/global-styles/use-global-styles-output.js +387 -89
  174. package/src/components/global-styles/utils.js +43 -2
  175. package/src/components/header/index.js +37 -13
  176. package/src/components/header/style.scss +5 -3
  177. package/src/components/header/undo-redo/redo.js +6 -2
  178. package/src/components/keyboard-shortcut-help-modal/index.js +1 -2
  179. package/src/components/keyboard-shortcut-help-modal/style.scss +0 -5
  180. package/src/components/list/actions/index.js +3 -1
  181. package/src/components/list/style.scss +0 -8
  182. package/src/components/save-button/index.js +10 -13
  183. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  184. package/src/components/sidebar/style.scss +4 -0
  185. package/src/components/sidebar/template-card/template-actions.js +3 -1
  186. package/src/components/template-details/edit-template-title.js +10 -2
  187. package/src/components/template-details/index.js +7 -22
  188. package/src/components/template-details/template-areas.js +3 -1
  189. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
  190. package/src/components/test/error-boundary.js +38 -0
  191. package/src/hooks/index.js +1 -0
  192. package/src/hooks/template-part-edit.js +82 -0
  193. package/src/store/selectors.js +11 -5
  194. package/src/style.scss +0 -1
  195. package/build/components/edit-template-part-menu-button/index.js +0 -90
  196. package/build/components/edit-template-part-menu-button/index.js.map +0 -1
  197. package/build-module/components/edit-template-part-menu-button/index.js +0 -72
  198. package/build-module/components/edit-template-part-menu-button/index.js.map +0 -1
  199. package/src/components/edit-template-part-menu-button/index.js +0 -82
@@ -7,10 +7,13 @@ import { __EXPERIMENTAL_ELEMENTS as ELEMENTS } from '@wordpress/blocks';
7
7
  * Internal dependencies
8
8
  */
9
9
  import {
10
+ getLayoutStyles,
10
11
  getNodesWithSettings,
11
12
  getNodesWithStyles,
13
+ getBlockSelectors,
12
14
  toCustomProperties,
13
15
  toStyles,
16
+ getStylesDeclarations,
14
17
  } from '../use-global-styles-output';
15
18
  import { ROOT_BLOCK_SELECTOR } from '../utils';
16
19
 
@@ -56,6 +59,11 @@ describe( 'global styles renderer', () => {
56
59
  },
57
60
  },
58
61
  },
62
+ 'core/image': {
63
+ border: {
64
+ radius: '9999px',
65
+ },
66
+ },
59
67
  },
60
68
  elements: {
61
69
  link: {
@@ -83,6 +91,10 @@ describe( 'global styles renderer', () => {
83
91
  'core/heading': {
84
92
  selector: '.my-heading1, .my-heading2',
85
93
  },
94
+ 'core/image': {
95
+ selector: '.my-image',
96
+ featureSelectors: '.my-image img, .my-image .crop-area',
97
+ },
86
98
  };
87
99
 
88
100
  expect( getNodesWithStyles( tree, blockSelectors ) ).toEqual( [
@@ -158,6 +170,15 @@ describe( 'global styles renderer', () => {
158
170
  },
159
171
  selector: '.my-heading1 a, .my-heading2 a',
160
172
  },
173
+ {
174
+ styles: {
175
+ border: {
176
+ radius: '9999px',
177
+ },
178
+ },
179
+ selector: '.my-image',
180
+ featureSelectors: '.my-image img, .my-image .crop-area',
181
+ },
161
182
  ] );
162
183
  } );
163
184
  } );
@@ -429,6 +450,14 @@ describe( 'global styles renderer', () => {
429
450
  },
430
451
  },
431
452
  },
453
+ 'core/image': {
454
+ color: {
455
+ text: 'red',
456
+ },
457
+ border: {
458
+ radius: '9999px',
459
+ },
460
+ },
432
461
  },
433
462
  },
434
463
  };
@@ -440,14 +469,279 @@ describe( 'global styles renderer', () => {
440
469
  'core/heading': {
441
470
  selector: 'h1,h2,h3,h4,h5,h6',
442
471
  },
472
+ 'core/image': {
473
+ selector: '.wp-block-image',
474
+ featureSelectors: {
475
+ border: '.wp-block-image img, .wp-block-image .wp-crop-area',
476
+ },
477
+ },
443
478
  };
444
479
 
445
480
  expect( toStyles( tree, blockSelectors ) ).toEqual(
446
481
  'body {margin: 0;}' +
447
- 'body{background-color: red;margin: 10px;padding: 10px;}h1{font-size: 42px;}a{color: blue;}a:hover{color: orange;}a:focus{color: orange;}.wp-block-group{margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}h1,h2,h3,h4,h5,h6{color: orange;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color: hotpink;}h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color: red;}h1 a:focus,h2 a:focus,h3 a:focus,h4 a:focus,h5 a:focus,h6 a:focus{color: red;}' +
448
- '.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }' +
482
+ 'body{background-color: red;margin: 10px;padding: 10px;}a{color: blue;}a:hover{color: orange;}a:focus{color: orange;}h1{font-size: 42px;}.wp-block-group{margin-top: 10px;margin-right: 20px;margin-bottom: 30px;margin-left: 40px;padding-top: 11px;padding-right: 22px;padding-bottom: 33px;padding-left: 44px;}h1,h2,h3,h4,h5,h6{color: orange;}h1 a,h2 a,h3 a,h4 a,h5 a,h6 a{color: hotpink;}h1 a:hover,h2 a:hover,h3 a:hover,h4 a:hover,h5 a:hover,h6 a:hover{color: red;}h1 a:focus,h2 a:focus,h3 a:focus,h4 a:focus,h5 a:focus,h6 a:focus{color: red;}' +
483
+ '.wp-block-image img, .wp-block-image .wp-crop-area{border-radius: 9999px }.wp-block-image{color: red;}.wp-site-blocks > .alignleft { float: left; margin-right: 2em; }.wp-site-blocks > .alignright { float: right; margin-left: 2em; }.wp-site-blocks > .aligncenter { justify-content: center; margin-left: auto; margin-right: auto; }' +
449
484
  '.has-white-color{color: var(--wp--preset--color--white) !important;}.has-white-background-color{background-color: var(--wp--preset--color--white) !important;}.has-white-border-color{border-color: var(--wp--preset--color--white) !important;}.has-black-color{color: var(--wp--preset--color--black) !important;}.has-black-background-color{background-color: var(--wp--preset--color--black) !important;}.has-black-border-color{border-color: var(--wp--preset--color--black) !important;}h1.has-blue-color,h2.has-blue-color,h3.has-blue-color,h4.has-blue-color,h5.has-blue-color,h6.has-blue-color{color: var(--wp--preset--color--blue) !important;}h1.has-blue-background-color,h2.has-blue-background-color,h3.has-blue-background-color,h4.has-blue-background-color,h5.has-blue-background-color,h6.has-blue-background-color{background-color: var(--wp--preset--color--blue) !important;}h1.has-blue-border-color,h2.has-blue-border-color,h3.has-blue-border-color,h4.has-blue-border-color,h5.has-blue-border-color,h6.has-blue-border-color{border-color: var(--wp--preset--color--blue) !important;}'
450
485
  );
451
486
  } );
452
487
  } );
488
+
489
+ describe( 'getLayoutStyles', () => {
490
+ const layoutDefinitionsTree = {
491
+ settings: {
492
+ layout: {
493
+ definitions: {
494
+ default: {
495
+ name: 'default',
496
+ slug: 'flow',
497
+ className: 'is-layout-flow',
498
+ baseStyles: [
499
+ {
500
+ selector: ' > .alignleft',
501
+ rules: {
502
+ float: 'left',
503
+ 'margin-inline-start': '0',
504
+ 'margin-inline-end': '2em',
505
+ },
506
+ },
507
+ {
508
+ selector: ' > .alignright',
509
+ rules: {
510
+ float: 'right',
511
+ 'margin-inline-start': '2em',
512
+ 'margin-inline-end': '0',
513
+ },
514
+ },
515
+ {
516
+ selector: ' > .aligncenter',
517
+ rules: {
518
+ 'margin-left': 'auto !important',
519
+ 'margin-right': 'auto !important',
520
+ },
521
+ },
522
+ ],
523
+ spacingStyles: [
524
+ {
525
+ selector: ' > *',
526
+ rules: {
527
+ 'margin-block-start': '0',
528
+ 'margin-block-end': '0',
529
+ },
530
+ },
531
+ {
532
+ selector: ' > * + *',
533
+ rules: {
534
+ 'margin-block-start': null,
535
+ 'margin-block-end': '0',
536
+ },
537
+ },
538
+ ],
539
+ },
540
+ flex: {
541
+ name: 'flex',
542
+ slug: 'flex',
543
+ className: 'is-layout-flex',
544
+ displayMode: 'flex',
545
+ baseStyles: [
546
+ {
547
+ selector: '',
548
+ rules: {
549
+ 'flex-wrap': 'wrap',
550
+ 'align-items': 'center',
551
+ },
552
+ },
553
+ {
554
+ selector: ' > *',
555
+ rules: {
556
+ margin: '0',
557
+ },
558
+ },
559
+ ],
560
+ spacingStyles: [
561
+ {
562
+ selector: '',
563
+ rules: {
564
+ gap: null,
565
+ },
566
+ },
567
+ ],
568
+ },
569
+ },
570
+ },
571
+ },
572
+ };
573
+
574
+ it( 'should return fallback gap flex layout style, and all base styles, if block styles are enabled and blockGap is disabled', () => {
575
+ const style = { spacing: { blockGap: '12px' } };
576
+
577
+ const layoutStyles = getLayoutStyles( {
578
+ tree: layoutDefinitionsTree,
579
+ style,
580
+ selector: 'body',
581
+ hasBlockGapSupport: false,
582
+ hasFallbackGapSupport: true,
583
+ } );
584
+
585
+ expect( layoutStyles ).toEqual(
586
+ ':where(.is-layout-flex) { gap: 0.5em; }body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }'
587
+ );
588
+ } );
589
+
590
+ it( 'should return fallback gap layout styles, and base styles, if blockGap is enabled, but there is no blockGap value', () => {
591
+ const style = {};
592
+
593
+ const layoutStyles = getLayoutStyles( {
594
+ tree: layoutDefinitionsTree,
595
+ style,
596
+ selector: 'body',
597
+ hasBlockGapSupport: true,
598
+ hasFallbackGapSupport: true,
599
+ } );
600
+
601
+ expect( layoutStyles ).toEqual(
602
+ 'body .is-layout-flow > * { margin-block-start: 0; margin-block-end: 0; }body .is-layout-flow > * + * { margin-block-start: 0.5em; margin-block-end: 0; }body .is-layout-flex { gap: 0.5em; }body { --wp--style--block-gap: 0.5em; }body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }'
603
+ );
604
+ } );
605
+
606
+ it( 'should return real gap layout style if blockGap is enabled, and base styles', () => {
607
+ const style = { spacing: { blockGap: '12px' } };
608
+
609
+ const layoutStyles = getLayoutStyles( {
610
+ tree: layoutDefinitionsTree,
611
+ style,
612
+ selector: 'body',
613
+ hasBlockGapSupport: true,
614
+ hasFallbackGapSupport: true,
615
+ } );
616
+
617
+ expect( layoutStyles ).toEqual(
618
+ 'body .is-layout-flow > * { margin-block-start: 0; margin-block-end: 0; }body .is-layout-flow > * + * { margin-block-start: 12px; margin-block-end: 0; }body .is-layout-flex { gap: 12px; }body { --wp--style--block-gap: 12px; }body .is-layout-flow > .alignleft { float: left; margin-inline-start: 0; margin-inline-end: 2em; }body .is-layout-flow > .alignright { float: right; margin-inline-start: 2em; margin-inline-end: 0; }body .is-layout-flow > .aligncenter { margin-left: auto !important; margin-right: auto !important; }body .is-layout-flex { display:flex; }body .is-layout-flex { flex-wrap: wrap; align-items: center; }body .is-layout-flex > * { margin: 0; }'
619
+ );
620
+ } );
621
+
622
+ it( 'should return real gap layout style if blockGap is enabled', () => {
623
+ const style = { spacing: { blockGap: '12px' } };
624
+
625
+ const layoutStyles = getLayoutStyles( {
626
+ tree: layoutDefinitionsTree,
627
+ style,
628
+ selector: '.wp-block-group',
629
+ hasBlockGapSupport: true,
630
+ hasFallbackGapSupport: true,
631
+ } );
632
+
633
+ expect( layoutStyles ).toEqual(
634
+ '.wp-block-group.is-layout-flow > * { margin-block-start: 0; margin-block-end: 0; }.wp-block-group.is-layout-flow > * + * { margin-block-start: 12px; margin-block-end: 0; }.wp-block-group.is-layout-flex { gap: 12px; }'
635
+ );
636
+ } );
637
+
638
+ it( 'should return fallback gap flex layout style for a block if blockGap is disabled, and a fallback value is provided', () => {
639
+ const style = { spacing: { blockGap: '12px' } };
640
+
641
+ const layoutStyles = getLayoutStyles( {
642
+ tree: layoutDefinitionsTree,
643
+ style,
644
+ selector: '.wp-block-group',
645
+ hasBlockGapSupport: false, // This means that the fallback value will be used instead of the "real" one.
646
+ hasFallbackGapSupport: true,
647
+ fallbackGapValue: '2em',
648
+ } );
649
+
650
+ expect( layoutStyles ).toEqual(
651
+ ':where(.wp-block-group.is-layout-flex) { gap: 2em; }'
652
+ );
653
+ } );
654
+ } );
655
+
656
+ describe( 'getBlockSelectors', () => {
657
+ it( 'should return block selectors data', () => {
658
+ const imageSupports = {
659
+ __experimentalBorder: {
660
+ radius: true,
661
+ __experimentalSelector: 'img, .crop-area',
662
+ },
663
+ color: {
664
+ __experimentalDuotone: 'img',
665
+ },
666
+ __experimentalSelector: '.my-image',
667
+ };
668
+ const imageBlock = { name: 'core/image', supports: imageSupports };
669
+ const blockTypes = [ imageBlock ];
670
+
671
+ expect( getBlockSelectors( blockTypes ) ).toEqual( {
672
+ 'core/image': {
673
+ name: imageBlock.name,
674
+ selector: imageSupports.__experimentalSelector,
675
+ duotoneSelector: imageSupports.color.__experimentalDuotone,
676
+ fallbackGapValue: undefined,
677
+ featureSelectors: {
678
+ border: '.my-image img, .my-image .crop-area',
679
+ },
680
+ hasLayoutSupport: false,
681
+ },
682
+ } );
683
+ } );
684
+ } );
685
+
686
+ describe( 'getStylesDeclarations', () => {
687
+ const blockStyles = {
688
+ spacing: {
689
+ padding: {
690
+ top: '33px',
691
+ right: '33px',
692
+ bottom: '33px',
693
+ left: '33px',
694
+ },
695
+ },
696
+ color: {
697
+ background: 'var:preset|color|light-green-cyan',
698
+ },
699
+ typography: {
700
+ fontFamily: 'sans-serif',
701
+ },
702
+ };
703
+
704
+ it( 'Should output padding variables and other properties if useRootPaddingAwareAlignments is enabled', () => {
705
+ expect(
706
+ getStylesDeclarations( blockStyles, 'body', true )
707
+ ).toEqual( [
708
+ 'font-family: sans-serif',
709
+ '--wp--style--root--padding-top: 33px',
710
+ '--wp--style--root--padding-right: 33px',
711
+ '--wp--style--root--padding-bottom: 33px',
712
+ '--wp--style--root--padding-left: 33px',
713
+ 'background-color: var(--wp--preset--color--light-green-cyan)',
714
+ ] );
715
+ } );
716
+
717
+ it( 'Should output padding and other properties if useRootPaddingAwareAlignments is disabled', () => {
718
+ expect(
719
+ getStylesDeclarations( blockStyles, 'body', false )
720
+ ).toEqual( [
721
+ 'font-family: sans-serif',
722
+ 'background-color: var(--wp--preset--color--light-green-cyan)',
723
+ 'padding-top: 33px',
724
+ 'padding-right: 33px',
725
+ 'padding-bottom: 33px',
726
+ 'padding-left: 33px',
727
+ ] );
728
+ } );
729
+
730
+ it( 'Should not output padding variables if selector is not root', () => {
731
+ expect(
732
+ getStylesDeclarations(
733
+ blockStyles,
734
+ '.wp-block-button__link',
735
+ true
736
+ )
737
+ ).toEqual( [
738
+ 'font-family: sans-serif',
739
+ 'background-color: var(--wp--preset--color--light-green-cyan)',
740
+ 'padding-top: 33px',
741
+ 'padding-right: 33px',
742
+ 'padding-bottom: 33px',
743
+ 'padding-left: 33px',
744
+ ] );
745
+ } );
746
+ } );
453
747
  } );
@@ -11,8 +11,11 @@ import {
11
11
  PanelBody,
12
12
  FontSizePicker,
13
13
  __experimentalSpacer as Spacer,
14
+ __experimentalToggleGroupControl as ToggleGroupControl,
15
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption,
14
16
  } from '@wordpress/components';
15
-
17
+ import { __ } from '@wordpress/i18n';
18
+ import { useState } from '@wordpress/element';
16
19
  /**
17
20
  * Internal dependencies
18
21
  */
@@ -59,9 +62,14 @@ function useHasLetterSpacingControl( name ) {
59
62
  }
60
63
 
61
64
  export default function TypographyPanel( { name, element } ) {
65
+ const [ selectedLevel, setCurrentTab ] = useState( 'heading' );
62
66
  const supports = getSupportedGlobalStylesPanels( name );
63
- const prefix =
64
- element === 'text' || ! element ? '' : `elements.${ element }.`;
67
+ let prefix = '';
68
+ if ( element === 'heading' ) {
69
+ prefix = `elements.${ selectedLevel }.`;
70
+ } else if ( element && element !== 'text' ) {
71
+ prefix = `elements.${ element }.`;
72
+ }
65
73
  const [ fontSizes ] = useSetting( 'typography.fontSizes', name );
66
74
  const disableCustomFontSizes = ! useSetting(
67
75
  'typography.customFontSize',
@@ -78,6 +86,12 @@ export default function TypographyPanel( { name, element } ) {
78
86
  const hasAppearanceControl = useHasAppearanceControl( name );
79
87
  const hasLetterSpacingControl = useHasLetterSpacingControl( name );
80
88
 
89
+ /* Disable font size controls when the option to style all headings is selected. */
90
+ let hasFontSizeEnabled = supports.includes( 'fontSize' );
91
+ if ( element === 'heading' && selectedLevel === 'heading' ) {
92
+ hasFontSizeEnabled = false;
93
+ }
94
+
81
95
  const [ fontFamily, setFontFamily ] = useStyle(
82
96
  prefix + 'typography.fontFamily',
83
97
  name
@@ -130,30 +144,79 @@ export default function TypographyPanel( { name, element } ) {
130
144
  >
131
145
  Aa
132
146
  </div>
133
-
147
+ { element === 'heading' && (
148
+ <div>
149
+ <h4>{ __( 'Select heading level' ) }</h4>
150
+ <ToggleGroupControl
151
+ label={ __( 'Select heading level' ) }
152
+ hideLabelFromVision={ true }
153
+ value={ selectedLevel }
154
+ onChange={ setCurrentTab }
155
+ isBlock
156
+ size="__unstable-large"
157
+ >
158
+ <ToggleGroupControlOption
159
+ value="heading"
160
+ /* translators: 'All' refers to selecting all heading levels
161
+ and applying the same style to h1-h6. */
162
+ label={ __( 'All' ) }
163
+ />
164
+ <ToggleGroupControlOption
165
+ value="h1"
166
+ label={ __( 'H1' ) }
167
+ />
168
+ <ToggleGroupControlOption
169
+ value="h2"
170
+ label={ __( 'H2' ) }
171
+ />
172
+ <ToggleGroupControlOption
173
+ value="h3"
174
+ label={ __( 'H3' ) }
175
+ />
176
+ <ToggleGroupControlOption
177
+ value="h4"
178
+ label={ __( 'H4' ) }
179
+ />
180
+ <ToggleGroupControlOption
181
+ value="h5"
182
+ label={ __( 'H5' ) }
183
+ />
184
+ <ToggleGroupControlOption
185
+ value="h6"
186
+ label={ __( 'H6' ) }
187
+ />
188
+ </ToggleGroupControl>
189
+ </div>
190
+ ) }
134
191
  { supports.includes( 'fontFamily' ) && (
135
192
  <FontFamilyControl
136
193
  fontFamilies={ fontFamilies }
137
194
  value={ fontFamily }
138
195
  onChange={ setFontFamily }
196
+ size="__unstable-large"
139
197
  />
140
198
  ) }
141
- { supports.includes( 'fontSize' ) && (
199
+ { hasFontSizeEnabled && (
142
200
  <FontSizePicker
143
201
  value={ fontSize }
144
202
  onChange={ setFontSize }
145
203
  fontSizes={ fontSizes }
146
204
  disableCustomFontSizes={ disableCustomFontSizes }
205
+ size="__unstable-large"
147
206
  />
148
207
  ) }
149
208
  { hasLineHeightEnabled && (
150
- <Spacer marginBottom={ 6 }>
151
- <LineHeightControl
152
- __nextHasNoMarginBottom={ true }
153
- value={ lineHeight }
154
- onChange={ setLineHeight }
155
- />
156
- </Spacer>
209
+ <div className="edit-site-typography-panel__half-width-control">
210
+ <Spacer marginBottom={ 6 }>
211
+ <LineHeightControl
212
+ __nextHasNoMarginBottom={ true }
213
+ __unstableInputWidth="auto"
214
+ value={ lineHeight }
215
+ onChange={ setLineHeight }
216
+ size="__unstable-large"
217
+ />
218
+ </Spacer>
219
+ </div>
157
220
  ) }
158
221
  { hasAppearanceControl && (
159
222
  <FontAppearanceControl
@@ -170,13 +233,19 @@ export default function TypographyPanel( { name, element } ) {
170
233
  } }
171
234
  hasFontStyles={ hasFontStyles }
172
235
  hasFontWeights={ hasFontWeights }
236
+ size="__unstable-large"
237
+ __nextUnconstrainedWidth
173
238
  />
174
239
  ) }
175
240
  { hasLetterSpacingControl && (
176
- <LetterSpacingControl
177
- value={ letterSpacing }
178
- onChange={ setLetterSpacing }
179
- />
241
+ <div className="edit-site-typography-panel__half-width-control">
242
+ <LetterSpacingControl
243
+ value={ letterSpacing }
244
+ onChange={ setLetterSpacing }
245
+ size="__unstable-large"
246
+ __unstableInputWidth="auto"
247
+ />
248
+ </div>
180
249
  ) }
181
250
  </PanelBody>
182
251
  );