@wordpress/block-library 7.6.0 → 7.7.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 (152) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/button/deprecated.js +175 -35
  3. package/build/button/deprecated.js.map +1 -1
  4. package/build/button/edit.js +1 -1
  5. package/build/button/edit.js.map +1 -1
  6. package/build/button/save.js +1 -1
  7. package/build/button/save.js.map +1 -1
  8. package/build/columns/index.js +3 -1
  9. package/build/columns/index.js.map +1 -1
  10. package/build/cover/deprecated.js +212 -207
  11. package/build/cover/deprecated.js.map +1 -1
  12. package/build/cover/edit/index.js +13 -3
  13. package/build/cover/edit/index.js.map +1 -1
  14. package/build/cover/save.js +18 -5
  15. package/build/cover/save.js.map +1 -1
  16. package/build/cover/shared.js +14 -17
  17. package/build/cover/shared.js.map +1 -1
  18. package/build/file/edit.js +1 -1
  19. package/build/file/edit.js.map +1 -1
  20. package/build/file/save.js +9 -1
  21. package/build/file/save.js.map +1 -1
  22. package/build/gallery/gap-styles.js +14 -4
  23. package/build/gallery/gap-styles.js.map +1 -1
  24. package/build/gallery/index.js +1 -1
  25. package/build/image/edit.js +5 -59
  26. package/build/image/edit.js.map +1 -1
  27. package/build/image/edit.native.js +56 -3
  28. package/build/image/edit.native.js.map +1 -1
  29. package/build/image/image.js +3 -13
  30. package/build/image/image.js.map +1 -1
  31. package/build/list-item/hooks/use-split.js +17 -3
  32. package/build/list-item/hooks/use-split.js.map +1 -1
  33. package/build/navigation-link/edit.js +31 -5
  34. package/build/navigation-link/edit.js.map +1 -1
  35. package/build/post-author-name/index.js +3 -0
  36. package/build/post-author-name/index.js.map +1 -1
  37. package/build/post-author-name/transforms.js +41 -0
  38. package/build/post-author-name/transforms.js.map +1 -0
  39. package/build/post-comments-form/form.js +11 -1
  40. package/build/post-comments-form/form.js.map +1 -1
  41. package/build/post-date/edit.js +13 -7
  42. package/build/post-date/edit.js.map +1 -1
  43. package/build/search/edit.js +1 -1
  44. package/build/search/edit.js.map +1 -1
  45. package/build/search/index.js +4 -0
  46. package/build/search/index.js.map +1 -1
  47. package/build/shortcode/edit.native.js +16 -13
  48. package/build/shortcode/edit.native.js.map +1 -1
  49. package/build/social-links/edit.js +2 -2
  50. package/build/social-links/edit.js.map +1 -1
  51. package/build/table-of-contents/edit.js +11 -3
  52. package/build/table-of-contents/edit.js.map +1 -1
  53. package/build-module/button/deprecated.js +175 -35
  54. package/build-module/button/deprecated.js.map +1 -1
  55. package/build-module/button/edit.js +2 -2
  56. package/build-module/button/edit.js.map +1 -1
  57. package/build-module/button/save.js +2 -2
  58. package/build-module/button/save.js.map +1 -1
  59. package/build-module/columns/index.js +3 -1
  60. package/build-module/columns/index.js.map +1 -1
  61. package/build-module/cover/deprecated.js +206 -198
  62. package/build-module/cover/deprecated.js.map +1 -1
  63. package/build-module/cover/edit/index.js +14 -4
  64. package/build-module/cover/edit/index.js.map +1 -1
  65. package/build-module/cover/save.js +19 -6
  66. package/build-module/cover/save.js.map +1 -1
  67. package/build-module/cover/shared.js +11 -12
  68. package/build-module/cover/shared.js.map +1 -1
  69. package/build-module/file/edit.js +2 -2
  70. package/build-module/file/edit.js.map +1 -1
  71. package/build-module/file/save.js +7 -2
  72. package/build-module/file/save.js.map +1 -1
  73. package/build-module/gallery/gap-styles.js +14 -4
  74. package/build-module/gallery/gap-styles.js.map +1 -1
  75. package/build-module/gallery/index.js +1 -1
  76. package/build-module/image/edit.js +5 -56
  77. package/build-module/image/edit.js.map +1 -1
  78. package/build-module/image/edit.native.js +57 -5
  79. package/build-module/image/edit.native.js.map +1 -1
  80. package/build-module/image/image.js +4 -14
  81. package/build-module/image/image.js.map +1 -1
  82. package/build-module/list-item/hooks/use-split.js +19 -5
  83. package/build-module/list-item/hooks/use-split.js.map +1 -1
  84. package/build-module/navigation-link/edit.js +31 -6
  85. package/build-module/navigation-link/edit.js.map +1 -1
  86. package/build-module/post-author-name/index.js +2 -0
  87. package/build-module/post-author-name/index.js.map +1 -1
  88. package/build-module/post-author-name/transforms.js +32 -0
  89. package/build-module/post-author-name/transforms.js.map +1 -0
  90. package/build-module/post-comments-form/form.js +7 -1
  91. package/build-module/post-comments-form/form.js.map +1 -1
  92. package/build-module/post-date/edit.js +15 -9
  93. package/build-module/post-date/edit.js.map +1 -1
  94. package/build-module/search/edit.js +2 -2
  95. package/build-module/search/edit.js.map +1 -1
  96. package/build-module/search/index.js +4 -0
  97. package/build-module/search/index.js.map +1 -1
  98. package/build-module/shortcode/edit.native.js +17 -13
  99. package/build-module/shortcode/edit.native.js.map +1 -1
  100. package/build-module/social-links/edit.js +2 -2
  101. package/build-module/social-links/edit.js.map +1 -1
  102. package/build-module/table-of-contents/edit.js +12 -4
  103. package/build-module/table-of-contents/edit.js.map +1 -1
  104. package/build-style/cover/style-rtl.css +32 -23
  105. package/build-style/cover/style.css +32 -23
  106. package/build-style/site-logo/style-rtl.css +4 -0
  107. package/build-style/site-logo/style.css +4 -0
  108. package/build-style/style-rtl.css +36 -23
  109. package/build-style/style.css +36 -23
  110. package/package.json +28 -28
  111. package/src/button/deprecated.js +145 -0
  112. package/src/button/edit.js +3 -1
  113. package/src/button/save.js +3 -1
  114. package/src/buttons/test/__snapshots__/edit.native.js.snap +1 -1
  115. package/src/buttons/test/edit.native.js +1 -1
  116. package/src/columns/block.json +3 -1
  117. package/src/cover/deprecated.js +230 -183
  118. package/src/cover/edit/index.js +25 -13
  119. package/src/cover/save.js +26 -13
  120. package/src/cover/shared.js +5 -7
  121. package/src/cover/style.scss +27 -22
  122. package/src/file/edit.js +5 -1
  123. package/src/file/save.js +14 -2
  124. package/src/gallery/block.json +1 -1
  125. package/src/gallery/gap-styles.js +21 -6
  126. package/src/gallery/index.php +23 -12
  127. package/src/image/edit.js +1 -53
  128. package/src/image/edit.native.js +65 -3
  129. package/src/image/image.js +2 -11
  130. package/src/image/styles.native.scss +11 -0
  131. package/src/list-item/hooks/use-split.js +18 -9
  132. package/src/navigation-link/edit.js +35 -5
  133. package/src/navigation-link/test/edit.js +0 -20
  134. package/src/post-author/index.php +3 -2
  135. package/src/post-author-name/index.js +2 -0
  136. package/src/post-author-name/index.php +1 -1
  137. package/src/post-author-name/transforms.js +25 -0
  138. package/src/post-comments/index.php +1 -1
  139. package/src/post-comments-form/form.js +11 -1
  140. package/src/post-comments-form/index.php +1 -1
  141. package/src/post-date/edit.js +4 -3
  142. package/src/query-pagination/index.php +0 -1
  143. package/src/search/block.json +4 -0
  144. package/src/search/edit.js +3 -1
  145. package/src/search/index.php +28 -15
  146. package/src/shortcode/edit.native.js +29 -15
  147. package/src/shortcode/style.native.scss +11 -4
  148. package/src/shortcode/test/__snapshots__/edit.native.js.snap +9 -0
  149. package/src/shortcode/test/edit.native.js +58 -40
  150. package/src/site-logo/style.scss +6 -0
  151. package/src/social-links/edit.js +11 -10
  152. package/src/table-of-contents/edit.js +19 -6
