@wordpress/block-library 8.12.7 → 8.12.8

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 (50) hide show
  1. package/build/footnotes/edit.js +20 -1
  2. package/build/footnotes/edit.js.map +1 -1
  3. package/build/footnotes/format.js +2 -7
  4. package/build/footnotes/format.js.map +1 -1
  5. package/build/footnotes/index.js +0 -1
  6. package/build/footnotes/index.js.map +1 -1
  7. package/build/image/deprecated.js +453 -175
  8. package/build/image/deprecated.js.map +1 -1
  9. package/build/image/save.js +3 -1
  10. package/build/image/save.js.map +1 -1
  11. package/build/list/edit.js +4 -4
  12. package/build/list/edit.js.map +1 -1
  13. package/build/navigation-link/edit.js +10 -5
  14. package/build/navigation-link/edit.js.map +1 -1
  15. package/build/quote/transforms.js +8 -0
  16. package/build/quote/transforms.js.map +1 -1
  17. package/build-module/footnotes/edit.js +18 -2
  18. package/build-module/footnotes/edit.js.map +1 -1
  19. package/build-module/footnotes/format.js +2 -7
  20. package/build-module/footnotes/format.js.map +1 -1
  21. package/build-module/footnotes/index.js +0 -1
  22. package/build-module/footnotes/index.js.map +1 -1
  23. package/build-module/image/deprecated.js +454 -176
  24. package/build-module/image/deprecated.js.map +1 -1
  25. package/build-module/image/save.js +3 -1
  26. package/build-module/image/save.js.map +1 -1
  27. package/build-module/list/edit.js +4 -4
  28. package/build-module/list/edit.js.map +1 -1
  29. package/build-module/navigation-link/edit.js +10 -5
  30. package/build-module/navigation-link/edit.js.map +1 -1
  31. package/build-module/quote/transforms.js +8 -0
  32. package/build-module/quote/transforms.js.map +1 -1
  33. package/build-style/footnotes/style-rtl.css +4 -3
  34. package/build-style/footnotes/style.css +4 -3
  35. package/build-style/style-rtl.css +4 -3
  36. package/build-style/style.css +4 -3
  37. package/package.json +8 -8
  38. package/src/comment-template/index.php +5 -2
  39. package/src/footnotes/block.json +0 -1
  40. package/src/footnotes/edit.js +21 -2
  41. package/src/footnotes/format.js +2 -6
  42. package/src/footnotes/style.scss +6 -3
  43. package/src/image/deprecated.js +597 -320
  44. package/src/image/save.js +2 -0
  45. package/src/list/edit.js +6 -4
  46. package/src/navigation-link/edit.js +59 -45
  47. package/src/post-template/index.php +4 -2
  48. package/src/quote/test/__snapshots__/transforms.native.js.snap +10 -0
  49. package/src/quote/test/transforms.native.js +5 -1
  50. package/src/quote/transforms.js +13 -0
@@ -6,355 +6,632 @@ import classnames from 'classnames';
6
6
  /**
7
7
  * WordPress dependencies
8
8
  */
9
- import { RichText, useBlockProps } from '@wordpress/block-editor';
9
+ import {
10
+ RichText,
11
+ useBlockProps,
12
+ __experimentalGetElementClassName as getBorderClassesAndStyles,
13
+ } from '@wordpress/block-editor';
10
14
 
