@wordpress/block-library 7.4.0 → 7.5.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 (269) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/audio/edit.js +3 -15
  3. package/build/audio/edit.js.map +1 -1
  4. package/build/button/edit.native.js +7 -3
  5. package/build/button/edit.native.js.map +1 -1
  6. package/build/comment-template/edit.js +1 -3
  7. package/build/comment-template/edit.js.map +1 -1
  8. package/build/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  9. package/{build-module/comments-query-loop → build/comments}/edit/comments-inspector-controls.js.map +1 -1
  10. package/build/{comments-query-loop → comments}/edit.js +3 -3
  11. package/build/comments/edit.js.map +1 -0
  12. package/build/{comments-query-loop → comments}/index.js +1 -1
  13. package/build/comments/index.js.map +1 -0
  14. package/build/{comments-query-loop → comments}/save.js +2 -2
  15. package/build/comments/save.js.map +1 -0
  16. package/build/comments-title/edit.js +7 -5
  17. package/build/comments-title/edit.js.map +1 -1
  18. package/build/cover/edit.js +4 -71
  19. package/build/cover/edit.js.map +1 -1
  20. package/build/cover/edit.native.js +36 -15
  21. package/build/cover/edit.native.js.map +1 -1
  22. package/build/cover/transforms.js +77 -6
  23. package/build/cover/transforms.js.map +1 -1
  24. package/build/cover/use-cover-is-dark.js +81 -0
  25. package/build/cover/use-cover-is-dark.js.map +1 -0
  26. package/build/cover/use-cover-is-dark.native.js +60 -0
  27. package/build/cover/use-cover-is-dark.native.js.map +1 -0
  28. package/build/group/index.js +1 -0
  29. package/build/group/index.js.map +1 -1
  30. package/build/heading/transforms.js +8 -4
  31. package/build/heading/transforms.js.map +1 -1
  32. package/build/index.js +4 -6
  33. package/build/index.js.map +1 -1
  34. package/build/latest-posts/edit.native.js +49 -0
  35. package/build/latest-posts/edit.native.js.map +1 -1
  36. package/build/navigation/edit/index.js +5 -28
  37. package/build/navigation/edit/index.js.map +1 -1
  38. package/build/navigation/edit/inner-blocks.js +5 -7
  39. package/build/navigation/edit/inner-blocks.js.map +1 -1
  40. package/build/navigation/index.js +0 -1
  41. package/build/navigation/index.js.map +1 -1
  42. package/build/navigation/view-modal.js +25 -0
  43. package/build/navigation/view-modal.js.map +1 -1
  44. package/build/navigation-link/edit.js +29 -30
  45. package/build/navigation-link/edit.js.map +1 -1
  46. package/build/navigation-submenu/edit.js +14 -14
  47. package/build/navigation-submenu/edit.js.map +1 -1
  48. package/build/paragraph/edit.js +10 -0
  49. package/build/paragraph/edit.js.map +1 -1
  50. package/build/paragraph/use-enter.js +94 -0
  51. package/build/paragraph/use-enter.js.map +1 -0
  52. package/build/post-comment/index.js +1 -1
  53. package/build/post-comments/edit.js +120 -35
  54. package/build/post-comments/edit.js.map +1 -1
  55. package/build/post-comments/index.js +3 -2
  56. package/build/post-comments/index.js.map +1 -1
  57. package/build/post-comments-form/edit.js +38 -4
  58. package/build/post-comments-form/edit.js.map +1 -1
  59. package/build/post-comments-form/form.js +48 -0
  60. package/build/post-comments-form/form.js.map +1 -0
  61. package/build/post-comments-form/index.js +1 -0
  62. package/build/post-comments-form/index.js.map +1 -1
  63. package/build/post-content/edit.js +1 -1
  64. package/build/post-content/edit.js.map +1 -1
  65. package/build/post-excerpt/edit.js +1 -1
  66. package/build/post-excerpt/edit.js.map +1 -1
  67. package/build/post-terms/edit.js +25 -3
  68. package/build/post-terms/edit.js.map +1 -1
  69. package/build/post-terms/index.js +8 -0
  70. package/build/post-terms/index.js.map +1 -1
  71. package/build/query-no-results/edit.js +1 -1
  72. package/build/query-no-results/edit.js.map +1 -1
  73. package/build/quote/index.js +1 -0
  74. package/build/quote/index.js.map +1 -1
  75. package/build/separator/index.js +3 -0
  76. package/build/separator/index.js.map +1 -1
  77. package/build/video/edit.js +3 -7
  78. package/build/video/edit.js.map +1 -1
  79. package/build-module/audio/edit.js +3 -15
  80. package/build-module/audio/edit.js.map +1 -1
  81. package/build-module/button/edit.native.js +7 -3
  82. package/build-module/button/edit.native.js.map +1 -1
  83. package/build-module/comment-template/edit.js +1 -3
  84. package/build-module/comment-template/edit.js.map +1 -1
  85. package/build-module/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  86. package/build-module/comments/edit/comments-inspector-controls.js.map +1 -0
  87. package/build-module/{comments-query-loop → comments}/edit.js +2 -2
  88. package/build-module/comments/edit.js.map +1 -0
  89. package/build-module/{comments-query-loop → comments}/index.js +1 -1
  90. package/build-module/comments/index.js.map +1 -0
  91. package/build-module/{comments-query-loop → comments}/save.js +1 -1
  92. package/build-module/comments/save.js.map +1 -0
  93. package/build-module/comments-title/edit.js +7 -5
  94. package/build-module/comments-title/edit.js.map +1 -1
  95. package/build-module/cover/edit.js +4 -71
  96. package/build-module/cover/edit.js.map +1 -1
  97. package/build-module/cover/edit.native.js +35 -16
  98. package/build-module/cover/edit.native.js.map +1 -1
  99. package/build-module/cover/transforms.js +74 -6
  100. package/build-module/cover/transforms.js.map +1 -1
  101. package/build-module/cover/use-cover-is-dark.js +70 -0
  102. package/build-module/cover/use-cover-is-dark.js.map +1 -0
  103. package/build-module/cover/use-cover-is-dark.native.js +51 -0
  104. package/build-module/cover/use-cover-is-dark.native.js.map +1 -0
  105. package/build-module/group/index.js +1 -0
  106. package/build-module/group/index.js.map +1 -1
  107. package/build-module/heading/transforms.js +8 -4
  108. package/build-module/heading/transforms.js.map +1 -1
  109. package/build-module/index.js +3 -4
  110. package/build-module/index.js.map +1 -1
  111. package/build-module/latest-posts/edit.native.js +51 -2
  112. package/build-module/latest-posts/edit.native.js.map +1 -1
  113. package/build-module/navigation/edit/index.js +6 -28
  114. package/build-module/navigation/edit/index.js.map +1 -1
  115. package/build-module/navigation/edit/inner-blocks.js +5 -7
  116. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  117. package/build-module/navigation/index.js +0 -1
  118. package/build-module/navigation/index.js.map +1 -1
  119. package/build-module/navigation/view-modal.js +24 -0
  120. package/build-module/navigation/view-modal.js.map +1 -1
  121. package/build-module/navigation-link/edit.js +29 -30
  122. package/build-module/navigation-link/edit.js.map +1 -1
  123. package/build-module/navigation-submenu/edit.js +14 -14
  124. package/build-module/navigation-submenu/edit.js.map +1 -1
  125. package/build-module/paragraph/edit.js +9 -0
  126. package/build-module/paragraph/edit.js.map +1 -1
  127. package/build-module/paragraph/use-enter.js +81 -0
  128. package/build-module/paragraph/use-enter.js.map +1 -0
  129. package/build-module/post-comment/index.js +1 -1
  130. package/build-module/post-comments/edit.js +120 -37
  131. package/build-module/post-comments/edit.js.map +1 -1
  132. package/build-module/post-comments/index.js +3 -2
  133. package/build-module/post-comments/index.js.map +1 -1
  134. package/build-module/post-comments-form/edit.js +38 -6
  135. package/build-module/post-comments-form/edit.js.map +1 -1
  136. package/build-module/post-comments-form/form.js +39 -0
  137. package/build-module/post-comments-form/form.js.map +1 -0
  138. package/build-module/post-comments-form/index.js +1 -0
  139. package/build-module/post-comments-form/index.js.map +1 -1
  140. package/build-module/post-content/edit.js +1 -1
  141. package/build-module/post-content/edit.js.map +1 -1
  142. package/build-module/post-excerpt/edit.js +1 -1
  143. package/build-module/post-excerpt/edit.js.map +1 -1
  144. package/build-module/post-terms/edit.js +26 -4
  145. package/build-module/post-terms/edit.js.map +1 -1
  146. package/build-module/post-terms/index.js +8 -0
  147. package/build-module/post-terms/index.js.map +1 -1
  148. package/build-module/query-no-results/edit.js +1 -1
  149. package/build-module/query-no-results/edit.js.map +1 -1
  150. package/build-module/quote/index.js +1 -0
  151. package/build-module/quote/index.js.map +1 -1
  152. package/build-module/separator/index.js +3 -0
  153. package/build-module/separator/index.js.map +1 -1
  154. package/build-module/video/edit.js +3 -7
  155. package/build-module/video/edit.js.map +1 -1
  156. package/build-style/comment-content/style-rtl.css +81 -0
  157. package/build-style/comment-content/style.css +81 -0
  158. package/build-style/{comments-query-loop → comments}/editor-rtl.css +0 -0
  159. package/build-style/{comments-query-loop → comments}/editor.css +0 -0
  160. package/build-style/cover/style-rtl.css +1 -5
  161. package/build-style/cover/style.css +1 -5
  162. package/build-style/editor-rtl.css +12 -4
  163. package/build-style/editor.css +12 -4
  164. package/build-style/latest-posts/style-rtl.css +2 -0
  165. package/build-style/latest-posts/style.css +4 -0
  166. package/build-style/navigation/style-rtl.css +3 -0
  167. package/build-style/navigation/style.css +3 -0
  168. package/build-style/post-comments/editor-rtl.css +79 -0
  169. package/build-style/post-comments/editor.css +79 -0
  170. package/build-style/post-comments/style-rtl.css +6 -4
  171. package/build-style/post-comments/style.css +6 -4
  172. package/build-style/post-comments-form/editor-rtl.css +79 -0
  173. package/build-style/post-comments-form/editor.css +79 -0
  174. package/build-style/style-rtl.css +12 -9
  175. package/build-style/style.css +14 -9
  176. package/package.json +28 -28
  177. package/src/audio/edit.js +2 -7
  178. package/src/button/edit.native.js +6 -3
  179. package/src/comment-author-name/index.php +7 -5
  180. package/src/comment-content/index.php +25 -3
  181. package/src/comment-content/style.scss +5 -0
  182. package/src/comment-edit-link/index.php +1 -4
  183. package/src/comment-reply-link/index.php +1 -4
  184. package/src/comment-template/edit.js +1 -5
  185. package/src/comment-template/index.php +4 -0
  186. package/src/{comments-query-loop → comments}/block.json +1 -1
  187. package/src/{comments-query-loop → comments}/edit/comments-inspector-controls.js +0 -0
  188. package/src/{comments-query-loop → comments}/edit.js +2 -1
  189. package/src/{comments-query-loop → comments}/editor.scss +0 -0
  190. package/src/{comments-query-loop → comments}/index.js +0 -0
  191. package/src/{comments-query-loop → comments}/save.js +1 -3
  192. package/src/comments-pagination/index.php +4 -0
  193. package/src/comments-title/edit.js +20 -4
  194. package/src/comments-title/index.php +18 -7
  195. package/src/cover/edit.js +2 -67
  196. package/src/cover/edit.native.js +40 -13
  197. package/src/cover/index.php +1 -1
  198. package/src/cover/style.native.scss +4 -0
  199. package/src/cover/style.scss +1 -5
  200. package/src/cover/test/__snapshots__/edit.native.js.snap +6 -6
  201. package/src/cover/test/transforms.js +301 -0
  202. package/src/cover/transforms.js +112 -7
  203. package/src/cover/use-cover-is-dark.js +71 -0
  204. package/src/cover/use-cover-is-dark.native.js +51 -0
  205. package/src/editor.scss +3 -1
  206. package/src/group/block.json +1 -0
  207. package/src/heading/transforms.js +4 -3
  208. package/src/index.js +3 -6
  209. package/src/latest-posts/edit.native.js +56 -1
  210. package/src/latest-posts/style.scss +4 -0
  211. package/src/navigation/block.json +0 -1
  212. package/src/navigation/edit/index.js +6 -36
  213. package/src/navigation/edit/inner-blocks.js +5 -7
  214. package/src/navigation/style.scss +3 -0
  215. package/src/navigation/view-modal.js +32 -0
  216. package/src/navigation-link/edit.js +40 -43
  217. package/src/navigation-submenu/edit.js +13 -17
  218. package/src/paragraph/edit.js +6 -0
  219. package/src/paragraph/use-enter.js +103 -0
  220. package/src/post-author/index.php +1 -1
  221. package/src/post-comment/block.json +1 -1
  222. package/src/post-comments/block.json +3 -2
  223. package/src/post-comments/edit.js +174 -44
  224. package/src/post-comments/editor.scss +3 -0
  225. package/src/post-comments/index.php +2 -0
  226. package/src/post-comments/style.scss +6 -7
  227. package/src/post-comments-form/block.json +1 -0
  228. package/src/post-comments-form/edit.js +52 -23
  229. package/src/post-comments-form/editor.scss +3 -0
  230. package/src/post-comments-form/form.js +43 -0
  231. package/src/post-comments-form/index.php +9 -2
  232. package/src/post-content/edit.js +15 -1
  233. package/src/post-excerpt/edit.js +14 -1
  234. package/src/post-terms/block.json +8 -0
  235. package/src/post-terms/edit.js +28 -1
  236. package/src/post-terms/index.php +12 -2
  237. package/src/query-no-results/edit.js +1 -1
  238. package/src/quote/block.json +1 -0
  239. package/src/separator/block.json +3 -0
  240. package/src/video/edit.js +3 -4
  241. package/build/comments-query-loop/edit/comments-inspector-controls.js.map +0 -1
  242. package/build/comments-query-loop/edit.js.map +0 -1
  243. package/build/comments-query-loop/index.js.map +0 -1
  244. package/build/comments-query-loop/save.js.map +0 -1
  245. package/build/navigation-area/edit.js +0 -110
  246. package/build/navigation-area/edit.js.map +0 -1
  247. package/build/navigation-area/index.js +0 -62
  248. package/build/navigation-area/index.js.map +0 -1
  249. package/build/navigation-area/inner-blocks.js +0 -34
  250. package/build/navigation-area/inner-blocks.js.map +0 -1
  251. package/build/navigation-area/save.js +0 -18
  252. package/build/navigation-area/save.js.map +0 -1
  253. package/build-module/comments-query-loop/edit.js.map +0 -1
  254. package/build-module/comments-query-loop/index.js.map +0 -1
  255. package/build-module/comments-query-loop/save.js.map +0 -1
  256. package/build-module/navigation-area/edit.js +0 -94
  257. package/build-module/navigation-area/edit.js.map +0 -1
  258. package/build-module/navigation-area/index.js +0 -48
  259. package/build-module/navigation-area/index.js.map +0 -1
  260. package/build-module/navigation-area/inner-blocks.js +0 -26
  261. package/build-module/navigation-area/inner-blocks.js.map +0 -1
  262. package/build-module/navigation-area/save.js +0 -10
  263. package/build-module/navigation-area/save.js.map +0 -1
  264. package/src/navigation-area/block.json +0 -23
  265. package/src/navigation-area/edit.js +0 -111
  266. package/src/navigation-area/index.js +0 -26
  267. package/src/navigation-area/index.php +0 -22
  268. package/src/navigation-area/inner-blocks.js +0 -24
  269. package/src/navigation-area/save.js +0 -8