@@ -24,12 +24,15 @@ import { __ } from '@wordpress/i18n';
24
24
  import {
25
25
  IMAGE_BACKGROUND_TYPE,
26
26
  VIDEO_BACKGROUND_TYPE,
27
- backgroundImageStyles,
28
27
  getPositionClassName,
29
28
  isContentPositionCenter,
30
29
  dimRatioToClass,
31
30
  } from './shared';
32
31
 
32
+ function backgroundImageStyles( url ) {
33
+ return url ? { backgroundImage: `url(${ url })` } : {};
34
+ }
35
+
33
36
  /**
34
37
  * Original function to determine the background opacity classname
35
38
  *
@@ -81,91 +84,232 @@ const blockAttributes = {
81
84
  },
82
85
  };
83
86
 
84
- // Deprecation for blocks with `minHeightUnit` set but no `minHeight`.
85
- const v9 = {
86
- attributes: {
87
- url: {
88
- type: 'string',
89
- },
90
- id: {
91
- type: 'number',
92
- },
93
- alt: {
94
- type: 'string',
95
- source: 'attribute',
96
- selector: 'img',
97
- attribute: 'alt',
98
- default: '',
99
- },
100
- hasParallax: {
101
- type: 'boolean',
102
- default: false,
103
- },
104
- isRepeated: {
105
- type: 'boolean',
106
- default: false,
107
- },
108
- dimRatio: {
109
- type: 'number',
110
- default: 100,
111
- },
112
- overlayColor: {
113
- type: 'string',
114
- },
115
- customOverlayColor: {
116
- type: 'string',
117
- },
118
- backgroundType: {
119
- type: 'string',
120
- default: 'image',
121
- },
122
- focalPoint: {
123
- type: 'object',
124
- },
125
- minHeight: {
126
- type: 'number',
127
- },
128
- minHeightUnit: {
129
- type: 'string',
130
- },
131
- gradient: {
132
- type: 'string',
133
- },
134
- customGradient: {
135
- type: 'string',
136
- },
137
- contentPosition: {
138
- type: 'string',
139
- },
140
- isDark: {
141
- type: 'boolean',
142
- default: true,
143
- },
144
- allowedBlocks: {
145
- type: 'array',
146
- },
147
- templateLock: {
148
- type: [ 'string', 'boolean' ],
149
- enum: [ 'all', 'insert', false ],
150
- },
87
+ const v8ToV10BlockAttributes = {
88
+ url: {
89
+ type: 'string',
151
90
  },
152
- supports: {
153
- anchor: true,
154
- align: true,
155
- html: false,
156
- spacing: {
91
+ id: {
92
+ type: 'number',
93
+ },
94
+ alt: {
95
+ type: 'string',
96
+ source: 'attribute',
97
+ selector: 'img',
98
+ attribute: 'alt',
99
+ default: '',
100
+ },
101
+ hasParallax: {
102
+ type: 'boolean',
103
+ default: false,
104
+ },
105
+ isRepeated: {
106
+ type: 'boolean',
107
+ default: false,
108
+ },
109
+ dimRatio: {
110
+ type: 'number',
111
+ default: 100,
112
+ },
113
+ overlayColor: {
114
+ type: 'string',
115
+ },
116
+ customOverlayColor: {
117
+ type: 'string',
118
+ },
119
+ backgroundType: {
120
+ type: 'string',
121
+ default: 'image',
122
+ },
123
+ focalPoint: {
124
+ type: 'object',
125
+ },
126
+ minHeight: {
127
+ type: 'number',
128
+ },
129
+ minHeightUnit: {
130
+ type: 'string',
131
+ },
132
+ gradient: {
133
+ type: 'string',
134
+ },
135
+ customGradient: {
136
+ type: 'string',
137
+ },
138
+ contentPosition: {
139
+ type: 'string',
140
+ },
141
+ isDark: {
142
+ type: 'boolean',
143
+ default: true,
144
+ },
145
+ allowedBlocks: {
146
+ type: 'array',
147
+ },
148
+ templateLock: {
149
+ type: [ 'string', 'boolean' ],
150
+ enum: [ 'all', 'insert', false ],
151
+ },
152
+ };
153
+
154
+ const v7toV10BlockSupports = {
155
+ anchor: true,
156
+ align: true,
157
+ html: false,
158
+ spacing: {
159
+ padding: true,
160
+ __experimentalDefaultControls: {
157
161
  padding: true,
158
- __experimentalDefaultControls: {
159
- padding: true,
160
- },
161
- },
162
- color: {
163
- __experimentalDuotone:
164
- '> .wp-block-cover__image-background, > .wp-block-cover__video-background',
165
- text: false,
166
- background: false,
167
162
  },
168
163
  },
164
+ color: {
165
+ __experimentalDuotone:
166
+ '> .wp-block-cover__image-background, > .wp-block-cover__video-background',
167
+ text: false,
168
+ background: false,
169
+ },
170
+ };
171
+
172
+ // Deprecation for blocks that renders fixed background as backgroud from the main block container.
173
+ const v10 = {
174
+ attributes: v8ToV10BlockAttributes,
175
+ supports: v7toV10BlockSupports,
176
+ save( { attributes } ) {
177
+ const {
178
+ backgroundType,
179
+ gradient,
180
+ contentPosition,
181
+ customGradient,
182
+ customOverlayColor,
183
+ dimRatio,
184
+ focalPoint,
185
+ useFeaturedImage,
186
+ hasParallax,
187
+ isDark,
188
+ isRepeated,
189
+ overlayColor,
190
+ url,
191
+ alt,
192
+ id,
193
+ minHeight: minHeightProp,
194
+ minHeightUnit,
195
+ } = attributes;
196
+ const overlayColorClass = getColorClassName(
197
+ 'background-color',
198
+ overlayColor
199
+ );
200
+ const gradientClass = __experimentalGetGradientClass( gradient );
201
+ const minHeight =
202
+ minHeightProp && minHeightUnit
203
+ ? `${ minHeightProp }${ minHeightUnit }`
204
+ : minHeightProp;
205
+
206
+ const isImageBackground = IMAGE_BACKGROUND_TYPE === backgroundType;
207
+ const isVideoBackground = VIDEO_BACKGROUND_TYPE === backgroundType;
208
+
209
+ const isImgElement = ! ( hasParallax || isRepeated );
210
+
211
+ const style = {
212
+ ...( isImageBackground && ! isImgElement && ! useFeaturedImage
213
+ ? backgroundImageStyles( url )
214
+ : {} ),
215
+ minHeight: minHeight || undefined,
216
+ };
217
+
218
+ const bgStyle = {
219
+ backgroundColor: ! overlayColorClass
220
+ ? customOverlayColor
221
+ : undefined,
222
+ background: customGradient ? customGradient : undefined,
223
+ };
224
+
225
+ const objectPosition =
226
+ // prettier-ignore
227
+ focalPoint && isImgElement
228
+ ? `${ Math.round( focalPoint.x * 100 ) }% ${ Math.round( focalPoint.y * 100 ) }%`
229
+ : undefined;
230
+
231
+ const classes = classnames(
232
+ {
233
+ 'is-light': ! isDark,
234
+ 'has-parallax': hasParallax,
235
+ 'is-repeated': isRepeated,
236
+ 'has-custom-content-position': ! isContentPositionCenter(
237
+ contentPosition
238
+ ),
239
+ },
240
+ getPositionClassName( contentPosition )
241
+ );
242
+
243
+ const gradientValue = gradient || customGradient;
244
+
245
+ return (
246
+ <div { ...useBlockProps.save( { className: classes, style } ) }>
247
+ <span
248
+ aria-hidden="true"
249
+ className={ classnames(
250
+ 'wp-block-cover__background',
251
+ overlayColorClass,
252
+ dimRatioToClass( dimRatio ),
253
+ {
254
+ 'has-background-dim': dimRatio !== undefined,
255
+ // For backwards compatibility. Former versions of the Cover Block applied
256
+ // `.wp-block-cover__gradient-background` in the presence of
257
+ // media, a gradient and a dim.
258
+ 'wp-block-cover__gradient-background':
259
+ url && gradientValue && dimRatio !== 0,
260
+ 'has-background-gradient': gradientValue,
261
+ [ gradientClass ]: gradientClass,
262
+ }
263
+ ) }
264
+ style={ bgStyle }
265
+ />
266
+
267
+ { ! useFeaturedImage &&
268
+ isImageBackground &&
269
+ isImgElement &&
270
+ url && (
271
+ <img
272
+ className={ classnames(
273
+ 'wp-block-cover__image-background',
274
+ id ? `wp-image-${ id }` : null
275
+ ) }
276
+ alt={ alt }
277
+ src={ url }
278
+ style={ { objectPosition } }
279
+ data-object-fit="cover"
280
+ data-object-position={ objectPosition }
281
+ />
282
+ ) }
283
+ { isVideoBackground && url && (
284
+ <video
285
+ className={ classnames(
286
+ 'wp-block-cover__video-background',
287
+ 'intrinsic-ignore'
288
+ ) }
289
+ autoPlay
290
+ muted
291
+ loop
292
+ playsInline
293
+ src={ url }
294
+ style={ { objectPosition } }
295
+ data-object-fit="cover"
296
+ data-object-position={ objectPosition }
297
+ />
298
+ ) }
299
+ <div
300
+ { ...useInnerBlocksProps.save( {
301
+ className: 'wp-block-cover__inner-container',
302
+ } ) }
303
+ />
304
+ </div>
305
+ );
306
+ },
307
+ };
308
+
309
+ // Deprecation for blocks with `minHeightUnit` set but no `minHeight`.
310
+ const v9 = {
311
+ attributes: v8ToV10BlockAttributes,
312
+ supports: v7toV10BlockSupports,
169
313
  save( { attributes } ) {
170
314
  const {
171
315
  backgroundType,
@@ -296,89 +440,8 @@ const v9 = {
296
440
 
297
441
  // v8: deprecated to remove duplicated gradient classes and swap `wp-block-cover__gradient-background` for `wp-block-cover__background`.
298
442
  const v8 = {
299
- attributes: {
300
- url: {
301
- type: 'string',
302
- },
303
- id: {
304
- type: 'number',
305
- },
306
- alt: {
307
- type: 'string',
308
- source: 'attribute',
309
- selector: 'img',
310
- attribute: 'alt',
311
- default: '',
312
- },
313
- hasParallax: {
314
- type: 'boolean',
315
- default: false,
316
- },
317
- isRepeated: {
318
- type: 'boolean',
319
- default: false,
320
- },
321
- dimRatio: {
322
- type: 'number',
323
- default: 100,
324
- },
325
- overlayColor: {
326
- type: 'string',
327
- },
328
- customOverlayColor: {
329
- type: 'string',
330
- },
331
- backgroundType: {
332
- type: 'string',
333
- default: 'image',
334
- },
335
- focalPoint: {
336
- type: 'object',
337
- },
338
- minHeight: {
339
- type: 'number',
340
- },
341
- minHeightUnit: {
342
- type: 'string',
343
- },
344
- gradient: {
345
- type: 'string',
346
- },
347
- customGradient: {
348
- type: 'string',
349
- },
350
- contentPosition: {
351
- type: 'string',
352
- },
353
- isDark: {
354
- type: 'boolean',
355
- default: true,
356
- },
357
- allowedBlocks: {
358
- type: 'array',
359
- },
360
- templateLock: {
361
- type: [ 'string', 'boolean' ],
362
- enum: [ 'all', 'insert', false ],
363
- },
364
- },
365
- supports: {
366
- anchor: true,
367
- align: true,
368
- html: false,
369
- spacing: {
370
- padding: true,
371
- __experimentalDefaultControls: {
372
- padding: true,
373
- },
374
- },
375
- color: {
376
- __experimentalDuotone:
377
- '> .wp-block-cover__image-background, > .wp-block-cover__video-background',
378
- text: false,
379
- background: false,
380
- },
381
- },
443
+ attributes: v8ToV10BlockAttributes,
444
+ supports: v7toV10BlockSupports,
382
445
  save( { attributes } ) {
383
446
  const {
384
447
  backgroundType,
@@ -532,23 +595,7 @@ const v7 = {
532
595
  default: '',
533
596
  },
534
597
  },
535
- supports: {
536
- anchor: true,
537
- align: true,
538
- html: false,
539
- spacing: {
540
- padding: true,
541
- __experimentalDefaultControls: {
542
- padding: true,
543
- },
544
- },
545
- color: {
546
- __experimentalDuotone:
547
- '> .wp-block-cover__image-background, > .wp-block-cover__video-background',
548
- text: false,
549
- background: false,
550
- },
551
- },
598
+ supports: v7toV10BlockSupports,
552
599
  save( { attributes } ) {
553
600
  const {
554
601
  backgroundType,
@@ -1231,4 +1278,4 @@ const v1 = {
1231
1278
  },
1232
1279
  };
1233
1280
 
1234
- export default [ v9, v8, v7, v6, v5, v4, v3, v2, v1 ];
1281
+ export default [ v10, v9, v8, v7, v6, v5, v4, v3, v2, v1 ];
@@ -33,7 +33,6 @@ import {
33
33
  attributesFromMedia,
34
34
  IMAGE_BACKGROUND_TYPE,
35
35
  VIDEO_BACKGROUND_TYPE,
36
- backgroundImageStyles,
37
36
  dimRatioToClass,
38
37
  isContentPositionCenter,
39
38
  getPositionClassName,
@@ -158,12 +157,13 @@ function CoverEdit( {
158
157
  const isImgElement = ! ( hasParallax || isRepeated );
159
158
 
160
159
  const style = {
161
- ...( isImageBackground && ! isImgElement
162
- ? backgroundImageStyles( url )
163
- : undefined ),
164
160
  minHeight: minHeightWithUnit || undefined,
165
161
  };
166
162
 
163
+ const backgroundImage = url ? `url(${ url })` : undefined;
164
+
165
+ const backgroundPosition = mediaPosition( focalPoint );
166
+
167
167
  const bgStyle = { backgroundColor: overlayColor.color };
168
168
  const mediaStyle = {
169
169
  objectPosition:
@@ -344,15 +344,27 @@ function CoverEdit( {
344
344
  style={ { backgroundImage: gradientValue, ...bgStyle } }
345
345
  />
346
346
 
347
- { url && isImageBackground && isImgElement && (
348
- <img
349
- ref={ mediaElement }
350
- className="wp-block-cover__image-background"
351
- alt={ alt }
352
- src={ url }
353
- style={ mediaStyle }
354
- />
355
- ) }
347
+ { url &&
348
+ isImageBackground &&
349
+ ( isImgElement ? (
350
+ <img
351
+ ref={ mediaElement }
352
+ className="wp-block-cover__image-background"
353
+ alt={ alt }
354
+ src={ url }
355
+ style={ mediaStyle }
356
+ />
357
+ ) : (
358
+ <div
359
+ ref={ mediaElement }
360
+ role="img"
361
+ className={ classnames(
362
+ classes,
363
+ 'wp-block-cover__image-background'
364
+ ) }
365
+ style={ { backgroundImage, backgroundPosition } }
366
+ />
367
+ ) ) }
356
368
  { url && isVideoBackground && (
357
369
  <video
358
370
  ref={ mediaElement }
package/src/cover/save.js CHANGED
@@ -19,10 +19,10 @@ import {
19
19
  import {
20
20
  IMAGE_BACKGROUND_TYPE,
21
21
  VIDEO_BACKGROUND_TYPE,
22
- backgroundImageStyles,
23
22
  dimRatioToClass,
24
23
  isContentPositionCenter,
25
24
  getPositionClassName,
25
+ mediaPosition,
26
26
  } from './shared';
27
27
 
28
28
  export default function save( { attributes } ) {
@@ -61,9 +61,6 @@ export default function save( { attributes } ) {
61
61
  const isImgElement = ! ( hasParallax || isRepeated );
62
62
 
63
63
  const style = {
64
- ...( isImageBackground && ! isImgElement && ! useFeaturedImage
65
- ? backgroundImageStyles( url )
66
- : {} ),
67
64
  minHeight: minHeight || undefined,
68
65
  };
69
66
 
@@ -75,8 +72,12 @@ export default function save( { attributes } ) {
75
72
  const objectPosition =
76
73
  // prettier-ignore
77
74
  focalPoint && isImgElement
78
- ? `${ Math.round( focalPoint.x * 100 ) }% ${ Math.round( focalPoint.y * 100 ) }%`
79
- : undefined;
75
+ ? mediaPosition(focalPoint)
76
+ : undefined;
77
+
78
+ const backgroundImage = url ? `url(${ url })` : undefined;
79
+
80
+ const backgroundPosition = mediaPosition( focalPoint );
80
81
 
81
82
  const classes = classnames(
82
83
  {
@@ -90,6 +91,15 @@ export default function save( { attributes } ) {
90
91
  getPositionClassName( contentPosition )
91
92
  );
92
93
 
94
+ const imgClasses = classnames(
95
+ 'wp-block-cover__image-background',
96
+ id ? `wp-image-${ id }` : null,
97
+ {
98
+ 'has-parallax': hasParallax,
99
+ 'is-repeated': isRepeated,
100
+ }
101
+ );
102
+
93
103
  const gradientValue = gradient || customGradient;
94
104
 
95
105
  return (
@@ -116,20 +126,23 @@ export default function save( { attributes } ) {
116
126
 
117
127
  { ! useFeaturedImage &&
118
128
  isImageBackground &&
119
- isImgElement &&
120
- url && (
129
+ url &&
130
+ ( isImgElement ? (
121
131
  <img
122
- className={ classnames(
123
- 'wp-block-cover__image-background',
124
- id ? `wp-image-${ id }` : null
125
- ) }
132
+ className={ imgClasses }
126
133
  alt={ alt }
127
134
  src={ url }
128
135
  style={ { objectPosition } }
129
136
  data-object-fit="cover"
130
137
  data-object-position={ objectPosition }
131
138
  />
132
- ) }
139
+ ) : (
140
+ <div
141
+ role="img"
142
+ className={ imgClasses }
143
+ style={ { backgroundPosition, backgroundImage } }
144
+ />
145
+ ) ) }
133
146
  { isVideoBackground && url && (
134
147
  <video
135
148
  className={ classnames(
@@ -21,11 +21,13 @@ export const VIDEO_BACKGROUND_TYPE = 'video';
21
21
  export const COVER_MIN_HEIGHT = 50;
22
22
  export const COVER_MAX_HEIGHT = 1000;
23
23
  export const COVER_DEFAULT_HEIGHT = 300;
24
- export function backgroundImageStyles( url ) {
25
- return url ? { backgroundImage: `url(${ url })` } : {};
26
- }
24
+ export const DEFAULT_FOCAL_POINT = { x: 0.5, y: 0.5 };
27
25
  export const ALLOWED_MEDIA_TYPES = [ 'image', 'video' ];
28
26
 
27
+ export function mediaPosition( { x, y } = DEFAULT_FOCAL_POINT ) {
28
+ return `${ Math.round( x * 100 ) }% ${ Math.round( y * 100 ) }%`;
29
+ }
30
+
29
31
  export function dimRatioToClass( ratio ) {
30
32
  return ratio === 50 || ! ratio === undefined
31
33
  ? null
@@ -106,7 +108,3 @@ export function getPositionClassName( contentPosition ) {
106
108
 
107
109
  return POSITION_CLASSNAMES[ contentPosition ];
108
110
  }
109
-
110
- export function mediaPosition( { x, y } ) {
111
- return `${ Math.round( x * 100 ) }% ${ Math.round( y * 100 ) }%`;
112
- }
@@ -12,27 +12,6 @@
12
12
  // This block has customizable padding, border-box makes that more predictable.
13
13
  box-sizing: border-box;
14
14
 
15
- &.has-parallax {
16
- background-attachment: fixed;
17
-
18
- // Mobile Safari does not support fixed background attachment properly.
19
- // See also https://stackoverflow.com/questions/24154666/background-size-cover-not-working-on-ios
20
- // Chrome on Android does not appear to support the attachment at all: https://issuetracker.google.com/issues/36908439
21
- @supports (-webkit-touch-callout: inherit) {
22
- background-attachment: scroll;
23
- }
24
-
25
- // Remove the appearance of scrolling based on OS-level animation preferences.
26
- @media (prefers-reduced-motion: reduce) {
27
- background-attachment: scroll;
28
- }
29
- }
30
-
31
- &.is-repeated {
32
- background-repeat: repeat;
33
- background-size: auto;
34
- }
35
-
36
15
  /**
37
16
  * Set a default background color for has-background-dim _unless_ it includes another
38
17
  * background-color class (e.g. has-green-background-color). The presence of another
@@ -196,7 +175,7 @@
196
175
  }
197
176
 
198
177
  // Extra specificity for in edit mode where other styles would override it otherwise.
199
- img.wp-block-cover__image-background,
178
+ .wp-block-cover__image-background,
200
179
  video.wp-block-cover__video-background {
201
180
  position: absolute;
202
181
  top: 0;
@@ -216,6 +195,32 @@
216
195
  }
217
196
  }
218
197
 
198
+ .wp-block-cover-image,
199
+ .wp-block-cover,
200
+ .wp-block-cover__image-background,
201
+ video.wp-block-cover__video-background {
202
+ &.has-parallax {
203
+ background-attachment: fixed;
204
+
205
+ // Mobile Safari does not support fixed background attachment properly.
206
+ // See also https://stackoverflow.com/questions/24154666/background-size-cover-not-working-on-ios
207
+ // Chrome on Android does not appear to support the attachment at all: https://issuetracker.google.com/issues/36908439
208
+ @supports (-webkit-overflow-scrolling: touch) {
209
+ background-attachment: scroll;
210
+ }
211
+
212
+ // Remove the appearance of scrolling based on OS-level animation preferences.
213
+ @media (prefers-reduced-motion: reduce) {
214
+ background-attachment: scroll;
215
+ }
216
+ }
217
+
218
+ &.is-repeated {
219
+ background-repeat: repeat;
220
+ background-size: auto;
221
+ }
222
+ }
223
+
219
224
  .wp-block-cover__video-background {
220
225
  z-index: z-index(".wp-block-cover__video-background");
221
226
  }
package/src/file/edit.js CHANGED
@@ -22,6 +22,7 @@ import {
22
22
  RichText,
23
23
  useBlockProps,
24
24
  store as blockEditorStore,
25
+ __experimentalElementButtonClassName,
25
26
  } from '@wordpress/block-editor';
26
27
  import { useEffect } from '@wordpress/element';
27
28
  import { useCopyToClipboard } from '@wordpress/compose';
@@ -301,7 +302,10 @@ function FileEdit( {
301
302
  <RichText
302
303
  tagName="div" // Must be block-level or else cursor disappears.
303
304
  aria-label={ __( 'Download button text' ) }
304
- className={ 'wp-block-file__button' }
305
+ className={ classnames(
306
+ 'wp-block-file__button',
307
+ __experimentalElementButtonClassName
308
+ ) }
305
309
  value={ downloadButtonText }
306
310
  withoutInteractiveFormatting
307
311
  placeholder={ __( 'Add text…' ) }