@wordpress/edit-site 4.11.0 → 4.13.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 (180) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/build/components/add-new-template/add-custom-template-modal.js +4 -2
  3. package/build/components/add-new-template/add-custom-template-modal.js.map +1 -1
  4. package/build/components/add-new-template/new-template.js +29 -4
  5. package/build/components/add-new-template/new-template.js.map +1 -1
  6. package/build/components/add-new-template/utils.js +152 -28
  7. package/build/components/add-new-template/utils.js.map +1 -1
  8. package/build/components/block-editor/resizable-editor.js +26 -12
  9. package/build/components/block-editor/resizable-editor.js.map +1 -1
  10. package/build/components/global-styles/border-panel.js +3 -3
  11. package/build/components/global-styles/border-panel.js.map +1 -1
  12. package/build/components/global-styles/dimensions-panel.js +98 -8
  13. package/build/components/global-styles/dimensions-panel.js.map +1 -1
  14. package/build/components/global-styles/hooks.js +4 -4
  15. package/build/components/global-styles/hooks.js.map +1 -1
  16. package/build/components/global-styles/screen-color-palette.js +1 -1
  17. package/build/components/global-styles/screen-color-palette.js.map +1 -1
  18. package/build/components/global-styles/screen-colors.js +51 -7
  19. package/build/components/global-styles/screen-colors.js.map +1 -1
  20. package/build/components/global-styles/screen-heading-color.js +157 -0
  21. package/build/components/global-styles/screen-heading-color.js.map +1 -0
  22. package/build/components/global-styles/screen-typography-element.js +4 -0
  23. package/build/components/global-styles/screen-typography-element.js.map +1 -1
  24. package/build/components/global-styles/screen-typography.js +5 -0
  25. package/build/components/global-styles/screen-typography.js.map +1 -1
  26. package/build/components/global-styles/typography-panel.js +82 -14
  27. package/build/components/global-styles/typography-panel.js.map +1 -1
  28. package/build/components/global-styles/typography-utils.js +217 -0
  29. package/build/components/global-styles/typography-utils.js.map +1 -0
  30. package/build/components/global-styles/ui.js +11 -0
  31. package/build/components/global-styles/ui.js.map +1 -1
  32. package/build/components/global-styles/use-global-styles-output.js +102 -49
  33. package/build/components/global-styles/use-global-styles-output.js.map +1 -1
  34. package/build/components/global-styles/utils.js +54 -5
  35. package/build/components/global-styles/utils.js.map +1 -1
  36. package/build/components/header/document-actions/index.js +1 -0
  37. package/build/components/header/document-actions/index.js.map +1 -1
  38. package/build/components/header/index.js +20 -6
  39. package/build/components/header/index.js.map +1 -1
  40. package/build/components/header/mode-switcher/index.js +0 -4
  41. package/build/components/header/mode-switcher/index.js.map +1 -1
  42. package/build/components/header/more-menu/index.js +13 -3
  43. package/build/components/header/more-menu/index.js.map +1 -1
  44. package/build/components/header/undo-redo/redo.js +2 -1
  45. package/build/components/header/undo-redo/redo.js.map +1 -1
  46. package/build/components/list/actions/index.js +1 -1
  47. package/build/components/list/actions/index.js.map +1 -1
  48. package/build/components/save-button/index.js +2 -3
  49. package/build/components/save-button/index.js.map +1 -1
  50. package/build/components/sidebar/default-sidebar.js +11 -1
  51. package/build/components/sidebar/default-sidebar.js.map +1 -1
  52. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js +2 -2
  53. package/build/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  54. package/build/components/sidebar/plugin-sidebar/index.js +11 -1
  55. package/build/components/sidebar/plugin-sidebar/index.js.map +1 -1
  56. package/build/components/sidebar/template-card/template-actions.js +1 -1
  57. package/build/components/sidebar/template-card/template-actions.js.map +1 -1
  58. package/build/components/template-details/edit-template-title.js +1 -1
  59. package/build/components/template-details/edit-template-title.js.map +1 -1
  60. package/build/components/template-details/index.js +19 -9
  61. package/build/components/template-details/index.js.map +1 -1
  62. package/build/components/template-details/template-areas.js +1 -1
  63. package/build/components/template-details/template-areas.js.map +1 -1
  64. package/build/components/template-details/template-part-area-selector.js +47 -0
  65. package/build/components/template-details/template-part-area-selector.js.map +1 -0
  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/index.js +1 -1
  69. package/build/index.js.map +1 -1
  70. package/build-module/components/add-new-template/add-custom-template-modal.js +4 -2
  71. package/build-module/components/add-new-template/add-custom-template-modal.js.map +1 -1
  72. package/build-module/components/add-new-template/new-template.js +29 -6
  73. package/build-module/components/add-new-template/new-template.js.map +1 -1
  74. package/build-module/components/add-new-template/utils.js +147 -26
  75. package/build-module/components/add-new-template/utils.js.map +1 -1
  76. package/build-module/components/block-editor/resizable-editor.js +26 -12
  77. package/build-module/components/block-editor/resizable-editor.js.map +1 -1
  78. package/build-module/components/global-styles/border-panel.js +3 -3
  79. package/build-module/components/global-styles/border-panel.js.map +1 -1
  80. package/build-module/components/global-styles/dimensions-panel.js +96 -9
  81. package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
  82. package/build-module/components/global-styles/hooks.js +4 -4
  83. package/build-module/components/global-styles/hooks.js.map +1 -1
  84. package/build-module/components/global-styles/screen-color-palette.js +1 -1
  85. package/build-module/components/global-styles/screen-color-palette.js.map +1 -1
  86. package/build-module/components/global-styles/screen-colors.js +51 -7
  87. package/build-module/components/global-styles/screen-colors.js.map +1 -1
  88. package/build-module/components/global-styles/screen-heading-color.js +143 -0
  89. package/build-module/components/global-styles/screen-heading-color.js.map +1 -0
  90. package/build-module/components/global-styles/screen-typography-element.js +4 -0
  91. package/build-module/components/global-styles/screen-typography-element.js.map +1 -1
  92. package/build-module/components/global-styles/screen-typography.js +5 -0
  93. package/build-module/components/global-styles/screen-typography.js.map +1 -1
  94. package/build-module/components/global-styles/typography-panel.js +83 -15
  95. package/build-module/components/global-styles/typography-panel.js.map +1 -1
  96. package/build-module/components/global-styles/typography-utils.js +204 -0
  97. package/build-module/components/global-styles/typography-utils.js.map +1 -0
  98. package/build-module/components/global-styles/ui.js +10 -0
  99. package/build-module/components/global-styles/ui.js.map +1 -1
  100. package/build-module/components/global-styles/use-global-styles-output.js +102 -53
  101. package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
  102. package/build-module/components/global-styles/utils.js +53 -5
  103. package/build-module/components/global-styles/utils.js.map +1 -1
  104. package/build-module/components/header/document-actions/index.js +1 -0
  105. package/build-module/components/header/document-actions/index.js.map +1 -1
  106. package/build-module/components/header/index.js +22 -8
  107. package/build-module/components/header/index.js.map +1 -1
  108. package/build-module/components/header/mode-switcher/index.js +0 -4
  109. package/build-module/components/header/mode-switcher/index.js.map +1 -1
  110. package/build-module/components/header/more-menu/index.js +13 -3
  111. package/build-module/components/header/more-menu/index.js.map +1 -1
  112. package/build-module/components/header/undo-redo/redo.js +3 -2
  113. package/build-module/components/header/undo-redo/redo.js.map +1 -1
  114. package/build-module/components/list/actions/index.js +1 -1
  115. package/build-module/components/list/actions/index.js.map +1 -1
  116. package/build-module/components/save-button/index.js +3 -4
  117. package/build-module/components/save-button/index.js.map +1 -1
  118. package/build-module/components/sidebar/default-sidebar.js +9 -1
  119. package/build-module/components/sidebar/default-sidebar.js.map +1 -1
  120. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js +3 -3
  121. package/build-module/components/sidebar/navigation-menu-sidebar/navigation-menu.js.map +1 -1
  122. package/build-module/components/sidebar/plugin-sidebar/index.js +9 -1
  123. package/build-module/components/sidebar/plugin-sidebar/index.js.map +1 -1
  124. package/build-module/components/sidebar/template-card/template-actions.js +1 -1
  125. package/build-module/components/sidebar/template-card/template-actions.js.map +1 -1
  126. package/build-module/components/template-details/edit-template-title.js +1 -1
  127. package/build-module/components/template-details/edit-template-title.js.map +1 -1
  128. package/build-module/components/template-details/index.js +19 -10
  129. package/build-module/components/template-details/index.js.map +1 -1
  130. package/build-module/components/template-details/template-areas.js +1 -1
  131. package/build-module/components/template-details/template-areas.js.map +1 -1
  132. package/build-module/components/template-details/template-part-area-selector.js +35 -0
  133. package/build-module/components/template-details/template-part-area-selector.js.map +1 -0
  134. package/build-module/components/template-part-converter/convert-to-template-part.js +3 -1
  135. package/build-module/components/template-part-converter/convert-to-template-part.js.map +1 -1
  136. package/build-module/index.js +1 -1
  137. package/build-module/index.js.map +1 -1
  138. package/build-style/style-rtl.css +15 -8
  139. package/build-style/style.css +15 -8
  140. package/package.json +29 -29
  141. package/src/components/add-new-template/add-custom-template-modal.js +12 -3
  142. package/src/components/add-new-template/new-template.js +53 -24
  143. package/src/components/add-new-template/utils.js +145 -16
  144. package/src/components/block-editor/resizable-editor.js +28 -18
  145. package/src/components/editor/style.scss +1 -0
  146. package/src/components/global-styles/border-panel.js +3 -3
  147. package/src/components/global-styles/dimensions-panel.js +139 -33
  148. package/src/components/global-styles/hooks.js +4 -3
  149. package/src/components/global-styles/screen-color-palette.js +1 -1
  150. package/src/components/global-styles/screen-colors.js +46 -4
  151. package/src/components/global-styles/screen-heading-color.js +201 -0
  152. package/src/components/global-styles/screen-typography-element.js +4 -0
  153. package/src/components/global-styles/screen-typography.js +6 -0
  154. package/src/components/global-styles/style.scss +14 -6
  155. package/src/components/global-styles/test/typography-utils.js +130 -0
  156. package/src/components/global-styles/test/use-global-styles-output.js +79 -3
  157. package/src/components/global-styles/test/utils.js +68 -8
  158. package/src/components/global-styles/typography-panel.js +119 -48
  159. package/src/components/global-styles/typography-utils.js +228 -0
  160. package/src/components/global-styles/ui.js +13 -0
  161. package/src/components/global-styles/use-global-styles-output.js +119 -61
  162. package/src/components/global-styles/utils.js +39 -4
  163. package/src/components/header/document-actions/index.js +3 -0
  164. package/src/components/header/index.js +32 -4
  165. package/src/components/header/mode-switcher/index.js +0 -3
  166. package/src/components/header/more-menu/index.js +7 -2
  167. package/src/components/header/undo-redo/redo.js +6 -2
  168. package/src/components/list/actions/index.js +3 -1
  169. package/src/components/save-button/index.js +10 -13
  170. package/src/components/sidebar/default-sidebar.js +12 -0
  171. package/src/components/sidebar/navigation-menu-sidebar/navigation-menu.js +1 -5
  172. package/src/components/sidebar/plugin-sidebar/index.js +12 -0
  173. package/src/components/sidebar/template-card/template-actions.js +3 -1
  174. package/src/components/template-details/edit-template-title.js +7 -3
  175. package/src/components/template-details/index.js +23 -8
  176. package/src/components/template-details/style.scss +0 -5
  177. package/src/components/template-details/template-areas.js +3 -1
  178. package/src/components/template-details/template-part-area-selector.js +38 -0
  179. package/src/components/template-part-converter/convert-to-template-part.js +3 -1
  180. package/src/index.js +1 -1
