@wordpress/block-library 9.10.0 → 9.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 (307) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +10 -5
  3. package/build/archives/index.js +6 -0
  4. package/build/archives/index.js.map +1 -1
  5. package/build/avatar/hooks.js +2 -3
  6. package/build/avatar/hooks.js.map +1 -1
  7. package/build/button/get-updated-link-attributes.js +1 -1
  8. package/build/button/get-updated-link-attributes.js.map +1 -1
  9. package/build/button/index.js +1 -1
  10. package/build/button/index.js.map +1 -1
  11. package/build/comments/index.js +12 -0
  12. package/build/comments/index.js.map +1 -1
  13. package/build/cover/constants.js +8 -0
  14. package/build/cover/constants.js.map +1 -0
  15. package/build/cover/deprecated.js +140 -4
  16. package/build/cover/deprecated.js.map +1 -1
  17. package/build/cover/edit/block-controls.js +1 -1
  18. package/build/cover/edit/block-controls.js.map +1 -1
  19. package/build/cover/edit/cover-placeholder.js +1 -2
  20. package/build/cover/edit/cover-placeholder.js.map +1 -1
  21. package/build/cover/edit/index.js +42 -21
  22. package/build/cover/edit/index.js.map +1 -1
  23. package/build/cover/edit/inspector-controls.js +40 -2
  24. package/build/cover/edit/inspector-controls.js.map +1 -1
  25. package/build/cover/index.js +3 -0
  26. package/build/cover/index.js.map +1 -1
  27. package/build/cover/save.js +16 -14
  28. package/build/cover/save.js.map +1 -1
  29. package/build/details/index.js +1 -0
  30. package/build/details/index.js.map +1 -1
  31. package/build/file/edit.js +2 -3
  32. package/build/file/edit.js.map +1 -1
  33. package/build/gallery/constants.js +2 -1
  34. package/build/gallery/constants.js.map +1 -1
  35. package/build/gallery/edit.js +12 -3
  36. package/build/gallery/edit.js.map +1 -1
  37. package/build/gallery/utils.js +26 -5
  38. package/build/gallery/utils.js.map +1 -1
  39. package/build/html/edit.js +5 -1
  40. package/build/html/edit.js.map +1 -1
  41. package/build/html/preview.js +2 -2
  42. package/build/html/preview.js.map +1 -1
  43. package/build/image/edit.js +1 -1
  44. package/build/image/edit.js.map +1 -1
  45. package/build/image/image.js +144 -78
  46. package/build/image/image.js.map +1 -1
  47. package/build/image/index.js +1 -1
  48. package/build/latest-posts/edit.js +3 -9
  49. package/build/latest-posts/edit.js.map +1 -1
  50. package/build/lock-unlock.js.map +1 -1
  51. package/build/navigation/edit/menu-inspector-controls.js +1 -1
  52. package/build/navigation/edit/menu-inspector-controls.js.map +1 -1
  53. package/build/navigation/edit/navigation-menu-selector.js +2 -2
  54. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  55. package/build/paragraph/edit.js +2 -2
  56. package/build/paragraph/edit.js.map +1 -1
  57. package/build/post-content/index.js +13 -0
  58. package/build/post-content/index.js.map +1 -1
  59. package/build/post-featured-image/edit.js +1 -1
  60. package/build/post-featured-image/edit.js.map +1 -1
  61. package/build/post-template/edit.js +11 -0
  62. package/build/post-template/edit.js.map +1 -1
  63. package/build/post-template/index.js +1 -1
  64. package/build/post-time-to-read/edit.js +2 -2
  65. package/build/post-time-to-read/edit.js.map +1 -1
  66. package/build/query/edit/inspector-controls/index.js +2 -2
  67. package/build/query/edit/inspector-controls/index.js.map +1 -1
  68. package/build/query/edit/inspector-controls/order-control.js +2 -2
  69. package/build/query/edit/inspector-controls/order-control.js.map +1 -1
  70. package/build/query/edit/pattern-selection-modal.js +0 -3
  71. package/build/query/edit/pattern-selection-modal.js.map +1 -1
  72. package/build/query/edit/query-content.js +10 -12
  73. package/build/query/edit/query-content.js.map +1 -1
  74. package/build/query/index.js +1 -1
  75. package/build/query/utils.js +32 -1
  76. package/build/query/utils.js.map +1 -1
  77. package/build/query-title/edit.js +1 -1
  78. package/build/query-title/edit.js.map +1 -1
  79. package/build/search/edit.js +19 -14
  80. package/build/search/edit.js.map +1 -1
  81. package/build/separator/transforms.js +12 -0
  82. package/build/separator/transforms.js.map +1 -1
  83. package/build/social-links/edit.js +0 -1
  84. package/build/social-links/edit.js.map +1 -1
  85. package/build/spacer/index.js +2 -0
  86. package/build/spacer/index.js.map +1 -1
  87. package/build/spacer/transforms.js +27 -0
  88. package/build/spacer/transforms.js.map +1 -0
  89. package/build/table/edit.js +0 -1
  90. package/build/table/edit.js.map +1 -1
  91. package/build/table-of-contents/edit.js +2 -7
  92. package/build/table-of-contents/edit.js.map +1 -1
  93. package/build/template-part/edit/index.js +2 -5
  94. package/build/template-part/edit/index.js.map +1 -1
  95. package/build/template-part/edit/selection-modal.js +0 -3
  96. package/build/template-part/edit/selection-modal.js.map +1 -1
  97. package/build/video/edit.js +1 -1
  98. package/build/video/edit.js.map +1 -1
  99. package/build/video/tracks-editor.js +1 -3
  100. package/build/video/tracks-editor.js.map +1 -1
  101. package/build-module/archives/index.js +6 -0
  102. package/build-module/archives/index.js.map +1 -1
  103. package/build-module/avatar/hooks.js +2 -3
  104. package/build-module/avatar/hooks.js.map +1 -1
  105. package/build-module/button/get-updated-link-attributes.js +1 -1
  106. package/build-module/button/get-updated-link-attributes.js.map +1 -1
  107. package/build-module/button/index.js +1 -1
  108. package/build-module/button/index.js.map +1 -1
  109. package/build-module/comments/index.js +12 -0
  110. package/build-module/comments/index.js.map +1 -1
  111. package/build-module/cover/constants.js +2 -0
  112. package/build-module/cover/constants.js.map +1 -0
  113. package/build-module/cover/deprecated.js +140 -4
  114. package/build-module/cover/deprecated.js.map +1 -1
  115. package/build-module/cover/edit/block-controls.js +1 -1
  116. package/build-module/cover/edit/block-controls.js.map +1 -1
  117. package/build-module/cover/edit/cover-placeholder.js +1 -2
  118. package/build-module/cover/edit/cover-placeholder.js.map +1 -1
  119. package/build-module/cover/edit/index.js +42 -21
  120. package/build-module/cover/edit/index.js.map +1 -1
  121. package/build-module/cover/edit/inspector-controls.js +41 -3
  122. package/build-module/cover/edit/inspector-controls.js.map +1 -1
  123. package/build-module/cover/index.js +3 -0
  124. package/build-module/cover/index.js.map +1 -1
  125. package/build-module/cover/save.js +16 -14
  126. package/build-module/cover/save.js.map +1 -1
  127. package/build-module/details/index.js +1 -0
  128. package/build-module/details/index.js.map +1 -1
  129. package/build-module/file/edit.js +2 -3
  130. package/build-module/file/edit.js.map +1 -1
  131. package/build-module/gallery/constants.js +1 -0
  132. package/build-module/gallery/constants.js.map +1 -1
  133. package/build-module/gallery/edit.js +15 -6
  134. package/build-module/gallery/edit.js.map +1 -1
  135. package/build-module/gallery/utils.js +27 -6
  136. package/build-module/gallery/utils.js.map +1 -1
  137. package/build-module/html/edit.js +6 -2
  138. package/build-module/html/edit.js.map +1 -1
  139. package/build-module/html/preview.js +2 -2
  140. package/build-module/html/preview.js.map +1 -1
  141. package/build-module/image/edit.js +1 -1
  142. package/build-module/image/edit.js.map +1 -1
  143. package/build-module/image/image.js +149 -83
  144. package/build-module/image/image.js.map +1 -1
  145. package/build-module/image/index.js +1 -1
  146. package/build-module/latest-posts/edit.js +3 -9
  147. package/build-module/latest-posts/edit.js.map +1 -1
  148. package/build-module/lock-unlock.js.map +1 -1
  149. package/build-module/navigation/edit/menu-inspector-controls.js +1 -3
  150. package/build-module/navigation/edit/menu-inspector-controls.js.map +1 -1
  151. package/build-module/navigation/edit/navigation-menu-selector.js +2 -2
  152. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  153. package/build-module/paragraph/edit.js +2 -2
  154. package/build-module/paragraph/edit.js.map +1 -1
  155. package/build-module/post-content/index.js +13 -0
  156. package/build-module/post-content/index.js.map +1 -1
  157. package/build-module/post-featured-image/edit.js +1 -1
  158. package/build-module/post-featured-image/edit.js.map +1 -1
  159. package/build-module/post-template/edit.js +11 -0
  160. package/build-module/post-template/edit.js.map +1 -1
  161. package/build-module/post-template/index.js +1 -1
  162. package/build-module/post-time-to-read/edit.js +2 -2
  163. package/build-module/post-time-to-read/edit.js.map +1 -1
  164. package/build-module/query/edit/inspector-controls/index.js +2 -2
  165. package/build-module/query/edit/inspector-controls/index.js.map +1 -1
  166. package/build-module/query/edit/inspector-controls/order-control.js +2 -2
  167. package/build-module/query/edit/inspector-controls/order-control.js.map +1 -1
  168. package/build-module/query/edit/pattern-selection-modal.js +0 -3
  169. package/build-module/query/edit/pattern-selection-modal.js.map +1 -1
  170. package/build-module/query/edit/query-content.js +10 -12
  171. package/build-module/query/edit/query-content.js.map +1 -1
  172. package/build-module/query/index.js +1 -1
  173. package/build-module/query/utils.js +29 -0
  174. package/build-module/query/utils.js.map +1 -1
  175. package/build-module/query-title/edit.js +2 -2
  176. package/build-module/query-title/edit.js.map +1 -1
  177. package/build-module/search/edit.js +20 -15
  178. package/build-module/search/edit.js.map +1 -1
  179. package/build-module/separator/transforms.js +12 -0
  180. package/build-module/separator/transforms.js.map +1 -1
  181. package/build-module/social-links/edit.js +0 -1
  182. package/build-module/social-links/edit.js.map +1 -1
  183. package/build-module/spacer/index.js +2 -0
  184. package/build-module/spacer/index.js.map +1 -1
  185. package/build-module/spacer/transforms.js +20 -0
  186. package/build-module/spacer/transforms.js.map +1 -0
  187. package/build-module/table/edit.js +0 -1
  188. package/build-module/table/edit.js.map +1 -1
  189. package/build-module/table-of-contents/edit.js +2 -7
  190. package/build-module/table-of-contents/edit.js.map +1 -1
  191. package/build-module/template-part/edit/index.js +2 -5
  192. package/build-module/template-part/edit/index.js.map +1 -1
  193. package/build-module/template-part/edit/selection-modal.js +0 -3
  194. package/build-module/template-part/edit/selection-modal.js.map +1 -1
  195. package/build-module/video/edit.js +1 -1
  196. package/build-module/video/edit.js.map +1 -1
  197. package/build-module/video/tracks-editor.js +2 -4
  198. package/build-module/video/tracks-editor.js.map +1 -1
  199. package/build-style/archives/editor-rtl.css +5 -0
  200. package/build-style/archives/editor.css +5 -0
  201. package/build-style/button/style-rtl.css +3 -0
  202. package/build-style/button/style.css +3 -0
  203. package/build-style/comments/editor-rtl.css +4 -0
  204. package/build-style/comments/editor.css +4 -0
  205. package/build-style/comments/style-rtl.css +4 -0
  206. package/build-style/comments/style.css +4 -0
  207. package/build-style/cover/editor-rtl.css +3 -5
  208. package/build-style/cover/editor.css +3 -5
  209. package/build-style/cover/style-rtl.css +19 -10
  210. package/build-style/cover/style.css +19 -10
  211. package/build-style/editor-rtl.css +17 -12
  212. package/build-style/editor.css +17 -12
  213. package/build-style/image/editor-rtl.css +4 -0
  214. package/build-style/image/editor.css +4 -0
  215. package/build-style/latest-posts/editor-rtl.css +0 -7
  216. package/build-style/latest-posts/editor.css +0 -7
  217. package/build-style/media-text/style-rtl.css +1 -1
  218. package/build-style/media-text/style.css +1 -1
  219. package/build-style/navigation/editor-rtl.css +1 -0
  220. package/build-style/navigation/editor.css +1 -0
  221. package/build-style/style-rtl.css +27 -11
  222. package/build-style/style.css +27 -11
  223. package/build-types/lock-unlock.d.ts +2 -0
  224. package/build-types/lock-unlock.d.ts.map +1 -0
  225. package/package.json +41 -40
  226. package/src/archives/block.json +6 -0
  227. package/src/archives/editor.scss +8 -0
  228. package/src/avatar/hooks.js +2 -3
  229. package/src/avatar/index.php +4 -5
  230. package/src/button/get-updated-link-attributes.js +1 -1
  231. package/src/button/index.js +1 -1
  232. package/src/button/style.scss +3 -0
  233. package/src/button/test/get-updated-link-attributes.js +15 -0
  234. package/src/comment-author-avatar/index.php +1 -1
  235. package/src/comments/block.json +12 -0
  236. package/src/comments/style.scss +4 -1
  237. package/src/cover/block.json +3 -0
  238. package/src/cover/constants.js +1 -0
  239. package/src/cover/deprecated.js +182 -4
  240. package/src/cover/edit/block-controls.js +1 -1
  241. package/src/cover/edit/cover-placeholder.js +0 -3
  242. package/src/cover/edit/index.js +57 -24
  243. package/src/cover/edit/inspector-controls.js +46 -1
  244. package/src/cover/editor.scss +4 -5
  245. package/src/cover/save.js +29 -20
  246. package/src/cover/style.scss +40 -10
  247. package/src/cover/test/__snapshots__/edit.native.js.snap +9 -9
  248. package/src/cover/test/__snapshots__/transforms.native.js.snap +4 -4
  249. package/src/cover/test/edit.js +1 -3
  250. package/src/cover/test/edit.native.js +4 -4
  251. package/src/cover/test/transforms.native.js +4 -4
  252. package/src/details/block.json +1 -0
  253. package/src/file/edit.js +2 -3
  254. package/src/gallery/constants.js +1 -0
  255. package/src/gallery/edit.js +26 -3
  256. package/src/gallery/utils.js +23 -2
  257. package/src/html/edit.js +7 -1
  258. package/src/html/preview.js +3 -2
  259. package/src/image/block.json +1 -1
  260. package/src/image/edit.js +1 -1
  261. package/src/image/editor.scss +4 -0
  262. package/src/image/image.js +200 -109
  263. package/src/image/test/__snapshots__/transforms.native.js.snap +1 -1
  264. package/src/latest-posts/edit.js +3 -8
  265. package/src/latest-posts/editor.scss +0 -11
  266. package/src/latest-posts/index.php +1 -1
  267. package/src/media-text/style.scss +1 -1
  268. package/src/media-text/test/__snapshots__/transforms.native.js.snap +2 -2
  269. package/src/navigation/edit/menu-inspector-controls.js +2 -2
  270. package/src/navigation/edit/navigation-menu-selector.js +2 -2
  271. package/src/navigation/editor.scss +1 -0
  272. package/src/navigation/index.php +1 -1
  273. package/src/paragraph/edit.js +2 -2
  274. package/src/post-content/block.json +14 -1
  275. package/src/post-featured-image/edit.js +1 -1
  276. package/src/post-template/block.json +2 -1
  277. package/src/post-template/edit.js +19 -0
  278. package/src/post-time-to-read/edit.js +2 -2
  279. package/src/post-time-to-read/index.php +1 -1
  280. package/src/query/block.json +1 -1
  281. package/src/query/edit/inspector-controls/index.js +2 -2
  282. package/src/query/edit/inspector-controls/order-control.js +2 -2
  283. package/src/query/edit/pattern-selection-modal.js +0 -3
  284. package/src/query/edit/query-content.js +9 -17
  285. package/src/query/test/utils.js +59 -1
  286. package/src/query/utils.js +29 -0
  287. package/src/query-title/edit.js +2 -2
  288. package/src/rss/index.php +1 -1
  289. package/src/search/edit.js +28 -25
  290. package/src/search/index.php +2 -2
  291. package/src/separator/test/__snapshots__/transforms.native.js.snap +6 -0
  292. package/src/separator/test/transforms.native.js +1 -1
  293. package/src/separator/transforms.js +11 -0
  294. package/src/social-links/edit.js +0 -1
  295. package/src/spacer/index.js +2 -0
  296. package/src/spacer/test/__snapshots__/transforms.native.js.snap +6 -0
  297. package/src/spacer/test/transforms.native.js +1 -1
  298. package/src/spacer/transforms.js +20 -0
  299. package/src/table/edit.js +0 -1
  300. package/src/table-of-contents/edit.js +2 -6
  301. package/src/template-part/edit/index.js +2 -5
  302. package/src/template-part/edit/selection-modal.js +0 -3
  303. package/src/video/edit.js +1 -1
  304. package/src/video/test/__snapshots__/transforms.native.js.snap +1 -1
  305. package/src/video/tracks-editor.js +2 -4
  306. package/tsconfig.tsbuildinfo +1 -1
  307. /package/src/{lock-unlock.js → lock-unlock.ts} +0 -0