@@ -0,0 +1,301 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import {
5
+ createBlock,
6
+ getBlockTypes,
7
+ registerBlockType,
8
+ switchToBlockType,
9
+ unregisterBlockType,
10
+ } from '@wordpress/blocks';
11
+
12
+ /**
13
+ * Internal dependencies
14
+ */
15
+ import { metadata as coverMetadata, settings as coverSettings } from '../index';
16
+ import {
17
+ metadata as groupMetadata,
18
+ settings as groupSettings,
19
+ } from '../../group';
20
+
21
+ describe( 'transforms', () => {
22
+ beforeAll( () => {
23
+ registerBlockType( coverMetadata, coverSettings );
24
+ registerBlockType( groupMetadata, groupSettings );
25
+ } );
26
+
27
+ afterAll( () => {
28
+ getBlockTypes().forEach( ( block ) => {
29
+ unregisterBlockType( block.name );
30
+ } );
31
+ } );
32
+
33
+ describe( 'transform from Group to Cover', () => {
34
+ it( 'should return child Cover block when Group block contains only a single Cover block', () => {
35
+ const block = createBlock(
36
+ 'core/group',
37
+ { gradient: 'my-gradient' },
38
+ [ createBlock( 'core/cover', { dimRatio: 10 } ) ]
39
+ );
40
+
41
+ const transformedBlocks = switchToBlockType( block, 'core/cover' );
42
+
43
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
44
+ attributes: { dimRatio: 10 },
45
+ innerBlocks: [],
46
+ name: 'core/cover',
47
+ } );
48
+ } );
49
+
50
+ it( 'should wrap Group in a Cover block and move named gradient up to the parent Cover block', () => {
51
+ const block = createBlock( 'core/group', {
52
+ gradient: 'my-gradient',
53
+ } );
54
+
55
+ const transformedBlocks = switchToBlockType( block, 'core/cover' );
56
+ const innerGroupBlock = transformedBlocks[ 0 ].innerBlocks[ 0 ];
57
+
58
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
59
+ attributes: { gradient: 'my-gradient' },
60
+ name: 'core/cover',
61
+ } );
62
+
63
+ expect( innerGroupBlock.name ).toBe( 'core/group' );
64
+ expect( innerGroupBlock.attributes ).not.toHaveProperty(
65
+ 'gradient'
66
+ );
67
+ } );
68
+
69
+ it( 'should wrap Group in a Cover block and move custom gradient up to the parent Cover block', () => {
70
+ const gradient =
71
+ 'linear-gradient(90deg,rgb(188,138,51) 0%,rgb(65,88,208) 100%)';
72
+ const block = createBlock( 'core/group', {
73
+ style: {
74
+ color: {
75
+ gradient,
76
+ },
77
+ },
78
+ } );
79
+
80
+ const transformedBlocks = switchToBlockType( block, 'core/cover' );
81
+ const innerGroupBlock = transformedBlocks[ 0 ].innerBlocks[ 0 ];
82
+
83
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
84
+ attributes: { customGradient: gradient },
85
+ name: 'core/cover',
86
+ } );
87
+
88
+ expect( innerGroupBlock.name ).toBe( 'core/group' );
89
+ expect( innerGroupBlock.attributes ).not.toHaveProperty( 'style' );
90
+ } );
91
+
92
+ it( 'should wrap Group in a Cover block and move named background color up to the parent Cover block', () => {
93
+ const block = createBlock( 'core/group', {
94
+ backgroundColor: 'my-background-color',
95
+ } );
96
+
97
+ const transformedBlocks = switchToBlockType( block, 'core/cover' );
98
+ const innerGroupBlock = transformedBlocks[ 0 ].innerBlocks[ 0 ];
99
+
100
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
101
+ attributes: { overlayColor: 'my-background-color' },
102
+ name: 'core/cover',
103
+ } );
104
+
105
+ expect( innerGroupBlock.name ).toBe( 'core/group' );
106
+ expect( innerGroupBlock.attributes ).not.toHaveProperty(
107
+ 'backgroundColor'
108
+ );
109
+ } );
110
+
111
+ it( 'should wrap Group in a Cover block and move custom background color up to the parent Cover block', () => {
112
+ const background = '#ff0000';
113
+ const block = createBlock( 'core/group', {
114
+ style: {
115
+ color: {
116
+ background,
117
+ },
118
+ },
119
+ } );
120
+
121
+ const transformedBlocks = switchToBlockType( block, 'core/cover' );
122
+ const innerGroupBlock = transformedBlocks[ 0 ].innerBlocks[ 0 ];
123
+
124
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
125
+ attributes: { customOverlayColor: background },
126
+ name: 'core/cover',
127
+ } );
128
+
129
+ expect( innerGroupBlock.name ).toBe( 'core/group' );
130
+ expect( innerGroupBlock.attributes ).not.toHaveProperty( 'style' );
131
+ } );
132
+ } );
133
+
134
+ describe( 'transform from Cover to Group', () => {
135
+ it( 'should transfer named gradient color to Group block', () => {
136
+ const block = createBlock( 'core/cover', {
137
+ gradient: 'my-gradient',
138
+ } );
139
+
140
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
141
+
142
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
143
+ attributes: { gradient: 'my-gradient' },
144
+ name: 'core/group',
145
+ } );
146
+ } );
147
+
148
+ it( 'should transfer custom gradient color to style object in Group block', () => {
149
+ const gradient =
150
+ 'linear-gradient(90deg,rgb(188,138,51) 0%,rgb(65,88,208) 100%)';
151
+ const block = createBlock( 'core/cover', {
152
+ customGradient: gradient,
153
+ } );
154
+
155
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
156
+
157
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
158
+ attributes: { style: { color: { gradient } } },
159
+ name: 'core/group',
160
+ } );
161
+ } );
162
+
163
+ it( 'should transfer named background color to backgroundColor attribute in Group block', () => {
164
+ const block = createBlock( 'core/cover', {
165
+ overlayColor: 'my-background-color',
166
+ } );
167
+
168
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
169
+
170
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
171
+ attributes: { backgroundColor: 'my-background-color' },
172
+ name: 'core/group',
173
+ } );
174
+ } );
175
+
176
+ it( 'should transfer custom background color to style object in Group block', () => {
177
+ const block = createBlock( 'core/cover', {
178
+ customOverlayColor: '#ff0000',
179
+ } );
180
+
181
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
182
+
183
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
184
+ attributes: { style: { color: { background: '#ff0000' } } },
185
+ name: 'core/group',
186
+ } );
187
+ } );
188
+
189
+ it( 'should merge Cover block named gradient color into child Group block', () => {
190
+ const block = createBlock(
191
+ 'core/cover',
192
+ {
193
+ gradient: 'my-gradient',
194
+ },
195
+ [ createBlock( 'core/group', { fontSize: 'medium' } ) ]
196
+ );
197
+
198
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
199
+
200
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
201
+ attributes: { fontSize: 'medium', gradient: 'my-gradient' },
202
+ innerBlocks: [],
203
+ name: 'core/group',
204
+ } );
205
+ } );
206
+
207
+ it( 'should merge Cover block custom gradient color to style object in child Group block', () => {
208
+ const gradient =
209
+ 'linear-gradient(90deg,rgb(188,138,51) 0%,rgb(65,88,208) 100%)';
210
+ const block = createBlock(
211
+ 'core/cover',
212
+ {
213
+ customGradient: gradient,
214
+ },
215
+ [ createBlock( 'core/group', { fontSize: 'medium' } ) ]
216
+ );
217
+
218
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
219
+
220
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
221
+ attributes: {
222
+ fontSize: 'medium',
223
+ style: { color: { gradient } },
224
+ },
225
+ innerBlocks: [],
226
+ name: 'core/group',
227
+ } );
228
+ } );
229
+
230
+ it( 'should merge Cover block named background color to backgroundColor attribute in child Group block', () => {
231
+ const block = createBlock(
232
+ 'core/cover',
233
+ {
234
+ overlayColor: 'my-background-color',
235
+ },
236
+ [ createBlock( 'core/group', { fontSize: 'medium' } ) ]
237
+ );
238
+
239
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
240
+
241
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
242
+ attributes: {
243
+ backgroundColor: 'my-background-color',
244
+ fontSize: 'medium',
245
+ },
246
+ innerBlocks: [],
247
+ name: 'core/group',
248
+ } );
249
+ } );
250
+
251
+ it( 'should merge Cover block custom background color into child Group block', () => {
252
+ const block = createBlock(
253
+ 'core/cover',
254
+ {
255
+ customOverlayColor: '#ff0000',
256
+ },
257
+ [ createBlock( 'core/group', { fontSize: 'medium' } ) ]
258
+ );
259
+
260
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
261
+
262
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
263
+ attributes: {
264
+ fontSize: 'medium',
265
+ style: { color: { background: '#ff0000' } },
266
+ },
267
+ innerBlocks: [],
268
+ name: 'core/group',
269
+ } );
270
+ } );
271
+
272
+ it( 'should skip merging Cover block gradient into child Group block if Group block has background color', () => {
273
+ const block = createBlock(
274
+ 'core/cover',
275
+ {
276
+ gradient: 'my-gradient',
277
+ },
278
+ [
279
+ createBlock( 'core/group', {
280
+ fontSize: 'medium',
281
+ style: { color: { background: '#ff0000' } },
282
+ } ),
283
+ ]
284
+ );
285
+
286
+ const transformedBlocks = switchToBlockType( block, 'core/group' );
287
+
288
+ expect( transformedBlocks[ 0 ] ).toMatchObject( {
289
+ attributes: {
290
+ fontSize: 'medium',
291
+ style: { color: { background: '#ff0000' } },
292
+ },
293
+ innerBlocks: [],
294
+ name: 'core/group',
295
+ } );
296
+ expect( transformedBlocks[ 0 ].attributes ).not.toHaveProperty(
297
+ 'gradient'
298
+ );
299
+ } );
300
+ } );
301
+ } );
@@ -7,6 +7,7 @@ import { createBlock } from '@wordpress/blocks';
7
7
  * Internal dependencies