@@ -0,0 +1,130 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import { getTypographyFontSizeValue } from '../typography-utils';
5
+
6
+ describe( 'typography utils', () => {
7
+ describe( 'getTypographyFontSizeValue', () => {
8
+ it( 'should return the expected values', () => {
9
+ [
10
+ // Default return non-fluid value.
11
+ {
12
+ preset: {
13
+ size: '28px',
14
+ },
15
+ typographySettings: undefined,
16
+ expected: '28px',
17
+ },
18
+ // Should return non-fluid value when fluid is `false`.
19
+ {
20
+ preset: {
21
+ size: '28px',
22
+ fluid: false,
23
+ },
24
+ typographySettings: {
25
+ fluid: true,
26
+ },
27
+ expected: '28px',
28
+ },
29
+ // Should return fluid value.
30
+ {
31
+ preset: {
32
+ size: '1.75rem',
33
+ },
34
+ typographySettings: {
35
+ fluid: true,
36
+ },
37
+ expected:
38
+ 'clamp(1.3125rem, 1.3125rem + ((1vw - 0.48rem) * 2.524), 2.625rem)',
39
+ },
40
+ // Should return default fluid values with empty fluid array.
41
+ {
42
+ preset: {
43
+ size: '28px',
44
+ fluid: [],
45
+ },
46
+ typographySettings: {
47
+ fluid: true,
48
+ },
49
+ expected:
50
+ 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
51
+ },
52
+
53
+ // Should return default fluid values with null values.
54
+ {
55
+ preset: {
56
+ size: '28px',
57
+ fluid: null,
58
+ },
59
+ typographySettings: {
60
+ fluid: true,
61
+ },
62
+ expected:
63
+ 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 2.524), 42px)',
64
+ },
65
+
66
+ // Should return size with invalid fluid units.
67
+ {
68
+ preset: {
69
+ size: '10em',
70
+ fluid: {
71
+ min: '20vw',
72
+ max: '50%',
73
+ },
74
+ },
75
+ typographySettings: {
76
+ fluid: true,
77
+ },
78
+ expected: '10em',
79
+ },
80
+ // Should return fluid clamp value.
81
+ {
82
+ preset: {
83
+ size: '28px',
84
+ fluid: {
85
+ min: '20px',
86
+ max: '50rem',
87
+ },
88
+ },
89
+ typographySettings: {
90
+ fluid: true,
91
+ },
92
+ expected:
93
+ 'clamp(20px, 1.25rem + ((1vw - 7.68px) * 93.75), 50rem)',
94
+ },
95
+ // Should return clamp value with default fluid max value.
96
+ {
97
+ preset: {
98
+ size: '28px',
99
+ fluid: {
100
+ min: '2.6rem',
101
+ },
102
+ },
103
+ typographySettings: {
104
+ fluid: true,
105
+ },
106
+ expected:
107
+ 'clamp(2.6rem, 2.6rem + ((1vw - 0.48rem) * 0.048), 42px)',
108
+ },
109
+ // Should return clamp value with default fluid min value.
110
+ {
111
+ preset: {
112
+ size: '28px',
113
+ fluid: {
114
+ max: '80px',
115
+ },
116
+ },
117
+ typographySettings: {
118
+ fluid: true,
119
+ },
120
+ expected:
121
+ 'clamp(21px, 1.3125rem + ((1vw - 7.68px) * 7.091), 80px)',
122
+ },
123
+ ].forEach( ( { preset, typographySettings, expected } ) => {
124
+ expect(
125
+ getTypographyFontSizeValue( preset, typographySettings )
126
+ ).toBe( expected );
127
+ } );
128
+ } );
129
+ } );
130
+ } );
@@ -13,6 +13,7 @@ import {
13
13
  getBlockSelectors,
14
14
  toCustomProperties,
15
15
  toStyles,
16
+ getStylesDeclarations,
16
17
  } from '../use-global-styles-output';