11
- const blockAttributes = {
12
- align: {
13
- type: 'string',
14
- },
15
- url: {
16
- type: 'string',
17
- source: 'attribute',
18
- selector: 'img',
19
- attribute: 'src',
20
- },
21
- alt: {
22
- type: 'string',
23
- source: 'attribute',
24
- selector: 'img',
25
- attribute: 'alt',
26
- default: '',
27
- },
28
- caption: {
29
- type: 'string',
30
- source: 'html',
31
- selector: 'figcaption',
32
- },
33
- title: {
34
- type: 'string',
35
- source: 'attribute',
36
- selector: 'img',
37
- attribute: 'title',
38
- },
39
- href: {
40
- type: 'string',
41
- source: 'attribute',
42
- selector: 'figure > a',
43
- attribute: 'href',
44
- },
45
- rel: {
46
- type: 'string',
47
- source: 'attribute',
48
- selector: 'figure > a',
49
- attribute: 'rel',
50
- },
51
- linkClass: {
52
- type: 'string',
53
- source: 'attribute',
54
- selector: 'figure > a',
55
- attribute: 'class',
56
- },
57
- id: {
58
- type: 'number',
15
+ /**
16
+ * Deprecation for adding the `wp-image-${id}` class to the image block for
17
+ * responsive images.
18
+ *
19
+ * @see https://github.com/WordPress/gutenberg/pull/4898
20
+ */
21
+ const v1 = {
22
+ attributes: {
23
+ url: {
24
+ type: 'string',
25
+ source: 'attribute',
26
+ selector: 'img',
27
+ attribute: 'src',
28
+ },
29
+ alt: {
30
+ type: 'string',
31
+ source: 'attribute',
32
+ selector: 'img',
33
+ attribute: 'alt',
34
+ default: '',
35
+ },
36
+ caption: {
37
+ type: 'array',
38
+ source: 'children',
39
+ selector: 'figcaption',
40
+ },
41
+ href: {
42
+ type: 'string',
43
+ source: 'attribute',
44
+ selector: 'a',
45
+ attribute: 'href',
46
+ },
47
+ id: {
48
+ type: 'number',
49
+ },
50
+ align: {
51
+ type: 'string',
52
+ },
53
+ width: {
54
+ type: 'number',
55
+ },
56
+ height: {
57
+ type: 'number',
58
+ },
59
59
  },
60
- width: {
61
- type: 'number',
60
+ save( { attributes } ) {
61
+ const { url, alt, caption, align, href, width, height } = attributes;
62
+ const extraImageProps = width || height ? { width, height } : {};
63
+ const image = <img src={ url } alt={ alt } { ...extraImageProps } />;
64
+
65
+ let figureStyle = {};
66
+
67
+ if ( width ) {
68
+ figureStyle = { width };
69
+ } else if ( align === 'left' || align === 'right' ) {
70
+ figureStyle = { maxWidth: '50%' };
71
+ }
72
+
73
+ return (
74
+ <figure
75
+ className={ align ? `align${ align }` : null }
76
+ style={ figureStyle }
77
+ >
78
+ { href ? <a href={ href }>{ image }</a> : image }
79
+ { ! RichText.isEmpty( caption ) && (
80
+ <RichText.Content tagName="figcaption" value={ caption } />
81
+ ) }
82
+ </figure>
83
+ );
62
84
  },
63
- height: {
64
- type: 'number',
85
+ };
86
+
87
+ /**
88
+ * Deprecation for adding the `is-resized` class to the image block to fix
89
+ * captions on resized images.
90
+ *
91
+ * @see https://github.com/WordPress/gutenberg/pull/6496
92
+ */
93
+ const v2 = {
94
+ attributes: {
95
+ url: {
96
+ type: 'string',
97
+ source: 'attribute',
98
+ selector: 'img',
99
+ attribute: 'src',
100
+ },
101
+ alt: {
102
+ type: 'string',
103
+ source: 'attribute',
104
+ selector: 'img',
105
+ attribute: 'alt',
106
+ default: '',
107
+ },
108
+ caption: {
109
+ type: 'array',
110
+ source: 'children',
111
+ selector: 'figcaption',
112
+ },
113
+ href: {
114
+ type: 'string',
115
+ source: 'attribute',
116
+ selector: 'a',
117
+ attribute: 'href',
118
+ },
119
+ id: {
120
+ type: 'number',
121
+ },
122
+ align: {
123
+ type: 'string',
124
+ },
125
+ width: {
126
+ type: 'number',
127
+ },
128
+ height: {
129
+ type: 'number',
130
+ },
65
131
  },
66
- sizeSlug: {
67
- type: 'string',
132
+ save( { attributes } ) {
133
+ const { url, alt, caption, align, href, width, height, id } =
134
+ attributes;
135
+
136
+ const image = (
137
+ <img
138
+ src={ url }
139
+ alt={ alt }
140
+ className={ id ? `wp-image-${ id }` : null }
141
+ width={ width }
142
+ height={ height }
143
+ />
144
+ );
145
+
146
+ return (
147
+ <figure className={ align ? `align${ align }` : null }>
148
+ { href ? <a href={ href }>{ image }</a> : image }
149
+ { ! RichText.isEmpty( caption ) && (
150
+ <RichText.Content tagName="figcaption" value={ caption } />
151
+ ) }
152
+ </figure>
153
+ );
68
154
  },
69
- linkDestination: {
70
- type: 'string',
155
+ };
156
+
157
+ /**
158
+ * Deprecation for image floats including a wrapping div.
159
+ *
160
+ * @see https://github.com/WordPress/gutenberg/pull/7721
161
+ */
162
+ const v3 = {
163
+ attributes: {
164
+ url: {
165
+ type: 'string',
166
+ source: 'attribute',
167
+ selector: 'img',
168
+ attribute: 'src',
169
+ },
170
+ alt: {
171
+ type: 'string',
172
+ source: 'attribute',
173
+ selector: 'img',
174
+ attribute: 'alt',
175
+ default: '',
176
+ },
177
+ caption: {
178
+ type: 'array',
179
+ source: 'children',
180
+ selector: 'figcaption',
181
+ },
182
+ href: {
183
+ type: 'string',
184
+ source: 'attribute',
185
+ selector: 'figure > a',
186
+ attribute: 'href',
187
+ },
188
+ id: {
189
+ type: 'number',
190
+ },
191
+ align: {
192
+ type: 'string',
193
+ },
194
+ width: {
195
+ type: 'number',
196
+ },
197
+ height: {
198
+ type: 'number',
199
+ },
200
+ linkDestination: {
201
+ type: 'string',
202
+ default: 'none',
203
+ },
71
204
  },
72
- linkTarget: {
73
- type: 'string',
74
- source: 'attribute',
75
- selector: 'figure > a',
76
- attribute: 'target',
205
+ save( { attributes } ) {
206
+ const { url, alt, caption, align, href, width, height, id } =
207
+ attributes;
208
+
209
+ const classes = classnames( {
210
+ [ `align${ align }` ]: align,
211
+ 'is-resized': width || height,
212
+ } );
213
+
214
+ const image = (
215
+ <img
216
+ src={ url }
217
+ alt={ alt }
218
+ className={ id ? `wp-image-${ id }` : null }
219
+ width={ width }
220
+ height={ height }
221
+ />
222
+ );
223
+
224
+ return (
225
+ <figure className={ classes }>
226
+ { href ? <a href={ href }>{ image }</a> : image }
227
+ { ! RichText.isEmpty( caption ) && (
228
+ <RichText.Content tagName="figcaption" value={ caption } />
229
+ ) }
230
+ </figure>
231
+ );
77
232
  },
78
233
  };
79
234
 
80
- const blockSupports = {
81
- anchor: true,
82
- color: {
83
- __experimentalDuotone: 'img',
84
- text: false,
85
- background: false,
86
- },
87
- __experimentalBorder: {
88
- radius: true,
89
- __experimentalDefaultControls: {
90
- radius: true,
235
+ /**
236
+ * Deprecation for removing the outer div wrapper around aligned images.
237
+ *
238
+ * @see https://github.com/WordPress/gutenberg/pull/38657
239
+ */
240
+ const v4 = {
241
+ attributes: {
242
+ align: {
243
+ type: 'string',
244
+ },
245
+ url: {
246
+ type: 'string',
247
+ source: 'attribute',
248
+ selector: 'img',
249
+ attribute: 'src',
250
+ },
251
+ alt: {
252
+ type: 'string',
253
+ source: 'attribute',
254
+ selector: 'img',
255
+ attribute: 'alt',
256
+ default: '',
257
+ },
258
+ caption: {
259
+ type: 'string',
260
+ source: 'html',
261
+ selector: 'figcaption',
262
+ },
263
+ title: {
264
+ type: 'string',
265
+ source: 'attribute',
266
+ selector: 'img',
267
+ attribute: 'title',
268
+ },
269
+ href: {
270
+ type: 'string',
271
+ source: 'attribute',
272
+ selector: 'figure > a',
273
+ attribute: 'href',
274
+ },
275
+ rel: {
276
+ type: 'string',
277
+ source: 'attribute',
278
+ selector: 'figure > a',
279
+ attribute: 'rel',
280
+ },
281
+ linkClass: {
282
+ type: 'string',
283
+ source: 'attribute',
284
+ selector: 'figure > a',
285
+ attribute: 'class',
286
+ },
287
+ id: {
288
+ type: 'number',
289
+ },
290
+ width: {
291
+ type: 'number',
292
+ },
293
+ height: {
294
+ type: 'number',
295
+ },
296
+ sizeSlug: {
297
+ type: 'string',
298
+ },
299
+ linkDestination: {
300
+ type: 'string',
301
+ },
302
+ linkTarget: {
303
+ type: 'string',
304
+ source: 'attribute',
305
+ selector: 'figure > a',
306
+ attribute: 'target',
91
307
  },
92
308
  },
93
- };
309
+ supports: {
310
+ anchor: true,
311
+ },
312
+ save( { attributes } ) {
313
+ const {
314
+ url,
315
+ alt,
316
+ caption,
317
+ align,
318
+ href,
319
+ rel,
320
+ linkClass,
321
+ width,
322
+ height,
323
+ id,
324
+ linkTarget,
325
+ sizeSlug,
326
+ title,
327
+ } = attributes;
94
328
 
95
- const deprecated = [
96
- // The following deprecation moves existing border radius styles onto the
97
- // inner img element where new border block support styles must be applied.
98
- // It will also add a new `.has-custom-border` class for existing blocks
99
- // with border radii set. This class is required to improve caption position
100
- // and styling when an image within a gallery has a custom border or
101
- // rounded corners.
102
- //
103
- // See: https://github.com/WordPress/gutenberg/pull/31366/
104
- {
105
- attributes: blockAttributes,
106
- supports: blockSupports,
107
- save( { attributes } ) {
108
- const {
109
- url,
110
- alt,
111
- caption,
112
- align,
113
- href,
114
- rel,
115
- linkClass,
116
- width,
117
- height,
118
- id,
119
- linkTarget,
120
- sizeSlug,
121
- title,
122
- } = attributes;
123
-
124
- const newRel = ! rel ? undefined : rel;
125
-
126
- const classes = classnames( {
127
- [ `align${ align }` ]: align,
128
- [ `size-${ sizeSlug }` ]: sizeSlug,
129
- 'is-resized': width || height,
130
- } );
131
-
132
- const image = (
133
- <img
134
- src={ url }
135
- alt={ alt }
136
- className={ id ? `wp-image-${ id }` : null }
137
- width={ width }
138
- height={ height }
139
- title={ title }
140
- />
141
- );
329
+ const newRel = ! rel ? undefined : rel;
142
330
 
143
- const figure = (
144
- <>
145
- { href ? (
146
- <a
147
- className={ linkClass }
148
- href={ href }
149
- target={ linkTarget }
150
- rel={ newRel }
151
- >
152
- { image }
153
- </a>
154
- ) : (
155
- image
156
- ) }
157
- { ! RichText.isEmpty( caption ) && (
158
- <RichText.Content
159
- tagName="figcaption"
160
- value={ caption }
161
- />
162
- ) }
163
- </>
164
- );
331
+ const classes = classnames( {
332
+ [ `align${ align }` ]: align,
333
+ [ `size-${ sizeSlug }` ]: sizeSlug,
334
+ 'is-resized': width || height,
335
+ } );
336
+
337
+ const image = (
338
+ <img
339
+ src={ url }
340
+ alt={ alt }
341
+ className={ id ? `wp-image-${ id }` : null }
342
+ width={ width }
343
+ height={ height }
344
+ title={ title }
345
+ />
346
+ );
347
+
348
+ const figure = (
349
+ <>
350
+ { href ? (
351
+ <a
352
+ className={ linkClass }
353
+ href={ href }
354
+ target={ linkTarget }
355
+ rel={ newRel }
356
+ >
357
+ { image }
358
+ </a>
359
+ ) : (
360
+ image
361
+ ) }
362
+ { ! RichText.isEmpty( caption ) && (
363
+ <RichText.Content tagName="figcaption" value={ caption } />
364
+ ) }
365
+ </>
366
+ );
165
367
 
368
+ if ( 'left' === align || 'right' === align || 'center' === align ) {
166
369
  return (
167
- <figure { ...useBlockProps.save( { className: classes } ) }>
168
- { figure }
169
- </figure>
370
+ <div { ...useBlockProps.save() }>
371
+ <figure className={ classes }>{ figure }</figure>
372
+ </div>
170
373
  );
374
+ }
375
+
376
+ return (
377
+ <figure { ...useBlockProps.save( { className: classes } ) }>
378
+ { figure }
379
+ </figure>
380
+ );
381
+ },
382
+ };
383
+
384
+ /**
385
+ * Deprecation for moving existing border radius styles onto the inner img
386
+ * element where new border block support styles must be applied.
387
+ * It will also add a new `.has-custom-border` class for existing blocks
388
+ * with border radii set. This class is required to improve caption position
389
+ * and styling when an image within a gallery has a custom border or
390
+ * rounded corners.
391
+ *
392
+ * @see https://github.com/WordPress/gutenberg/pull/31366
393
+ */
394
+ const v5 = {
395
+ attributes: {
396
+ align: {
397
+ type: 'string',
398
+ },
399
+ url: {
400
+ type: 'string',
401
+ source: 'attribute',
402
+ selector: 'img',
403
+ attribute: 'src',
404
+ },
405
+ alt: {
406
+ type: 'string',
407
+ source: 'attribute',
408
+ selector: 'img',
409
+ attribute: 'alt',
410
+ default: '',
411
+ },
412
+ caption: {
413
+ type: 'string',
414
+ source: 'html',
415
+ selector: 'figcaption',
416
+ },
417
+ title: {
418
+ type: 'string',
419
+ source: 'attribute',
420
+ selector: 'img',
421
+ attribute: 'title',
422
+ },
423
+ href: {
424
+ type: 'string',
425
+ source: 'attribute',
426
+ selector: 'figure > a',
427
+ attribute: 'href',
428
+ },
429
+ rel: {
430
+ type: 'string',
431
+ source: 'attribute',
432
+ selector: 'figure > a',
433
+ attribute: 'rel',
434
+ },
435
+ linkClass: {
436
+ type: 'string',
437
+ source: 'attribute',
438
+ selector: 'figure > a',
439
+ attribute: 'class',
440
+ },
441
+ id: {
442
+ type: 'number',
443
+ },
444
+ width: {
445
+ type: 'number',
446
+ },
447
+ height: {
448
+ type: 'number',
449
+ },
450
+ sizeSlug: {
451
+ type: 'string',
452
+ },
453
+ linkDestination: {
454
+ type: 'string',
455
+ },
456
+ linkTarget: {
457
+ type: 'string',
458
+ source: 'attribute',
459
+ selector: 'figure > a',
460
+ attribute: 'target',
171
461
  },
172
462
  },
173
- {
174
- attributes: {
175
- ...blockAttributes,
176
- title: {
177
- type: 'string',
178
- source: 'attribute',
179
- selector: 'img',
180
- attribute: 'title',
463
+ supports: {
464
+ anchor: true,
465
+ color: {
466
+ __experimentalDuotone: 'img',
467
+ text: false,
468
+ background: false,
469
+ },
470
+ __experimentalBorder: {
471
+ radius: true,
472
+ __experimentalDefaultControls: {
473
+ radius: true,
181
474
  },
182
- sizeSlug: {
183
- type: 'string',
475
+ },
476
+ __experimentalStyle: {
477
+ spacing: {
478
+ margin: '0 0 1em 0',
184
479
  },
185
480
  },
186
- supports: blockSupports,
187
- save( { attributes } ) {
188
- const {
189
- url,
190
- alt,
191
- caption,
192
- align,
193
- href,
194
- rel,
195
- linkClass,
196
- width,
197
- height,
198
- id,
199
- linkTarget,
200
- sizeSlug,
201
- title,
202
- } = attributes;
203
-
204
- const newRel = ! rel ? undefined : rel;
205
-
206
- const classes = classnames( {
207
- [ `align${ align }` ]: align,
208
- [ `size-${ sizeSlug }` ]: sizeSlug,
209
- 'is-resized': width || height,
210
- } );
211
-
212
- const image = (
213
- <img
214
- src={ url }
215
- alt={ alt }
216
- className={ id ? `wp-image-${ id }` : null }
217
- width={ width }
218
- height={ height }
219
- title={ title }
220
- />
221
- );
481
+ },
482
+ save( { attributes } ) {
483
+ const {
484
+ url,
485
+ alt,
486
+ caption,
487
+ align,
488
+ href,
489
+ rel,
490
+ linkClass,
491
+ width,
492
+ height,
493
+ id,
494
+ linkTarget,
495
+ sizeSlug,
496
+ title,
497
+ } = attributes;
222
498
 
223
- const figure = (
224
- <>
225
- { href ? (
226
- <a
227
- className={ linkClass }
228
- href={ href }
229
- target={ linkTarget }
230
- rel={ newRel }
231
- >
232
- { image }
233
- </a>
234
- ) : (
235
- image
236
- ) }
237
- { ! RichText.isEmpty( caption ) && (
238
- <RichText.Content
239
- tagName="figcaption"
240
- value={ caption }
241
- />
242
- ) }
243
- </>
244
- );
499
+ const newRel = ! rel ? undefined : rel;
245
500
 
246
- if ( 'left' === align || 'right' === align || 'center' === align ) {
247
- return (
248
- <div { ...useBlockProps.save() }>
249
- <figure className={ classes }>{ figure }</figure>
250
- </div>
251
- );
252
- }
501
+ const classes = classnames( {
502
+ [ `align${ align }` ]: align,
503
+ [ `size-${ sizeSlug }` ]: sizeSlug,
504
+ 'is-resized': width || height,
505
+ } );
253
506
 
254
- return (
255
- <figure { ...useBlockProps.save( { className: classes } ) }>
256
- { figure }
257
- </figure>
258
- );
259
- },
260
- },
261
- {
262
- attributes: blockAttributes,
263
- save( { attributes } ) {
264
- const { url, alt, caption, align, href, width, height, id } =
265
- attributes;
266
-
267
- const classes = classnames( {
268
- [ `align${ align }` ]: align,
269
- 'is-resized': width || height,
270
- } );
271
-
272
- const image = (
273
- <img
274
- src={ url }
275
- alt={ alt }
276
- className={ id ? `wp-image-${ id }` : null }
277
- width={ width }
278
- height={ height }
279
- />
280
- );
507
+ const image = (
508
+ <img
509
+ src={ url }
510
+ alt={ alt }
511
+ className={ id ? `wp-image-${ id }` : null }
512
+ width={ width }
513
+ height={ height }
514
+ title={ title }
515
+ />
516
+ );
281
517
 
282
- return (
283
- <figure className={ classes }>
284
- { href ? <a href={ href }>{ image }</a> : image }
285
- { ! RichText.isEmpty( caption ) && (
286
- <RichText.Content
287
- tagName="figcaption"
288
- value={ caption }
289
- />
290
- ) }
291
- </figure>
292
- );
293
- },
294
- },
295
- {
296
- attributes: blockAttributes,
297
- save( { attributes } ) {
298
- const { url, alt, caption, align, href, width, height, id } =
299
- attributes;
300
-
301
- const image = (
302
- <img
303
- src={ url }
304
- alt={ alt }
305
- className={ id ? `wp-image-${ id }` : null }
306
- width={ width }
307
- height={ height }
308
- />
309
- );
518
+ const figure = (
519
+ <>
520
+ { href ? (
521
+ <a
522
+ className={ linkClass }
523
+ href={ href }
524
+ target={ linkTarget }
525
+ rel={ newRel }
526
+ >
527
+ { image }
528
+ </a>
529
+ ) : (
530
+ image
531
+ ) }
532
+ { ! RichText.isEmpty( caption ) && (
533
+ <RichText.Content tagName="figcaption" value={ caption } />
534
+ ) }
535
+ </>
536
+ );
310
537
 
311
- return (
312
- <figure className={ align ? `align${ align }` : null }>
313
- { href ? <a href={ href }>{ image }</a> : image }
314
- { ! RichText.isEmpty( caption ) && (
315
- <RichText.Content
316
- tagName="figcaption"
317
- value={ caption }
318
- />
319
- ) }
320
- </figure>
321
- );
322
- },
538
+ return (
539
+ <figure { ...useBlockProps.save( { className: classes } ) }>
540
+ { figure }
541
+ </figure>
542
+ );
323
543
  },
324
- {
325
- attributes: blockAttributes,
326
- save( { attributes } ) {
327
- const { url, alt, caption, align, href, width, height } =
328
- attributes;
329
- const extraImageProps = width || height ? { width, height } : {};
330
- const image = (
331
- <img src={ url } alt={ alt } { ...extraImageProps } />
332
- );
544
+ };
333
545
 
334
- let figureStyle = {};
546
+ /**
547
+ * Deprecation for adding width and height as style rules on the inner img.
548
+ * It also updates the widht and height attributes to be strings instead of numbers.
549
+ *
550
+ * @see https://github.com/WordPress/gutenberg/pull/31366
551
+ */
552
+ const v6 = {
553
+ save( { attributes } ) {
554
+ const {
555
+ url,
556
+ alt,
557
+ caption,
558
+ align,
559
+ href,
560
+ rel,
561
+ linkClass,
562
+ width,
563
+ height,
564
+ aspectRatio,
565
+ scale,
566
+ id,
567
+ linkTarget,
568
+ sizeSlug,
569
+ title,
570
+ } = attributes;
335
571
 
336
- if ( width ) {
337
- figureStyle = { width };
338
- } else if ( align === 'left' || align === 'right' ) {
339
- figureStyle = { maxWidth: '50%' };
340
- }
572
+ const newRel = ! rel ? undefined : rel;
573
+ const borderProps = getBorderClassesAndStyles( attributes );
341
574
 
342
- return (
343
- <figure
344
- className={ align ? `align${ align }` : null }
345
- style={ figureStyle }
346
- >
347
- { href ? <a href={ href }>{ image }</a> : image }
348
- { ! RichText.isEmpty( caption ) && (
349
- <RichText.Content
350
- tagName="figcaption"
351
- value={ caption }
352
- />
353
- ) }
354
- </figure>
355
- );
356
- },
575
+ const classes = classnames( {
576
+ [ `align${ align }` ]: align,
577
+ [ `size-${ sizeSlug }` ]: sizeSlug,
578
+ 'is-resized': width || height,
579
+ 'has-custom-border':
580
+ !! borderProps.className ||
581
+ ( borderProps.style &&
582
+ Object.keys( borderProps.style ).length > 0 ),
583
+ } );
584
+
585
+ const imageClasses = classnames( borderProps.className, {
586
+ [ `wp-image-${ id }` ]: !! id,
587
+ } );
588
+
589
+ const image = (
590
+ <img
591
+ src={ url }
592
+ alt={ alt }
593
+ className={ imageClasses || undefined }
594
+ style={ {
595
+ ...borderProps.style,
596
+ aspectRatio,
597
+ objectFit: scale,
598
+ } }
599
+ width={ width }
600
+ height={ height }
601
+ title={ title }
602
+ />
603
+ );
604
+
605
+ const figure = (
606
+ <>
607
+ { href ? (
608
+ <a
609
+ className={ linkClass }
610
+ href={ href }
611
+ target={ linkTarget }
612
+ rel={ newRel }
613
+ >
614
+ { image }
615
+ </a>
616
+ ) : (
617
+ image
618
+ ) }
619
+ { ! RichText.isEmpty( caption ) && (
620
+ <RichText.Content
621
+ className={ getBorderClassesAndStyles( 'caption' ) }
622
+ tagName="figcaption"
623
+ value={ caption }
624
+ />
625
+ ) }
626
+ </>
627
+ );
628
+
629
+ return (
630
+ <figure { ...useBlockProps.save( { className: classes } ) }>
631
+ { figure }
632
+ </figure>
633
+ );
357
634
  },
358
- ];
635
+ };
359
636
 
360
- export default deprecated;
637
+ export default [ v6, v5, v4, v3, v2, v1 ];