8
8
  */
9
9
  import { IMAGE_BACKGROUND_TYPE, VIDEO_BACKGROUND_TYPE } from './shared';
10
+ import cleanEmptyObject from '../utils/clean-empty-object';
10
11
 
11
12
  const transforms = {
12
13
  from: [
@@ -73,6 +74,19 @@ const transforms = {
73
74
  style,
74
75
  } = attributes;
75
76
 
77
+ // If the Group block being transformed has a Cover block as its
78
+ // only child return that Cover block.
79
+ if (
80
+ innerBlocks?.length === 1 &&
81
+ innerBlocks[ 0 ]?.name === 'core/cover'
82
+ ) {
83
+ return createBlock(
84
+ 'core/cover',
85
+ innerBlocks[ 0 ].attributes,
86
+ innerBlocks[ 0 ].innerBlocks
87
+ );
88
+ }
89
+
76
90
  // If no background or gradient color is provided, default to 50% opacity.
77
91
  // This matches the styling of a Cover block with a background image,
78
92
  // in the state where a background image has been removed.
@@ -99,14 +113,16 @@ const transforms = {
99
113
  ...attributes,
100
114
  backgroundColor: undefined,
101
115
  gradient: undefined,
102
- style: {
116
+ style: cleanEmptyObject( {
103
117
  ...attributes?.style,
104
- color: {
105
- ...attributes?.style?.color,
106
- background: undefined,
107
- gradient: undefined,
108
- },
109
- },
118
+ color: style?.color
119
+ ? {
120
+ ...style?.color,
121
+ background: undefined,
122
+ gradient: undefined,
123
+ }
124
+ : undefined,
125
+ } ),
110
126
  };
111
127
 
112
128
  // Preserve the block by nesting it within the Cover block,
@@ -192,6 +208,95 @@ const transforms = {
192
208
  anchor,
193
209
  } ),
194
210
  },