17
18
  import { ROOT_BLOCK_SELECTOR } from '../utils';
18
19
 
@@ -478,11 +479,24 @@ describe( 'global styles renderer', () => {
478
479
 
479
480
  expect( toStyles( tree, blockSelectors ) ).toEqual(
480
481
  'body {margin: 0;}' +
481
- '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;}' +
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;}' +
482
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; }' +
483
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;}'
484
485
  );
485
486
  } );
487
+ it( 'should output content and wide size variables if values are specified', () => {
488
+ const tree = {
489
+ settings: {
490
+ layout: {
491
+ contentSize: '840px',
492
+ wideSize: '1100px',
493
+ },
494
+ },
495
+ };
496
+ expect( toStyles( tree, 'body' ) ).toEqual(
497
+ 'body {margin: 0; --wp--style--global--content-size: 840px; --wp--style--global--wide-size: 1100px;}.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; }'
498
+ );
499
+ } );
486
500
  } );
487
501
 
488
502
  describe( 'getLayoutStyles', () => {
@@ -582,7 +596,7 @@ describe( 'global styles renderer', () => {
582
596
  } );
583
597
 
584
598
  expect( layoutStyles ).toEqual(
585
- 'body .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; }'
599
+ ':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; }'
586
600
  );
587
601
  } );