@@ -164,7 +164,7 @@ const v8ToV11BlockAttributes = {
164
164
  },
165
165
  };
166
166
 
167
- const v12BlockAttributes = {
167
+ const v12toV13BlockAttributes = {
168
168
  ...v8ToV11BlockAttributes,
169
169
  useFeaturedImage: {
170
170
  type: 'boolean',
@@ -176,6 +176,20 @@ const v12BlockAttributes = {
176
176
  },
177
177
  };
178
178
 
179
+ const v14BlockAttributes = {
180
+ ...v12toV13BlockAttributes,
181
+ isUserOverlayColor: {
182
+ type: 'boolean',
183
+ },
184
+ sizeSlug: {
185
+ type: 'string',
186
+ },
187
+ alt: {
188
+ type: 'string',
189
+ default: '',
190
+ },
191
+ };
192
+
179
193
  const v7toV11BlockSupports = {
180
194
  anchor: true,
181
195
  align: true,
@@ -244,9 +258,173 @@ const v12BlockSupports = {
244
258
  },
245
259
  };
246
260
 
261
+ const v14BlockSupports = {
262
+ ...v12BlockSupports,
263
+ shadow: true,
264
+ dimensions: {
265
+ aspectRatio: true,
266
+ },
267
+ interactivity: {
268
+ clientNavigation: true,
269
+ },
270
+ };
271
+
272
+ // Deprecation for blocks that have z-index.
273
+ const v14 = {
274
+ attributes: v14BlockAttributes,
275
+ supports: v14BlockSupports,
276
+ save( { attributes } ) {
277
+ const {
278
+ backgroundType,
279
+ gradient,
280
+ contentPosition,
281
+ customGradient,
282
+ customOverlayColor,
283
+ dimRatio,
284
+ focalPoint,
285
+ useFeaturedImage,
286
+ hasParallax,
287
+ isDark,
288
+ isRepeated,
289
+ overlayColor,
290
+ url,
291
+ alt,
292
+ id,
293
+ minHeight: minHeightProp,
294
+ minHeightUnit,
295
+ tagName: Tag,
296
+ sizeSlug,
297
+ } = attributes;
298
+ const overlayColorClass = getColorClassName(
299
+ 'background-color',
300
+ overlayColor
301
+ );
302
+ const gradientClass = __experimentalGetGradientClass( gradient );
303
+ const minHeight =
304
+ minHeightProp && minHeightUnit
305
+ ? `${ minHeightProp }${ minHeightUnit }`
306
+ : minHeightProp;
307
+
308
+ const isImageBackground = IMAGE_BACKGROUND_TYPE === backgroundType;
309
+ const isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType;
310
+
311
+ const isImgElement = ! ( hasParallax || isRepeated );
312
+
313
+ const style = {
314
+ minHeight: minHeight || undefined,
315
+ };
316
+
317
+ const bgStyle = {
318
+ backgroundColor: ! overlayColorClass
319
+ ? customOverlayColor
320
+ : undefined,
321
+ background: customGradient ? customGradient : undefined,
322
+ };
323
+
324
+ const objectPosition =
325
+ // prettier-ignore
326
+ focalPoint && isImgElement
327
+ ? mediaPosition(focalPoint)
328
+ : undefined;
329
+
330
+ const backgroundImage = url ? `url(${ url })` : undefined;
331
+
332
+ const backgroundPosition = mediaPosition( focalPoint );
333
+
334
+ const classes = clsx(
335
+ {
336
+ 'is-light': ! isDark,
337
+ 'has-parallax': hasParallax,
338
+ 'is-repeated': isRepeated,
339
+ 'has-custom-content-position':
340
+ ! isContentPositionCenter( contentPosition ),
341
+ },
342
+ getPositionClassName( contentPosition )
343
+ );
344
+
345
+ const imgClasses = clsx(
346
+ 'wp-block-cover__image-background',
347
+ id ? `wp-image-${ id }` : null,
348
+ {
349
+ [ `size-${ sizeSlug }` ]: sizeSlug,
350
+ 'has-parallax': hasParallax,
351
+ 'is-repeated': isRepeated,
352
+ }
353
+ );
354
+
355
+ const gradientValue = gradient || customGradient;
356
+
357
+ return (
358
+ <Tag { ...useBlockProps.save( { className: classes, style } ) }>
359
+ <span
360
+ aria-hidden="true"
361
+ className={ clsx(
362
+ 'wp-block-cover__background',
363
+ overlayColorClass,
364
+ dimRatioToClass( dimRatio ),
365
+ {
366
+ 'has-background-dim': dimRatio !== undefined,
367
+ // For backwards compatibility. Former versions of the Cover Block applied
368
+ // `.wp-block-cover__gradient-background` in the presence of
369
+ // media, a gradient and a dim.
370
+ 'wp-block-cover__gradient-background':
371
+ url && gradientValue && dimRatio !== 0,
372
+ 'has-background-gradient': gradientValue,
373
+ [ gradientClass ]: gradientClass,
374
+ }
375
+ ) }
376
+ style={ bgStyle }
377
+ />
378
+
379
+ { ! useFeaturedImage &&
380
+ isImageBackground &&
381
+ url &&
382
+ ( isImgElement ? (
383
+ <img
384
+ className={ imgClasses }
385
+ alt={ alt }
386
+ src={ url }
387
+ style={ { objectPosition } }
388
+ data-object-fit="cover"
389
+ data-object-position={ objectPosition }
390
+ />
391
+ ) : (
392
+ <div
393
+ role={ alt ? 'img' : undefined }
394
+ aria-label={ alt ? alt : undefined }
395
+ className={ imgClasses }
396
+ style={ { backgroundPosition, backgroundImage } }
397
+ />
398
+ ) ) }
399
+ { isVideoBackground && url && (
400
+ <video
401
+ className={ clsx(
402
+ 'wp-block-cover__video-background',
403
+ 'intrinsic-ignore'
404
+ ) }
405
+ autoPlay
406
+ muted
407
+ loop
408
+ playsInline
409
+ src={ url }
410
+ style={ { objectPosition } }
411
+ data-object-fit="cover"
412
+ data-object-position={ objectPosition }
413
+ />
414
+ ) }
415
+ <div
416
+ { ...useInnerBlocksProps.save( {
417
+ className: 'wp-block-cover__inner-container',
418
+ } ) }
419
+ />
420
+ </Tag>
421
+ );
422
+ },
423
+ };
424
+
247
425
  // Deprecation for blocks that does not have the aria-label when the image background is fixed or repeated.
248
426
  const v13 = {
249
- attributes: v12BlockAttributes,
427
+ attributes: v12toV13BlockAttributes,
250
428
  supports: v12BlockSupports,
251
429
  save( { attributes } ) {
252
430
  const {
@@ -396,7 +574,7 @@ const v13 = {
396
574
 
397
575
  // Deprecation for blocks to prevent auto overlay color from overriding previously set values.
398
576
  const v12 = {
399
- attributes: v12BlockAttributes,
577
+ attributes: v12toV13BlockAttributes,
400
578
  supports: v12BlockSupports,
401
579
  isEligible( attributes ) {
402
580
  return (
@@ -1824,4 +2002,4 @@ const v1 = {
1824
2002
  },
1825
2003
  };
1826
2004
 
1827
- export default [ v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1 ];
2005
+ export default [ v14, v13, v12, v11, v10, v9, v8, v7, v6, v5, v4, v3, v2, v1 ];
@@ -101,7 +101,7 @@ export default function CoverBlockControls( {
101
101
  onSelect={ onSelectMedia }
102
102
  onToggleFeaturedImage={ toggleUseFeaturedImage }
103
103
  useFeaturedImage={ useFeaturedImage }
104
- name={ ! url ? __( 'Add Media' ) : __( 'Replace' ) }
104
+ name={ ! url ? __( 'Add media' ) : __( 'Replace' ) }
105
105
  onReset={ onClearMedia }
106
106
  />
107
107
  </BlockControls>
@@ -23,9 +23,6 @@ export default function CoverPlaceholder( {
23
23
  icon={ <BlockIcon icon={ icon } /> }
24
24
  labels={ {
25
25
  title: __( 'Cover' ),
26
- instructions: __(
27
- 'Drag and drop onto this block, upload, or select existing media from your library.'
28
- ),
29
26
  } }
30
27
  onSelect={ onSelectMedia }
31
28
  accept="image/*,video/*"
@@ -47,6 +47,7 @@ import {
47
47
  DEFAULT_BACKGROUND_COLOR,
48
48
  DEFAULT_OVERLAY_COLOR,
49
49
  } from './color-utils';
50
+ import { DEFAULT_MEDIA_SIZE_SLUG } from '../constants';
50
51
 
51
52
  function getInnerBlocksTemplate( attributes ) {
52
53
  return [
@@ -100,6 +101,7 @@ function CoverEdit( {
100
101
  templateLock,
101
102
  tagName: TagName = 'div',
102
103
  isUserOverlayColor,
104
+ sizeSlug,
103
105
  } = attributes;
104
106
 
105
107
  const [ featuredImage ] = useEntityProp(
@@ -108,6 +110,7 @@ function CoverEdit( {
108
110
  'featured_media',
109
111
  postId
110
112
  );
113
+ const { getSettings } = useSelect( blockEditorStore );
111
114
 
112
115
  const { __unstableMarkNextChangeAsNotPersistent } =
113
116
  useDispatch( blockEditorStore );
@@ -149,8 +152,7 @@ function CoverEdit( {
149
152
  isUserOverlayColor: isUserOverlayColor || false,
150
153
  } );
151
154
  } )();
152
- // Disable reason: Update the block only when the featured image changes.
153
- // eslint-disable-next-line react-hooks/exhaustive-deps
155
+ // Update the block only when the featured image changes.
154
156
  }, [ mediaUrl ] );
155
157
 
156
158
  // instead of destructuring the attributes
@@ -199,6 +201,34 @@ function CoverEdit( {
199
201
  averageBackgroundColor
200
202
  );
201
203
 
204
+ if ( backgroundType === IMAGE_BACKGROUND_TYPE && mediaAttributes.id ) {
205
+ const { imageDefaultSize } = getSettings();
206
+
207
+ // Try to use the previous selected image size if it's available
208
+ // otherwise try the default image size or fallback to full size.
209
+ if (
210
+ sizeSlug &&
211
+ ( newMedia?.sizes?.[ sizeSlug ] ||
212
+ newMedia?.media_details?.sizes?.[ sizeSlug ] )
213
+ ) {
214
+ mediaAttributes.sizeSlug = sizeSlug;
215
+ mediaAttributes.url =
216
+ newMedia?.sizes?.[ sizeSlug ]?.url ||
217
+ newMedia?.media_details?.sizes?.[ sizeSlug ]?.source_url;
218
+ } else if (
219
+ newMedia?.sizes?.[ imageDefaultSize ] ||
220
+ newMedia?.media_details?.sizes?.[ imageDefaultSize ]
221
+ ) {
222
+ mediaAttributes.sizeSlug = imageDefaultSize;
223
+ mediaAttributes.url =
224
+ newMedia?.sizes?.[ imageDefaultSize ]?.url ||
225
+ newMedia?.media_details?.sizes?.[ imageDefaultSize ]
226
+ ?.source_url;
227
+ } else {
228
+ mediaAttributes.sizeSlug = DEFAULT_MEDIA_SIZE_SLUG;
229
+ }
230
+ }
231
+
202
232
  setAttributes( {
203
233
  ...mediaAttributes,
204
234
  focalPoint: undefined,
@@ -441,7 +471,7 @@ function CoverEdit( {
441
471
  setAttributes( { minHeight: newMinHeight } );
442
472
  },
443
473
  // Hide the resize handle if an aspect ratio is set, as the aspect ratio takes precedence.
444
- showHandle: ! attributes.style?.dimensions?.aspectRatio ? true : false,
474
+ showHandle: ! attributes.style?.dimensions?.aspectRatio,
445
475
  size: resizableBoxDimensions,
446
476
  width,
447
477
  };
@@ -509,27 +539,6 @@ function CoverEdit( {
509
539
  data-url={ url }
510
540
  >
511
541
  { resizeListener }
512
- { showOverlay && (
513
- <span
514
- aria-hidden="true"
515
- className={ clsx(
516
- 'wp-block-cover__background',
517
- dimRatioToClass( dimRatio ),
518
- {
519
- [ overlayColor.class ]: overlayColor.class,
520
- 'has-background-dim': dimRatio !== undefined,
521
- // For backwards compatibility. Former versions of the Cover Block applied
522
- // `.wp-block-cover__gradient-background` in the presence of
523
- // media, a gradient and a dim.
524
- 'wp-block-cover__gradient-background':
525
- url && gradientValue && dimRatio !== 0,
526
- 'has-background-gradient': gradientValue,
527
- [ gradientClass ]: gradientClass,
528
- }
529
- ) }
530
- style={ { backgroundImage: gradientValue, ...bgStyle } }
531
- />
532
- ) }
533
542
 
534
543
  { ! url && useFeaturedImage && (
535
544
  <Placeholder
@@ -571,7 +580,31 @@ function CoverEdit( {
571
580
  style={ mediaStyle }
572
581
  />
573
582
  ) }
583
+
584
+ { showOverlay && (
585
+ <span
586
+ aria-hidden="true"
587
+ className={ clsx(
588
+ 'wp-block-cover__background',
589
+ dimRatioToClass( dimRatio ),
590
+ {
591
+ [ overlayColor.class ]: overlayColor.class,
592
+ 'has-background-dim': dimRatio !== undefined,
593
+ // For backwards compatibility. Former versions of the Cover Block applied
594
+ // `.wp-block-cover__gradient-background` in the presence of
595
+ // media, a gradient and a dim.
596
+ 'wp-block-cover__gradient-background':
597
+ url && gradientValue && dimRatio !== 0,
598
+ 'has-background-gradient': gradientValue,
599
+ [ gradientClass ]: gradientClass,
600
+ }
601
+ ) }
602
+ style={ { backgroundImage: gradientValue, ...bgStyle } }
603
+ />
604
+ ) }
605
+
574
606
  { isUploadingMedia && <Spinner /> }
607
+
575
608
  <CoverPlaceholder
576
609
  disableMediaButtons
577
610
  onSelectMedia={ onSelectMedia }
@@ -19,12 +19,15 @@ import { useInstanceId } from '@wordpress/compose';
19
19
  import {
20
20
  InspectorControls,
21
21
  useSettings,
22
+ store as blockEditorStore,
22
23
  __experimentalColorGradientSettingsDropdown as ColorGradientSettingsDropdown,
23
24
  __experimentalUseGradient,
24
25
  __experimentalUseMultipleOriginColorsAndGradients as useMultipleOriginColorsAndGradients,
25
26
  privateApis as blockEditorPrivateApis,
26
27
  } from '@wordpress/block-editor';
27
28
  import { __ } from '@wordpress/i18n';
29
+ import { useSelect } from '@wordpress/data';
30
+ import { store as coreStore } from '@wordpress/core-data';
28
31
 
29
32
  /**
30
33
  * Internal dependencies
@@ -32,8 +35,9 @@ import { __ } from '@wordpress/i18n';
32
35
  import { COVER_MIN_HEIGHT, mediaPosition } from '../shared';
33
36
  import { unlock } from '../../lock-unlock';
34
37
  import { useToolsPanelDropdownMenuProps } from '../../utils/hooks';
38
+ import { DEFAULT_MEDIA_SIZE_SLUG } from '../constants';
35
39
 
36
- const { cleanEmptyObject } = unlock( blockEditorPrivateApis );
40
+ const { cleanEmptyObject, ResolutionTool } = unlock( blockEditorPrivateApis );
37
41
 
38
42
  function CoverHeightInput( {
39
43
  onChange,
@@ -95,6 +99,7 @@ export default function CoverInspectorControls( {
95
99
  } ) {
96
100
  const {
97
101
  useFeaturedImage,
102
+ id,
98
103
  dimRatio,
99
104
  focalPoint,
100
105
  hasParallax,
@@ -112,7 +117,38 @@ export default function CoverInspectorControls( {
112
117
  overlayColor,
113
118
  } = currentSettings;
114
119
 
120
+ const sizeSlug = attributes.sizeSlug || DEFAULT_MEDIA_SIZE_SLUG;
121
+
115
122
  const { gradientValue, setGradient } = __experimentalUseGradient();
123
+ const { getSettings } = useSelect( blockEditorStore );
124
+
125
+ const imageSizes = getSettings()?.imageSizes;
126
+
127
+ const image = useSelect(
128
+ ( select ) =>
129
+ id && isImageBackground
130
+ ? select( coreStore ).getMedia( id, { context: 'view' } )
131
+ : null,
132
+ [ id, isImageBackground ]
133
+ );
134
+
135
+ function updateImage( newSizeSlug ) {
136
+ const newUrl = image?.media_details?.sizes?.[ newSizeSlug ]?.source_url;
137
+ if ( ! newUrl ) {
138
+ return null;
139
+ }
140
+
141
+ setAttributes( {
142
+ url: newUrl,
143
+ sizeSlug: newSizeSlug,
144
+ } );
145
+ }
146
+
147
+ const imageSizeOptions = imageSizes
148
+ ?.filter(
149
+ ( { slug } ) => image?.media_details?.sizes?.[ slug ]?.source_url
150
+ )
151
+ ?.map( ( { name, slug } ) => ( { value: slug, label: name } ) );
116
152
 
117
153
  const toggleParallax = () => {
118
154
  setAttributes( {
@@ -175,6 +211,7 @@ export default function CoverInspectorControls( {
175
211
  focalPoint: undefined,
176
212
  isRepeated: false,
177
213
  alt: '',
214
+ sizeSlug: undefined,
178
215
  } );
179
216
  } }
180
217
  dropdownMenuProps={ dropdownMenuProps }
@@ -284,6 +321,14 @@ export default function CoverInspectorControls( {
284
321
  />
285
322
  </ToolsPanelItem>
286
323
  ) }
324
+ { ! useFeaturedImage && !! imageSizeOptions?.length && (
325
+ <ResolutionTool
326
+ value={ sizeSlug }
327
+ onChange={ updateImage }
328
+ options={ imageSizeOptions }
329
+ defaultValue={ DEFAULT_MEDIA_SIZE_SLUG }
330
+ />
331
+ ) }
287
332
  </ToolsPanel>
288
333
  ) }
289
334
  </InspectorControls>
@@ -37,12 +37,15 @@
37
37
  width: 100%;
38
38
  z-index: 1;
39
39
  }
40
+
41
+ .wp-block-cover__inner-container {
42
+ z-index: 2;
43
+ }
40
44
  }
41
45
 
42
46
  // Shown while media is being uploaded
43
47
  .components-spinner {
44
48
  position: absolute;
45
- z-index: z-index(".wp-block-cover__inner-container");
46
49
  top: 50%;
47
50
  left: 50%;
48
51
  transform: translate(-50%, -50%); // Account for spinner dimensions
@@ -104,10 +107,6 @@
104
107
  }
105
108
  }
106
109
 
107
- // When uploading background images, show a transparent overlay.
108
- .wp-block-cover > .components-drop-zone .components-drop-zone__content {
109
- opacity: 0.8 !important;
110
- }
111
110
 
112
111
  // Remove the parallax fixed background when in the patterns preview panel as it
113
112
  // doesn't work with the transforms that are applied to resize the block in that context.
package/src/cover/save.js CHANGED
@@ -45,6 +45,7 @@ export default function save( { attributes } ) {
45
45
  minHeight: minHeightProp,
46
46
  minHeightUnit,
47
47
  tagName: Tag,
48
+ sizeSlug,
48
49
  } = attributes;
49
50
  const overlayColorClass = getColorClassName(
50
51
  'background-color',
@@ -95,6 +96,7 @@ export default function save( { attributes } ) {
95
96
  'wp-block-cover__image-background',
96
97
  id ? `wp-image-${ id }` : null,
97
98
  {
99
+ [ `size-${ sizeSlug }` ]: sizeSlug,
98
100
  'has-parallax': hasParallax,
99
101
  'is-repeated': isRepeated,
100
102
  }
@@ -104,26 +106,6 @@ export default function save( { attributes } ) {
104
106
 
105
107
  return (
106
108
  <Tag { ...useBlockProps.save( { className: classes, style } ) }>
107
- <span
108
- aria-hidden="true"
109
- className={ clsx(
110
- 'wp-block-cover__background',
111
- overlayColorClass,
112
- dimRatioToClass( dimRatio ),
113
- {
114
- 'has-background-dim': dimRatio !== undefined,
115
- // For backwards compatibility. Former versions of the Cover Block applied
116
- // `.wp-block-cover__gradient-background` in the presence of
117
- // media, a gradient and a dim.
118
- 'wp-block-cover__gradient-background':
119
- url && gradientValue && dimRatio !== 0,
120
- 'has-background-gradient': gradientValue,
121
- [ gradientClass ]: gradientClass,
122
- }
123
- ) }
124
- style={ bgStyle }
125
- />
126
-
127
109
  { ! useFeaturedImage &&
128
110
  isImageBackground &&
129
111
  url &&
@@ -160,6 +142,33 @@ export default function save( { attributes } ) {
160
142
  data-object-position={ objectPosition }
161
143
  />
162
144
  ) }
145
+
146
+ { /* The `wp-block-cover__background` needs to be immediately before
147
+ the `wp-block-cover__inner-container`, so the exclusion CSS selector
148
+ `.wp-block-cover__background + .wp-block-cover__inner-container`
149
+ works properly. If it needs to be changed in the future, the
150
+ selector for the backward compatibility for v14 deprecation also
151
+ needs change. */ }
152
+ <span
153
+ aria-hidden="true"
154
+ className={ clsx(
155
+ 'wp-block-cover__background',
156
+ overlayColorClass,
157
+ dimRatioToClass( dimRatio ),
158
+ {
159
+ 'has-background-dim': dimRatio !== undefined,
160
+ // For backwards compatibility. Former versions of the Cover Block applied
161
+ // `.wp-block-cover__gradient-background` in the presence of
162
+ // media, a gradient and a dim.
163
+ 'wp-block-cover__gradient-background':
164
+ url && gradientValue && dimRatio !== 0,
165
+ 'has-background-gradient': gradientValue,
166
+ [ gradientClass ]: gradientClass,
167
+ }
168
+ ) }
169
+ style={ bgStyle }
170
+ />
171
+
163
172
  <div
164
173
  { ...useInnerBlocksProps.save( {
165
174
  className: 'wp-block-cover__inner-container',
@@ -54,7 +54,6 @@
54
54
  left: 0;
55
55
  bottom: 0;
56
56
  right: 0;
57
- z-index: z-index(".wp-block-cover.has-background-dim::before");
58
57
  opacity: 0.5;
59
58
  }
60
59
 
@@ -95,8 +94,8 @@
95
94
  }
96
95
 
97
96
  .wp-block-cover__inner-container {
97
+ position: relative; // Needed for the inner container to be positioned above other elements with absolute positioning.
98
98
  width: 100%;
99
- z-index: z-index(".wp-block-cover__inner-container");
100
99
  color: inherit;
101
100
  // Reset the fixed LTR direction at the root of the block in RTL languages.
102
101
  /*rtl:raw: direction: rtl; */
@@ -209,14 +208,6 @@ video.wp-block-cover__video-background {
209
208
  }
210
209
  }
211
210
 
212
- .wp-block-cover__video-background {
213
- z-index: z-index(".wp-block-cover__video-background");
214
- }
215
-
216
- .wp-block-cover__image-background {
217
- z-index: z-index(".wp-block-cover__image-background");
218
- }
219
-
220
211
  // Styles below only exist to support older versions of the block.
221
212
  // Versions that not had inner blocks and used an h2 heading had a section (and not a div) with a class wp-block-cover-image (and not a wp-block-cover).
222
213
  // We are using the previous referred differences to target old versions.
@@ -296,3 +287,42 @@ section.wp-block-cover-image > h2,
296
287
  color: inherit;
297
288
  }
298
289
  }
290
+
291
+ // Backward compatibility for v14 deprecation. Only applied to the frontend.
292
+ // Regarding the `.wp-block-cover__background + .wp-block-cover__inner-container`
293
+ // selector: When the `.wp-block-cover__inner-container` comes right after the
294
+ // `.wp-block-cover__background` , it means that it's using the new HTML
295
+ // structure or that it's using the color background or gradient (even in
296
+ // the deprecated version). In the color background or gradient option we don't
297
+ // need the z-index because the elements are in the expected order.
298
+ body:not(.editor-styles-wrapper) .wp-block-cover:not(
299
+ .wp-block-cover:has(
300
+ .wp-block-cover__background + .wp-block-cover__inner-container
301
+ )
302
+ ) {
303
+ .wp-block-cover__video-background {
304
+ z-index: z-index(".wp-block-cover__video-background");
305
+ }
306
+
307
+ .wp-block-cover__image-background {
308
+ z-index: z-index(".wp-block-cover__image-background");
309
+ }
310
+
311
+ // The first selector is required for old Cover markup/
312
+ // Keep .wp-block-cover__gradient-background for v8 deprecation.
313
+ &.has-background-dim:not(.has-background-gradient)::before,
314
+ .wp-block-cover__background,
315
+ .wp-block-cover__gradient-background {
316
+ z-index: z-index(".wp-block-cover.has-background-dim::before");
317
+ }
318
+
319
+ .wp-block-cover__inner-container {
320
+ z-index: z-index(".wp-block-cover__inner-container");
321
+
322
+ // Reset the z-index to auto when the body has a modal open. So when the
323
+ // modal is inside the cover, it doesn't create a stacking context.
324
+ @at-root .has-modal-open & {
325
+ z-index: auto;
326
+ }
327
+ }
328
+ }