211
+ {
212
+ type: 'block',
213
+ blocks: [ 'core/group' ],
214
+ isMatch: ( { url } ) => {
215
+ // If the Cover block uses background media, skip this transform,
216
+ // and instead use the Group block's default transform.
217
+ if ( url ) {
218
+ return false;
219
+ }
220
+ return true;
221
+ },
222
+ transform: ( attributes, innerBlocks ) => {
223
+ // Convert Cover overlay colors to comparable Group background colors.
224
+ const transformedColorAttributes = {
225
+ backgroundColor: attributes?.overlayColor,
226
+ gradient: attributes?.gradient,
227
+ style: cleanEmptyObject( {
228
+ ...attributes?.style,
229
+ color:
230
+ attributes?.customOverlayColor ||
231
+ attributes?.customGradient ||
232
+ attributes?.style?.color
233
+ ? {
234
+ background:
235
+ attributes?.customOverlayColor,
236
+ gradient: attributes?.customGradient,
237
+ ...attributes?.style?.color,
238
+ }
239
+ : undefined,
240
+ } ),
241
+ };
242
+
243
+ // If the Cover block contains only a single Group block as a direct child,
244
+ // then attempt to merge the Cover's background colors with the child Group block,
245
+ // and remove the Cover block as the wrapper.
246
+ if (
247
+ innerBlocks?.length === 1 &&
248
+ innerBlocks[ 0 ]?.name === 'core/group'
249
+ ) {
250
+ const groupAttributes = cleanEmptyObject(
251
+ innerBlocks[ 0 ].attributes || {}
252
+ );
253
+
254
+ // If the Group block contains any kind of background color or gradient,
255
+ // skip merging Cover background colors, and preserve the Group block's colors.
256
+ if (
257
+ groupAttributes?.backgroundColor ||
258
+ groupAttributes?.gradient ||
259
+ groupAttributes?.style?.color?.background ||
260
+ groupAttributes?.style?.color?.gradient
261
+ ) {
262
+ return createBlock(
263
+ 'core/group',
264
+ groupAttributes,
265
+ innerBlocks[ 0 ]?.innerBlocks
266
+ );
267
+ }
268
+
269
+ return createBlock(
270
+ 'core/group',
271
+ {
272
+ ...transformedColorAttributes,
273
+ ...groupAttributes,
274
+ style: cleanEmptyObject( {
275
+ ...groupAttributes?.style,
276
+ color:
277
+ transformedColorAttributes?.style?.color ||
278
+ groupAttributes?.style?.color
279
+ ? {
280
+ ...transformedColorAttributes
281
+ ?.style?.color,
282
+ ...groupAttributes?.style
283
+ ?.color,
284
+ }
285
+ : undefined,
286
+ } ),
287
+ },
288
+ innerBlocks[ 0 ]?.innerBlocks
289
+ );
290
+ }
291
+
292
+ // In all other cases, transform the Cover block directly to a Group block.
293
+ return createBlock(
294
+ 'core/group',
295
+ { ...attributes, ...transformedColorAttributes },
296
+ innerBlocks
297
+ );
298
+ },
299
+ },
195
300
  ],