588
602
 
@@ -647,7 +661,7 @@ describe( 'global styles renderer', () => {
647
661
  } );
648
662
 
649
663
  expect( layoutStyles ).toEqual(
650
- '.wp-block-group.is-layout-flex { gap: 2em; }'
664
+ ':where(.wp-block-group.is-layout-flex) { gap: 2em; }'
651
665
  );
652
666
  } );
653
667
  } );
@@ -681,4 +695,66 @@ describe( 'global styles renderer', () => {
681
695
  } );
682
696
  } );
683
697
  } );
698
+
699
+ describe( 'getStylesDeclarations', () => {
700
+ const blockStyles = {
701
+ spacing: {
702
+ padding: {
703
+ top: '33px',
704
+ right: '33px',
705
+ bottom: '33px',
706
+ left: '33px',
707
+ },
708
+ },
709
+ color: {
710
+ background: 'var:preset|color|light-green-cyan',
711
+ },
712
+ typography: {
713
+ fontFamily: 'sans-serif',
714
+ },
715
+ };
716
+
717
+ it( 'Should output padding variables and other properties if useRootPaddingAwareAlignments is enabled', () => {
718
+ expect(
719
+ getStylesDeclarations( blockStyles, 'body', true )
720
+ ).toEqual( [
721
+ '--wp--style--root--padding-top: 33px',
722
+ '--wp--style--root--padding-right: 33px',
723
+ '--wp--style--root--padding-bottom: 33px',
724
+ '--wp--style--root--padding-left: 33px',
725
+ 'background-color: var(--wp--preset--color--light-green-cyan)',
726
+ 'font-family: sans-serif',
727
+ ] );
728
+ } );
729
+
730
+ it( 'Should output padding and other properties if useRootPaddingAwareAlignments is disabled', () => {
731
+ expect(
732
+ getStylesDeclarations( blockStyles, 'body', false )
733
+ ).toEqual( [
734
+ 'background-color: var(--wp--preset--color--light-green-cyan)',
735
+ 'padding-top: 33px',
736
+ 'padding-right: 33px',
737
+ 'padding-bottom: 33px',
738
+ 'padding-left: 33px',
739
+ 'font-family: sans-serif',
740
+ ] );
741
+ } );
742
+
743
+ it( 'Should not output padding variables if selector is not root', () => {
744
+ expect(
745
+ getStylesDeclarations(
746
+ blockStyles,
747
+ '.wp-block-button__link',
748
+ true
749
+ )
750
+ ).toEqual( [
751
+ 'background-color: var(--wp--preset--color--light-green-cyan)',
752
+ 'padding-top: 33px',
753
+ 'padding-right: 33px',
754
+ 'padding-bottom: 33px',
755
+ 'padding-left: 33px',
756
+ 'font-family: sans-serif',
757
+ ] );
758
+ } );
759
+ } );
684
760
  } );