196
301
  };
197
302
 
@@ -0,0 +1,71 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import FastAverageColor from 'fast-average-color';
5
+ import { colord } from 'colord';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { useEffect, useState } from '@wordpress/element';
11
+
12
+ function retrieveFastAverageColor() {
13
+ if ( ! retrieveFastAverageColor.fastAverageColor ) {
14
+ retrieveFastAverageColor.fastAverageColor = new FastAverageColor();
15
+ }
16
+ return retrieveFastAverageColor.fastAverageColor;
17
+ }
18
+
19
+ /**
20
+ * useCoverIsDark is a hook that returns a boolean variable specifying if the cover
21
+ * background is dark or not.
22
+ *
23
+ * @param {?string} url Url of the media background.
24
+ * @param {?number} dimRatio Transparency of the overlay color. If an image and
25
+ * color are set, dimRatio is used to decide what is used
26
+ * for background darkness checking purposes.
27
+ * @param {?string} overlayColor String containing the overlay color value if one exists.
28
+ * @param {?Object} elementRef If a media background is set, elementRef should contain a reference to a
29
+ * dom element that renders that media.
30
+ *
31
+ * @return {boolean} True if the cover background is considered "dark" and false otherwise.
32
+ */
33
+ export default function useCoverIsDark(
34
+ url,
35
+ dimRatio = 50,
36
+ overlayColor,
37
+ elementRef
38
+ ) {
39
+ const [ isDark, setIsDark ] = useState( false );
40
+ useEffect( () => {
41
+ // If opacity is lower than 50 the dominant color is the image or video color,
42
+ // so use that color for the dark mode computation.
43
+ if ( url && dimRatio <= 50 && elementRef.current ) {
44
+ retrieveFastAverageColor().getColorAsync(
45
+ elementRef.current,
46
+ ( color ) => {
47
+ setIsDark( color.isDark );
48
+ }
49
+ );
50
+ }
51
+ }, [ url, url && dimRatio <= 50 && elementRef.current, setIsDark ] );
52
+ useEffect( () => {
53
+ // If opacity is greater than 50 the dominant color is the overlay color,
54
+ // so use that color for the dark mode computation.
55
+ if ( dimRatio > 50 || ! url ) {
56
+ if ( ! overlayColor ) {
57
+ // If no overlay color exists the overlay color is black (isDark )
58
+ setIsDark( true );
59
+ return;
60
+ }
61
+ setIsDark( colord( overlayColor ).isDark() );
62
+ }
63
+ }, [ overlayColor, dimRatio > 50 || ! url, setIsDark ] );
64
+ useEffect( () => {
65
+ if ( ! url && ! overlayColor ) {
66
+ // Reset isDark.
67
+ setIsDark( false );
68
+ }
69
+ }, [ ! url && ! overlayColor, setIsDark ] );
70
+ return isDark;
71
+ }
@@ -0,0 +1,51 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+
5
+ import { colord } from 'colord';
6
+
7
+ /**
8
+ * WordPress dependencies
9
+ */
10
+ import { useEffect, useState } from '@wordpress/element';
11
+
12
+ /**
13
+ * useCoverIsDark is a hook that returns a boolean variable specifying if the cover
14
+ * background is dark or not.
15
+ *
16
+ * @param {?boolean} initialValue Initial value.
17
+ * @param {?string} url Url of the media background.
18
+ * @param {?number} dimRatio Transparency of the overlay color. If an image and
19
+ * color are set, dimRatio is used to decide what is used
20
+ * for background darkness checking purposes.
21
+ * @param {?string} overlayColor String containing the overlay color value if one exists.
22
+ *
23
+ * @return {boolean} True if the cover background is considered "dark" and false otherwise.
24
+ */
25
+ export default function useCoverIsDark(
26
+ initialValue = false,
27
+ url,
28
+ dimRatio = 50,
29
+ overlayColor
30
+ ) {
31
+ const [ isDark, setIsDark ] = useState( initialValue );
32
+ useEffect( () => {
33
+ // If opacity is greater than 50 the dominant color is the overlay color,
34
+ // so use that color for the dark mode computation.
35
+ if ( dimRatio > 50 || ! url ) {
36
+ if ( ! overlayColor ) {
37
+ // If no overlay color exists the overlay color is black (isDark )
38
+ setIsDark( true );
39
+ return;
40
+ }
41
+ setIsDark( colord( overlayColor ).isDark() );
42
+ }
43
+ }, [ overlayColor, dimRatio > 50 || ! url, setIsDark ] );
44
+ useEffect( () => {
45
+ if ( ! url && ! overlayColor ) {
46
+ // Reset isDark.
47
+ setIsDark( false );
48
+ }
49
+ }, [ ! url && ! overlayColor, setIsDark ] );
50
+ return isDark;
51
+ }
package/src/editor.scss CHANGED
@@ -6,8 +6,8 @@
6
6
  @import "./buttons/editor.scss";