@@ -4,7 +4,7 @@
4
4
  import { getPresetVariableFromValue, getValueFromVariable } from '../utils';
5
5
 
6
6
  describe( 'editor utils', () => {
7
- const styles = {
7
+ const themeJson = {
8
8
  version: 1,
9
9
  settings: {
10
10
  color: {
@@ -57,7 +57,7 @@ describe( 'editor utils', () => {
57
57
  describe( 'when a provided global style (e.g. fontFamily, color,etc.) does not exist', () => {
58
58
  it( 'returns the originally provided value', () => {
59
59
  const actual = getPresetVariableFromValue(
60
- styles.settings,
60
+ themeJson.settings,
61
61
  context,
62
62
  'fakePropertyName',
63
63
  value
@@ -69,7 +69,7 @@ describe( 'editor utils', () => {
69
69
  describe( 'when a global style is cleared by the user', () => {
70
70
  it( 'returns an undefined preset variable', () => {
71
71
  const actual = getPresetVariableFromValue(
72
- styles.settings,
72
+ themeJson.settings,
73
73
  context,
74
74
  propertyName,
75
75
  undefined
@@ -83,7 +83,7 @@ describe( 'editor utils', () => {
83
83
  it( 'returns the originally provided value', () => {
84
84
  const customValue = '#6e4545';
85
85
  const actual = getPresetVariableFromValue(
86
- styles.settings,
86
+ themeJson.settings,
87
87
  context,
88
88
  propertyName,
89
89
  customValue
@@ -95,7 +95,7 @@ describe( 'editor utils', () => {
95
95
  describe( 'and it is a preset value', () => {
96
96
  it( 'returns the preset variable', () => {
97
97
  const actual = getPresetVariableFromValue(
98
- styles.settings,
98
+ themeJson.settings,
99
99
  context,
100
100
  propertyName,
101
101
  value
@@ -110,7 +110,7 @@ describe( 'editor utils', () => {
110
110
  describe( 'when provided an invalid variable', () => {
111
111
  it( 'returns the originally provided value', () => {
112
112
  const actual = getValueFromVariable(
113
- styles.settings,
113
+ themeJson,
114
114
  'root',
115
115
  undefined
116
116
  );
@@ -122,7 +122,7 @@ describe( 'editor utils', () => {
122
122
  describe( 'when provided a preset variable', () => {
123
123
  it( 'retrieves the correct preset value', () => {
124
124
  const actual = getValueFromVariable(
125
- styles.settings,
125
+ themeJson,
126
126
  'root',
127
127
  'var:preset|color|primary'
128
128
  );
@@ -134,7 +134,7 @@ describe( 'editor utils', () => {
134
134
  describe( 'when provided a custom variable', () => {
135
135
  it( 'retrieves the correct custom value', () => {
136
136
  const actual = getValueFromVariable(
137
- styles.settings,
137
+ themeJson,
138
138
  'root',
139
139
  'var(--wp--custom--color--secondary)'
140
140
  );
@@ -142,5 +142,65 @@ describe( 'editor utils', () => {
142
142
  expect( actual ).toBe( '#a65555' );
143
143
  } );
144
144
  } );
145
+
146
+ describe( 'when provided a dynamic reference', () => {
147
+ it( 'retrieves the referenced value', () => {
148
+ const stylesWithRefs = {
149
+ ...themeJson,
150
+ styles: {
151
+ color: {
152
+ background: {
153
+ ref: 'styles.color.text',
154
+ },
155
+ text: 'purple-rain',
156
+ },
157
+ },
158
+ };
159
+ const actual = getValueFromVariable( stylesWithRefs, 'root', {
160
+ ref: 'styles.color.text',
161
+ } );
162
+
163
+ expect( actual ).toBe( stylesWithRefs.styles.color.text );
164
+ } );
165
+
166
+ it( 'returns the originally provided value where value is dynamic reference and reference does not exist', () => {
167
+ const stylesWithRefs = {
168
+ ...themeJson,
169
+ styles: {
170
+ color: {
171
+ text: {
172
+ ref: 'styles.background.text',
173
+ },
174
+ },
175
+ },
176
+ };
177
+ const actual = getValueFromVariable( stylesWithRefs, 'root', {
178
+ ref: 'styles.color.text',
179
+ } );
180
+
181
+ expect( actual ).toBe( stylesWithRefs.styles.color.text );
182
+ } );
183
+
184
+ it( 'returns the originally provided value where value is dynamic reference', () => {
185
+ const stylesWithRefs = {
186
+ ...themeJson,
187
+ styles: {
188
+ color: {
189
+ background: {
190
+ ref: 'styles.color.text',
191
+ },
192
+ text: {
193
+ ref: 'styles.background.text',
194
+ },
195
+ },
196
+ },
197
+ };
198
+ const actual = getValueFromVariable( stylesWithRefs, 'root', {
199
+ ref: 'styles.color.text',
200
+ } );
201
+
202
+ expect( actual ).toBe( stylesWithRefs.styles.color.text );
203
+ } );
204
+ } );
145
205
  } );
146
206
  } );
@@ -10,9 +10,12 @@ import {
10
10
  import {
11
11
  PanelBody,
12
12
  FontSizePicker,
13
- __experimentalSpacer as Spacer,
13
+ __experimentalToggleGroupControl as ToggleGroupControl,
14
+ __experimentalToggleGroupControlOption as ToggleGroupControlOption,
15
+ __experimentalGrid as Grid,
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,54 +144,111 @@ export default function TypographyPanel( { name, element } ) {
130
144
  >
131
145
  Aa
132
146
  </div>
133
-
134
- { supports.includes( 'fontFamily' ) && (
135
- <FontFamilyControl
136
- fontFamilies={ fontFamilies }
137
- value={ fontFamily }
138
- onChange={ setFontFamily }
139
- />
140
- ) }
141
- { supports.includes( 'fontSize' ) && (
142
- <FontSizePicker
143
- value={ fontSize }
144
- onChange={ setFontSize }
145
- fontSizes={ fontSizes }
146
- disableCustomFontSizes={ disableCustomFontSizes }
147
- />
148
- ) }
149
- { hasLineHeightEnabled && (
150
- <Spacer marginBottom={ 6 }>
147
+ <Grid columns={ 2 } rowGap={ 16 } columnGap={ 8 }>
148
+ { element === 'heading' && (
149
+ <div className="edit-site-typography-panel__full-width-control">
150
+ <ToggleGroupControl
151
+ label={ __( 'Select heading level' ) }
152
+ hideLabelFromVision
153
+ value={ selectedLevel }
154
+ onChange={ setCurrentTab }
155
+ isBlock
156
+ size="__unstable-large"
157
+ __nextHasNoMarginBottom
158
+ >
159
+ <ToggleGroupControlOption
160
+ value="heading"
161
+ /* translators: 'All' refers to selecting all heading levels
162
+ and applying the same style to h1-h6. */
163
+ label={ __( 'All' ) }
164
+ />
165
+ <ToggleGroupControlOption
166
+ value="h1"
167
+ label={ __( 'H1' ) }
168
+ />
169
+ <ToggleGroupControlOption
170
+ value="h2"
171
+ label={ __( 'H2' ) }
172
+ />
173
+ <ToggleGroupControlOption
174
+ value="h3"
175
+ label={ __( 'H3' ) }
176
+ />
177
+ <ToggleGroupControlOption
178
+ value="h4"
179
+ label={ __( 'H4' ) }
180
+ />
181
+ <ToggleGroupControlOption
182
+ value="h5"
183
+ label={ __( 'H5' ) }
184
+ />
185
+ <ToggleGroupControlOption
186
+ value="h6"
187
+ label={ __( 'H6' ) }
188
+ />
189
+ </ToggleGroupControl>
190
+ </div>
191
+ ) }
192
+ { supports.includes( 'fontFamily' ) && (
193
+ <div className="edit-site-typography-panel__full-width-control">
194
+ <FontFamilyControl
195
+ fontFamilies={ fontFamilies }
196
+ value={ fontFamily }
197
+ onChange={ setFontFamily }
198
+ size="__unstable-large"
199
+ __nextHasNoMarginBottom
200
+ />
201
+ </div>
202
+ ) }
203
+ { hasFontSizeEnabled && (
204
+ <div className="edit-site-typography-panel__full-width-control">
205
+ <FontSizePicker
206
+ value={ fontSize }
207
+ onChange={ setFontSize }
208
+ fontSizes={ fontSizes }
209
+ disableCustomFontSizes={ disableCustomFontSizes }
210
+ size="__unstable-large"
211
+ __nextHasNoMarginBottom
212
+ />
213
+ </div>
214
+ ) }
215
+ { hasAppearanceControl && (
216
+ <FontAppearanceControl
217
+ value={ {
218
+ fontStyle,
219
+ fontWeight,
220
+ } }
221
+ onChange={ ( {
222
+ fontStyle: newFontStyle,
223
+ fontWeight: newFontWeight,
224
+ } ) => {
225
+ setFontStyle( newFontStyle );
226
+ setFontWeight( newFontWeight );
227
+ } }
228
+ hasFontStyles={ hasFontStyles }
229
+ hasFontWeights={ hasFontWeights }
230
+ size="__unstable-large"
231
+ __nextHasNoMarginBottom
232
+ />
233
+ ) }
234
+ { hasLineHeightEnabled && (
151
235
  <LineHeightControl
152
- __nextHasNoMarginBottom={ true }
236
+ __nextHasNoMarginBottom
237
+ __unstableInputWidth="auto"
153
238
  value={ lineHeight }
154
239
  onChange={ setLineHeight }
240
+ size="__unstable-large"
241
+ />
242
+ ) }
243
+ { hasLetterSpacingControl && (
244
+ <LetterSpacingControl
245
+ value={ letterSpacing }
246
+ onChange={ setLetterSpacing }
247
+ size="__unstable-large"
248
+ __unstableInputWidth="auto"
155
249
  />
156
- </Spacer>
157
- ) }
158
- { hasAppearanceControl && (
159
- <FontAppearanceControl
160
- value={ {
161
- fontStyle,
162
- fontWeight,
163
- } }
164
- onChange={ ( {
165
- fontStyle: newFontStyle,
166
- fontWeight: newFontWeight,
167
- } ) => {
168
- setFontStyle( newFontStyle );
169
- setFontWeight( newFontWeight );
170
- } }
171
- hasFontStyles={ hasFontStyles }
172
- hasFontWeights={ hasFontWeights }
173
- />
174
- ) }
175
- { hasLetterSpacingControl && (
176
- <LetterSpacingControl
177
- value={ letterSpacing }
178
- onChange={ setLetterSpacing }
179
- />
180
- ) }
250
+ ) }
251
+ </Grid>
181
252
  </PanelBody>
182
253
  );
183
254
  }