7
7
  @import "./categories/editor.scss";
8
8
  @import "./columns/editor.scss";
9
+ @import "./comments/editor.scss";
9
10
  @import "./comment-author-avatar/editor.scss";
10
- @import "./comments-query-loop/editor.scss";
11
11
  @import "./comments-pagination/editor.scss";
12
12
  @import "./comments-pagination-numbers/editor.scss";
13
13
  @import "./comments-title/editor.scss";
@@ -49,6 +49,8 @@
49
49
  @import "./query-pagination/editor.scss";
50
50
  @import "./query-pagination-numbers/editor.scss";
51
51
  @import "./post-featured-image/editor.scss";
52
+ @import "./post-comments/editor.scss";
53
+ @import "./post-comments-form/editor.scss";
52
54
 
53
55
  :root .editor-styles-wrapper {
54
56
  @include background-colors-deprecated();
@@ -18,6 +18,7 @@
18
18
  }
19
19
  },
20
20
  "supports": {
21
+ "__experimentalSettings": true,
21
22
  "align": [ "wide", "full" ],
22
23
  "anchor": true,
23
24
  "html": false,
@@ -16,10 +16,11 @@ const transforms = {
16
16
  isMultiBlock: true,
17
17
  blocks: [ 'core/paragraph' ],
18
18
  transform: ( attributes ) =>
19
- attributes.map( ( { content, anchor } ) =>
19
+ attributes.map( ( { content, anchor, align: textAlign } ) =>
20
20
  createBlock( name, {
21
21
  content,
22
22
  anchor,
23
+ textAlign,
23
24
  } )
24
25
  ),
25
26
  },
@@ -84,8 +85,8 @@ const transforms = {
84
85
  isMultiBlock: true,
85
86
  blocks: [ 'core/paragraph' ],
86
87
  transform: ( attributes ) =>
87
- attributes.map( ( { content } ) =>
88
- createBlock( 'core/paragraph', { content } )
88
+ attributes.map( ( { content, textAlign: align } ) =>
89
+ createBlock( 'core/paragraph', { content, align } )
89
90
  ),
90
91
  },
91
92
  ],
package/src/index.js CHANGED
@@ -23,6 +23,7 @@ import * as classic from './freeform';
23
23
  import * as code from './code';
24
24
  import * as column from './column';
25
25
  import * as columns from './columns';
26
+ import * as comments from './comments';
26
27
  import * as commentAuthorAvatar from './comment-author-avatar';
27
28
  import * as commentAuthorName from './comment-author-name';
28
29
  import * as commentContent from './comment-content';
@@ -31,7 +32,6 @@ import * as commentEditLink from './comment-edit-link';
31
32
  import * as commentReplyLink from './comment-reply-link';
32
33
  import * as commentTemplate from './comment-template';
33
34
  import * as commentsPaginationPrevious from './comments-pagination-previous';
34
- import * as commentsQueryLoop from './comments-query-loop';
35
35
  import * as commentsPagination from './comments-pagination';
36
36
  import * as commentsPaginationNext from './comments-pagination-next';
37
37
  import * as commentsPaginationNumbers from './comments-pagination-numbers';
@@ -54,7 +54,6 @@ import * as mediaText from './media-text';
54
54
  import * as missing from './missing';
55
55
  import * as more from './more';
56
56
  import * as navigation from './navigation';
57
- import * as navigationArea from './navigation-area';
58
57
  import * as navigationLink from './navigation-link';
59
58
  import * as navigationSubmenu from './navigation-submenu';
60
59
  import * as nextpage from './nextpage';
@@ -207,6 +206,7 @@ export const __experimentalGetCoreBlocks = () => [
207
206
  queryPaginationPrevious,
208
207
  queryNoResults,
209
208
  readMore,
209
+ comments,
210
210
  commentAuthorName,
211
211
  commentContent,
212
212
  commentDate,
@@ -214,13 +214,12 @@ export const __experimentalGetCoreBlocks = () => [
214
214
  commentReplyLink,
215
215
  commentTemplate,
216
216
  commentsTitle,
217
- commentsQueryLoop,
218
217
  commentsPagination,
219
218
  commentsPaginationNext,
220
219
  commentsPaginationNumbers,
221
220
  commentsPaginationPrevious,
222
-
223
221
  postComments,
222
+ postCommentsForm,
224
223
  homeLink,
225
224
  logInOut,
226
225
  termDescription,
@@ -278,10 +277,8 @@ export const __experimentalRegisterExperimentalCoreBlocks = process.env
278
277
  ...( enableFSEBlocks
279
278
  ? [
280
279
  commentAuthorAvatar,
281
- navigationArea,
282
280
  postComment,
283
281
  postCommentsCount,
284
- postCommentsForm,
285
282
  postCommentsLink,
286
283
  ]
287
284
  : [] ),