@wordpress/block-library 6.0.8 → 6.0.12

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 (214) hide show
  1. package/build/cover/edit.js +9 -3
  2. package/build/cover/edit.js.map +1 -1
  3. package/build/gallery/deprecated.js +314 -26
  4. package/build/gallery/deprecated.js.map +1 -1
  5. package/build/gallery/edit-wrapper.js +10 -27
  6. package/build/gallery/edit-wrapper.js.map +1 -1
  7. package/build/gallery/edit.js +11 -13
  8. package/build/gallery/edit.js.map +1 -1
  9. package/build/gallery/save.js +3 -3
  10. package/build/gallery/save.js.map +1 -1
  11. package/build/gallery/shared.js +24 -0
  12. package/build/gallery/shared.js.map +1 -1
  13. package/build/gallery/transforms.js +8 -22
  14. package/build/gallery/transforms.js.map +1 -1
  15. package/build/gallery/use-mobile-warning.js +1 -1
  16. package/build/gallery/use-mobile-warning.js.map +1 -1
  17. package/build/gallery/v1/edit.js +2 -21
  18. package/build/gallery/v1/edit.js.map +1 -1
  19. package/build/index.js +4 -3
  20. package/build/index.js.map +1 -1
  21. package/build/navigation/deprecated.js +127 -19
  22. package/build/navigation/deprecated.js.map +1 -1
  23. package/build/navigation/edit/index.js +46 -31
  24. package/build/navigation/edit/index.js.map +1 -1
  25. package/build/navigation/edit/inner-blocks.js +0 -4
  26. package/build/navigation/edit/inner-blocks.js.map +1 -1
  27. package/build/navigation/edit/navigation-menu-selector.js +2 -2
  28. package/build/navigation/edit/navigation-menu-selector.js.map +1 -1
  29. package/build/navigation/edit/placeholder/index.js +16 -48
  30. package/build/navigation/edit/placeholder/index.js.map +1 -1
  31. package/build/navigation/edit/unsaved-inner-blocks.js +4 -35
  32. package/build/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  33. package/build/navigation/edit/use-create-navigation-menu.js +50 -0
  34. package/build/navigation/edit/use-create-navigation-menu.js.map +1 -0
  35. package/build/navigation/edit/use-generate-default-navigation-title.js +73 -0
  36. package/build/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
  37. package/build/navigation/index.js +1 -1
  38. package/build/navigation/save.js +2 -2
  39. package/build/navigation/save.js.map +1 -1
  40. package/build/navigation/use-navigation-menu.js +19 -8
  41. package/build/navigation/use-navigation-menu.js.map +1 -1
  42. package/build/navigation-area/edit.js +5 -0
  43. package/build/navigation-area/edit.js.map +1 -1
  44. package/build/navigation-submenu/edit.js +4 -0
  45. package/build/navigation-submenu/edit.js.map +1 -1
  46. package/build/pattern/index.js +1 -1
  47. package/build/post-featured-image/edit.js +2 -3
  48. package/build/post-featured-image/edit.js.map +1 -1
  49. package/build/post-terms/index.js +1 -1
  50. package/build/post-title/edit.js +2 -2
  51. package/build/post-title/edit.js.map +1 -1
  52. package/build/query-pagination/index.js +1 -1
  53. package/build/query-pagination-next/index.js +2 -2
  54. package/build/query-pagination-numbers/index.js +1 -1
  55. package/build/query-pagination-previous/index.js +2 -2
  56. package/build/query-title/index.js +1 -1
  57. package/build/separator/separator-settings.js +1 -0
  58. package/build/separator/separator-settings.js.map +1 -1
  59. package/build/site-logo/index.js +1 -1
  60. package/build/site-tagline/index.js +1 -1
  61. package/build/site-title/index.js +1 -1
  62. package/build/social-links/edit.js +1 -0
  63. package/build/social-links/edit.js.map +1 -1
  64. package/build/template-part/edit/placeholder/index.js +1 -1
  65. package/build/template-part/edit/placeholder/index.js.map +1 -1
  66. package/build/template-part/index.js +2 -1
  67. package/build/template-part/index.js.map +1 -1
  68. package/build-module/cover/edit.js +9 -3
  69. package/build-module/cover/edit.js.map +1 -1
  70. package/build-module/gallery/deprecated.js +309 -27
  71. package/build-module/gallery/deprecated.js.map +1 -1
  72. package/build-module/gallery/edit-wrapper.js +7 -27
  73. package/build-module/gallery/edit-wrapper.js.map +1 -1
  74. package/build-module/gallery/edit.js +11 -13
  75. package/build-module/gallery/edit.js.map +1 -1
  76. package/build-module/gallery/save.js +2 -3
  77. package/build-module/gallery/save.js.map +1 -1
  78. package/build-module/gallery/shared.js +22 -0
  79. package/build-module/gallery/shared.js.map +1 -1
  80. package/build-module/gallery/transforms.js +9 -21
  81. package/build-module/gallery/transforms.js.map +1 -1
  82. package/build-module/gallery/use-mobile-warning.js +1 -1
  83. package/build-module/gallery/use-mobile-warning.js.map +1 -1
  84. package/build-module/gallery/v1/edit.js +4 -22
  85. package/build-module/gallery/v1/edit.js.map +1 -1
  86. package/build-module/index.js +4 -3
  87. package/build-module/index.js.map +1 -1
  88. package/build-module/navigation/deprecated.js +127 -19
  89. package/build-module/navigation/deprecated.js.map +1 -1
  90. package/build-module/navigation/edit/index.js +47 -31
  91. package/build-module/navigation/edit/index.js.map +1 -1
  92. package/build-module/navigation/edit/inner-blocks.js +0 -4
  93. package/build-module/navigation/edit/inner-blocks.js.map +1 -1
  94. package/build-module/navigation/edit/navigation-menu-selector.js +2 -2
  95. package/build-module/navigation/edit/navigation-menu-selector.js.map +1 -1
  96. package/build-module/navigation/edit/placeholder/index.js +15 -45
  97. package/build-module/navigation/edit/placeholder/index.js.map +1 -1
  98. package/build-module/navigation/edit/unsaved-inner-blocks.js +6 -35
  99. package/build-module/navigation/edit/unsaved-inner-blocks.js.map +1 -1
  100. package/build-module/navigation/edit/use-create-navigation-menu.js +36 -0
  101. package/build-module/navigation/edit/use-create-navigation-menu.js.map +1 -0
  102. package/build-module/navigation/edit/use-generate-default-navigation-title.js +57 -0
  103. package/build-module/navigation/edit/use-generate-default-navigation-title.js.map +1 -0
  104. package/build-module/navigation/index.js +1 -1
  105. package/build-module/navigation/save.js +2 -2
  106. package/build-module/navigation/save.js.map +1 -1
  107. package/build-module/navigation/use-navigation-menu.js +19 -8
  108. package/build-module/navigation/use-navigation-menu.js.map +1 -1
  109. package/build-module/navigation-area/edit.js +4 -0
  110. package/build-module/navigation-area/edit.js.map +1 -1
  111. package/build-module/navigation-submenu/edit.js +4 -0
  112. package/build-module/navigation-submenu/edit.js.map +1 -1
  113. package/build-module/pattern/index.js +1 -1
  114. package/build-module/post-featured-image/edit.js +2 -3
  115. package/build-module/post-featured-image/edit.js.map +1 -1
  116. package/build-module/post-terms/index.js +1 -1
  117. package/build-module/post-title/edit.js +2 -2
  118. package/build-module/post-title/edit.js.map +1 -1
  119. package/build-module/query-pagination/index.js +1 -1
  120. package/build-module/query-pagination-next/index.js +2 -2
  121. package/build-module/query-pagination-numbers/index.js +1 -1
  122. package/build-module/query-pagination-previous/index.js +2 -2
  123. package/build-module/query-title/index.js +1 -1
  124. package/build-module/separator/separator-settings.js +1 -0
  125. package/build-module/separator/separator-settings.js.map +1 -1
  126. package/build-module/site-logo/index.js +1 -1
  127. package/build-module/site-tagline/index.js +1 -1
  128. package/build-module/site-title/index.js +1 -1
  129. package/build-module/social-links/edit.js +1 -0
  130. package/build-module/social-links/edit.js.map +1 -1
  131. package/build-module/template-part/edit/placeholder/index.js +2 -2
  132. package/build-module/template-part/edit/placeholder/index.js.map +1 -1
  133. package/build-module/template-part/index.js +2 -1
  134. package/build-module/template-part/index.js.map +1 -1
  135. package/build-style/columns/editor-rtl.css +1 -1
  136. package/build-style/columns/editor.css +1 -1
  137. package/build-style/editor-rtl.css +6 -5
  138. package/build-style/editor.css +6 -5
  139. package/build-style/gallery/editor-rtl.css +1 -0
  140. package/build-style/gallery/editor.css +1 -0
  141. package/build-style/navigation/style-rtl.css +12 -3
  142. package/build-style/navigation/style.css +12 -3
  143. package/build-style/post-featured-image/editor-rtl.css +2 -2
  144. package/build-style/post-featured-image/editor.css +2 -2
  145. package/build-style/site-logo/editor-rtl.css +2 -2
  146. package/build-style/site-logo/editor.css +2 -2
  147. package/build-style/style-rtl.css +12 -3
  148. package/build-style/style.css +12 -3
  149. package/package.json +9 -9
  150. package/src/calendar/index.php +2 -2
  151. package/src/columns/editor.scss +3 -2
  152. package/src/cover/edit.js +9 -1
  153. package/src/gallery/deprecated.js +831 -559
  154. package/src/gallery/edit-wrapper.js +7 -27
  155. package/src/gallery/edit.js +11 -13
  156. package/src/gallery/editor.scss +1 -0
  157. package/src/gallery/save.js +2 -1
  158. package/src/gallery/shared.js +24 -0
  159. package/src/gallery/transforms.js +9 -27
  160. package/src/gallery/use-mobile-warning.js +1 -1
  161. package/src/gallery/v1/edit.js +1 -28
  162. package/src/index.js +28 -26
  163. package/src/navigation/block.json +1 -1
  164. package/src/navigation/deprecated.js +115 -13
  165. package/src/navigation/edit/index.js +44 -36
  166. package/src/navigation/edit/inner-blocks.js +0 -5
  167. package/src/navigation/edit/navigation-menu-selector.js +2 -2
  168. package/src/navigation/edit/placeholder/index.js +16 -62
  169. package/src/navigation/edit/unsaved-inner-blocks.js +6 -57
  170. package/src/navigation/edit/use-create-navigation-menu.js +39 -0
  171. package/src/navigation/edit/use-generate-default-navigation-title.js +79 -0
  172. package/src/navigation/index.php +263 -26
  173. package/src/navigation/save.js +2 -2
  174. package/src/navigation/style.scss +15 -4
  175. package/src/navigation/use-navigation-menu.js +20 -9
  176. package/src/navigation-area/edit.js +5 -0
  177. package/src/navigation-area/index.php +1 -0
  178. package/src/navigation-submenu/edit.js +6 -0
  179. package/src/navigation-submenu/index.php +30 -45
  180. package/src/page-list/index.php +14 -13
  181. package/src/pattern/block.json +1 -1
  182. package/src/post-featured-image/edit.js +2 -5
  183. package/src/post-featured-image/editor.scss +2 -2
  184. package/src/post-terms/block.json +1 -1
  185. package/src/post-title/edit.js +2 -2
  186. package/src/query-pagination/block.json +1 -1
  187. package/src/query-pagination-next/block.json +2 -2
  188. package/src/query-pagination-numbers/block.json +1 -1
  189. package/src/query-pagination-previous/block.json +2 -2
  190. package/src/query-title/block.json +1 -1
  191. package/src/separator/separator-settings.js +1 -0
  192. package/src/site-logo/block.json +1 -1
  193. package/src/site-logo/editor.scss +2 -2
  194. package/src/site-tagline/block.json +1 -1
  195. package/src/site-title/block.json +1 -1
  196. package/src/social-links/edit.js +1 -0
  197. package/src/template-part/block.json +2 -1
  198. package/src/template-part/edit/placeholder/index.js +2 -2
  199. package/src/template-part/index.php +38 -1
  200. package/build/gallery/v1/update-gallery-modal.js +0 -114
  201. package/build/gallery/v1/update-gallery-modal.js.map +0 -1
  202. package/build/navigation/edit/navigation-menu-name-modal.js +0 -55
  203. package/build/navigation/edit/navigation-menu-name-modal.js.map +0 -1
  204. package/build/navigation/edit/navigation-menu-publish-button.js +0 -53
  205. package/build/navigation/edit/navigation-menu-publish-button.js.map +0 -1
  206. package/build-module/gallery/v1/update-gallery-modal.js +0 -97
  207. package/build-module/gallery/v1/update-gallery-modal.js.map +0 -1
  208. package/build-module/navigation/edit/navigation-menu-name-modal.js +0 -47
  209. package/build-module/navigation/edit/navigation-menu-name-modal.js.map +0 -1
  210. package/build-module/navigation/edit/navigation-menu-publish-button.js +0 -40
  211. package/build-module/navigation/edit/navigation-menu-publish-button.js.map +0 -1
  212. package/src/gallery/v1/update-gallery-modal.js +0 -97
  213. package/src/navigation/edit/navigation-menu-name-modal.js +0 -69
  214. package/src/navigation/edit/navigation-menu-publish-button.js +0 -57
@@ -7,7 +7,22 @@ import { map, some } from 'lodash';
7
7
  /**
8
8
  * WordPress dependencies
9
9
  */
10
- import { RichText } from '@wordpress/block-editor';
10
+ import { RichText, useBlockProps } from '@wordpress/block-editor';
11
+
12
+ import { createBlock } from '@wordpress/blocks';
13
+
14
+ /**
15
+ * Internal dependencies
16
+ */
17
+ import {
18
+ LINK_DESTINATION_ATTACHMENT,
19
+ LINK_DESTINATION_MEDIA,
20
+ LINK_DESTINATION_NONE,
21
+ } from './constants';
22
+ import { isGalleryV2Enabled } from './shared';
23
+
24
+ const DEPRECATED_LINK_DESTINATION_MEDIA = 'file';
25
+ const DEPRECATED_LINK_DESTINATION_ATTACHMENT = 'post';
11
26
 
12
27
  /**
13
28
  * Original function to determine default number of columns from a block's
@@ -19,422 +34,202 @@ import { RichText } from '@wordpress/block-editor';
19
34
  * @return {number} Default number of columns for the gallery.
20
35
  */
21
36
  export function defaultColumnsNumberV1( attributes ) {
22
- return Math.min( 3, attributes.images.length );
37
+ return Math.min( 3, attributes?.images?.length );
23
38
  }
24
39
 
25
- const deprecated = [
26
- {
27
- attributes: {
28
- images: {
29
- type: 'array',
30
- default: [],
31
- source: 'query',
32
- selector: '.blocks-gallery-item',
33
- query: {
34
- url: {
35
- type: 'string',
36
- source: 'attribute',
37
- selector: 'img',
38
- attribute: 'src',
39
- },
40
- fullUrl: {
41
- type: 'string',
42
- source: 'attribute',
43
- selector: 'img',
44
- attribute: 'data-full-url',
45
- },
46
- link: {
47
- type: 'string',
48
- source: 'attribute',
49
- selector: 'img',
50
- attribute: 'data-link',
51
- },
52
- alt: {
53
- type: 'string',
54
- source: 'attribute',
55
- selector: 'img',
56
- attribute: 'alt',
57
- default: '',
58
- },
59
- id: {
60
- type: 'string',
61
- source: 'attribute',
62
- selector: 'img',
63
- attribute: 'data-id',
64
- },
65
- caption: {
66
- type: 'string',
67
- source: 'html',
68
- selector: '.blocks-gallery-item__caption',
69
- },
70
- },
71
- },
72
- ids: {
73
- type: 'array',
74
- items: {
75
- type: 'number',
76
- },
77
- default: [],
78
- },
79
- columns: {
80
- type: 'number',
81
- minimum: 1,
82
- maximum: 8,
83
- },
84
- caption: {
85
- type: 'string',
86
- source: 'html',
87
- selector: '.blocks-gallery-caption',
88
- },
89
- imageCrop: {
90
- type: 'boolean',
91
- default: true,
92
- },
93
- linkTo: {
94
- type: 'string',
95
- default: 'none',
96
- },
97
- sizeSlug: {
98
- type: 'string',
99
- default: 'large',
100
- },
101
- },
102
- supports: {
103
- align: true,
104
- },
105
- isEligible( { linkTo } ) {
106
- return ! linkTo || linkTo === 'attachment' || linkTo === 'media';
107
- },
108
- migrate( attributes ) {
109
- let linkTo = attributes.linkTo;
110
- if ( ! attributes.linkTo ) {
111
- linkTo = 'none';
112
- } else if ( attributes.linkTo === 'attachment' ) {
113
- linkTo = 'post';
114
- } else if ( attributes.linkTo === 'media' ) {
115
- linkTo = 'file';
116
- }
40
+ /**
41
+ * Original function to determine new href and linkDestination values for an image block from the
42
+ * supplied Gallery link destination.
43
+ *
44
+ * Used in deprecations: v1-6.
45
+ *
46
+ * @param {Object} image Gallery image.
47
+ * @param {string} destination Gallery's selected link destination.
48
+ * @return {Object} New attributes to assign to image block.
49
+ */
50
+ export function getHrefAndDestination( image, destination ) {
51
+ // Need to determine the URL that the selected destination maps to.
52
+ // Gutenberg and WordPress use different constants so the new link
53
+ // destination also needs to be tweaked.
54
+ switch ( destination ) {
55
+ case DEPRECATED_LINK_DESTINATION_MEDIA:
117
56
  return {
118
- ...attributes,
119
- linkTo,
57
+ href: image?.source_url || image?.url, // eslint-disable-line camelcase
58
+ linkDestination: LINK_DESTINATION_MEDIA,
120
59
  };
121
- },
122
- save( { attributes } ) {
123
- const {
124
- images,
125
- columns = defaultColumnsNumberV1( attributes ),
126
- imageCrop,
127
- caption,
128
- linkTo,
129
- } = attributes;
130
-
131
- return (
132
- <figure
133
- className={ `columns-${ columns } ${
134
- imageCrop ? 'is-cropped' : ''
135
- }` }
136
- >
137
- <ul className="blocks-gallery-grid">
138
- { images.map( ( image ) => {
139
- let href;
140
-
141
- switch ( linkTo ) {
142
- case 'media':
143
- href = image.fullUrl || image.url;
144
- break;
145
- case 'attachment':
146
- href = image.link;
147
- break;
148
- }
60
+ case DEPRECATED_LINK_DESTINATION_ATTACHMENT:
61
+ return {
62
+ href: image?.link,
63
+ linkDestination: LINK_DESTINATION_ATTACHMENT,
64
+ };
65
+ case LINK_DESTINATION_MEDIA:
66
+ return {
67
+ href: image?.source_url || image?.url, // eslint-disable-line camelcase
68
+ linkDestination: LINK_DESTINATION_MEDIA,
69
+ };
70
+ case LINK_DESTINATION_ATTACHMENT:
71
+ return {
72
+ href: image?.link,
73
+ linkDestination: LINK_DESTINATION_ATTACHMENT,
74
+ };
75
+ case LINK_DESTINATION_NONE:
76
+ return {
77
+ href: undefined,
78
+ linkDestination: LINK_DESTINATION_NONE,
79
+ };
80
+ }
149
81
 
150
- const img = (
151
- <img
152
- src={ image.url }
153
- alt={ image.alt }
154
- data-id={ image.id }
155
- data-full-url={ image.fullUrl }
156
- data-link={ image.link }
157
- className={
158
- image.id
159
- ? `wp-image-${ image.id }`
160
- : null
161
- }
162
- />
163
- );
164
-
165
- return (
166
- <li
167
- key={ image.id || image.url }
168
- className="blocks-gallery-item"
169
- >
170
- <figure>
171
- { href ? (
172
- <a href={ href }>{ img }</a>
173
- ) : (
174
- img
175
- ) }
176
- { ! RichText.isEmpty(
177
- image.caption
178
- ) && (
179
- <RichText.Content
180
- tagName="figcaption"
181
- className="blocks-gallery-item__caption"
182
- value={ image.caption }
183
- />
184
- ) }
185
- </figure>
186
- </li>
187
- );
188
- } ) }
189
- </ul>
190
- { ! RichText.isEmpty( caption ) && (
191
- <RichText.Content
192
- tagName="figcaption"
193
- className="blocks-gallery-caption"
194
- value={ caption }
195
- />
196
- ) }
197
- </figure>
198
- );
82
+ return {};
83
+ }
84
+
85
+ function runV2Migration( attributes ) {
86
+ let linkTo = attributes.linkTo ? attributes.linkTo : 'none';
87
+
88
+ if ( linkTo === 'post' ) {
89
+ linkTo = 'attachment';
90
+ } else if ( linkTo === 'file' ) {
91
+ linkTo = 'media';
92
+ }
93
+
94
+ const imageBlocks = attributes.images.map( ( image ) => {
95
+ return getImageBlock( image, attributes.sizeSlug, linkTo );
96
+ } );
97
+
98
+ return [
99
+ {
100
+ caption: attributes.caption,
101
+ columns: attributes.columns,
102
+ imageCrop: attributes.imageCrop,
103
+ linkTo,
104
+ sizeSlug: attributes.sizeSlug,
105
+ allowResize: false,
199
106
  },
200
- },
201
- {
202
- attributes: {
203
- images: {
204
- type: 'array',
205
- default: [],
206
- source: 'query',
207
- selector: '.blocks-gallery-item',
208
- query: {
209
- url: {
210
- source: 'attribute',
211
- selector: 'img',
212
- attribute: 'src',
213
- },
214
- fullUrl: {
215
- source: 'attribute',
216
- selector: 'img',
217
- attribute: 'data-full-url',
218
- },
219
- link: {
220
- source: 'attribute',
221
- selector: 'img',
222
- attribute: 'data-link',
223
- },
224
- alt: {
225
- source: 'attribute',
226
- selector: 'img',
227
- attribute: 'alt',
228
- default: '',
229
- },
230
- id: {
231
- source: 'attribute',
232
- selector: 'img',
233
- attribute: 'data-id',
234
- },
235
- caption: {
236
- type: 'string',
237
- source: 'html',
238
- selector: '.blocks-gallery-item__caption',
239
- },
107
+ imageBlocks,
108
+ ];
109
+ }
110
+ /**
111
+ * Gets an Image block from gallery image data
112
+ *
113
+ * Used to migrate Galleries to nested Image InnerBlocks.
114
+ *
115
+ * @param {Object} image Image properties.
116
+ * @param {string} sizeSlug Gallery sizeSlug attribute.
117
+ * @param {string} linkTo Gallery linkTo attribute.
118
+ * @return {Object} Image block.
119
+ */
120
+ export function getImageBlock( image, sizeSlug, linkTo ) {
121
+ return createBlock( 'core/image', {
122
+ ...( image.id && { id: parseInt( image.id ) } ),
123
+ url: image.url,
124
+ alt: image.alt,
125
+ caption: image.caption,
126
+ sizeSlug,
127
+ ...getHrefAndDestination( image, linkTo ),
128
+ } );
129
+ }
130
+
131
+ const v6 = {
132
+ attributes: {
133
+ images: {
134
+ type: 'array',
135
+ default: [],
136
+ source: 'query',
137
+ selector: '.blocks-gallery-item',
138
+ query: {
139
+ url: {
140
+ type: 'string',
141
+ source: 'attribute',
142
+ selector: 'img',
143
+ attribute: 'src',
144
+ },
145
+ fullUrl: {
146
+ type: 'string',
147
+ source: 'attribute',
148
+ selector: 'img',
149
+ attribute: 'data-full-url',
150
+ },
151
+ link: {
152
+ type: 'string',
153
+ source: 'attribute',
154
+ selector: 'img',
155
+ attribute: 'data-link',
156
+ },
157
+ alt: {
158
+ type: 'string',
159
+ source: 'attribute',
160
+ selector: 'img',
161
+ attribute: 'alt',
162
+ default: '',
163
+ },
164
+ id: {
165
+ type: 'string',
166
+ source: 'attribute',
167
+ selector: 'img',
168
+ attribute: 'data-id',
169
+ },
170
+ caption: {
171
+ type: 'string',
172
+ source: 'html',
173
+ selector: '.blocks-gallery-item__caption',
240
174
  },
241
175
  },
242
- ids: {
243
- type: 'array',
244
- default: [],
245
- },
246
- columns: {
176
+ },
177
+ ids: {
178
+ type: 'array',
179
+ items: {
247
180
  type: 'number',
248
181
  },
249
- caption: {
250
- type: 'string',
251
- source: 'html',
252
- selector: '.blocks-gallery-caption',
253
- },
254
- imageCrop: {
255
- type: 'boolean',
256
- default: true,
257
- },
258
- linkTo: {
259
- type: 'string',
260
- default: 'none',
261
- },
182
+ default: [],
262
183
  },
263
- supports: {
264
- align: true,
184
+ columns: {
185
+ type: 'number',
186
+ minimum: 1,
187
+ maximum: 8,
265
188
  },
266
- isEligible( { ids } ) {
267
- return ids && ids.some( ( id ) => typeof id === 'string' );
189
+ caption: {
190
+ type: 'string',
191
+ source: 'html',
192
+ selector: '.blocks-gallery-caption',
268
193
  },
269
- migrate( attributes ) {
270
- return {
271
- ...attributes,
272
- ids: map( attributes.ids, ( id ) => {
273
- const parsedId = parseInt( id, 10 );
274
- return Number.isInteger( parsedId ) ? parsedId : null;
275
- } ),
276
- };
194
+ imageCrop: {
195
+ type: 'boolean',
196
+ default: true,
277
197
  },
278
- save( { attributes } ) {
279
- const {
280
- images,
281
- columns = defaultColumnsNumberV1( attributes ),
282
- imageCrop,
283
- caption,
284
- linkTo,
285
- } = attributes;
286
-
287
- return (
288
- <figure
289
- className={ `columns-${ columns } ${
290
- imageCrop ? 'is-cropped' : ''
291
- }` }
292
- >
293
- <ul className="blocks-gallery-grid">
294
- { images.map( ( image ) => {
295
- let href;
296
-
297
- switch ( linkTo ) {
298
- case 'media':
299
- href = image.fullUrl || image.url;
300
- break;
301
- case 'attachment':
302
- href = image.link;
303
- break;
304
- }
305
-
306
- const img = (
307
- <img
308
- src={ image.url }
309
- alt={ image.alt }
310
- data-id={ image.id }
311
- data-full-url={ image.fullUrl }
312
- data-link={ image.link }
313
- className={
314
- image.id
315
- ? `wp-image-${ image.id }`
316
- : null
317
- }
318
- />
319
- );
320
-
321
- return (
322
- <li
323
- key={ image.id || image.url }
324
- className="blocks-gallery-item"
325
- >
326
- <figure>
327
- { href ? (
328
- <a href={ href }>{ img }</a>
329
- ) : (
330
- img
331
- ) }
332
- { ! RichText.isEmpty(
333
- image.caption
334
- ) && (
335
- <RichText.Content
336
- tagName="figcaption"
337
- className="blocks-gallery-item__caption"
338
- value={ image.caption }
339
- />
340
- ) }
341
- </figure>
342
- </li>
343
- );
344
- } ) }
345
- </ul>
346
- { ! RichText.isEmpty( caption ) && (
347
- <RichText.Content
348
- tagName="figcaption"
349
- className="blocks-gallery-caption"
350
- value={ caption }
351
- />
352
- ) }
353
- </figure>
354
- );
198
+ linkTo: {
199
+ type: 'string',
355
200
  },
356
- },
357
- {
358
- attributes: {
359
- images: {
360
- type: 'array',
361
- default: [],
362
- source: 'query',
363
- selector: 'ul.wp-block-gallery .blocks-gallery-item',
364
- query: {
365
- url: {
366
- source: 'attribute',
367
- selector: 'img',
368
- attribute: 'src',
369
- },
370
- fullUrl: {
371
- source: 'attribute',
372
- selector: 'img',
373
- attribute: 'data-full-url',
374
- },
375
- alt: {
376
- source: 'attribute',
377
- selector: 'img',
378
- attribute: 'alt',
379
- default: '',
380
- },
381
- id: {
382
- source: 'attribute',
383
- selector: 'img',
384
- attribute: 'data-id',
385
- },
386
- link: {
387
- source: 'attribute',
388
- selector: 'img',
389
- attribute: 'data-link',
390
- },
391
- caption: {
392
- type: 'array',
393
- source: 'children',
394
- selector: 'figcaption',
395
- },
396
- },
397
- },
398
- ids: {
399
- type: 'array',
400
- default: [],
401
- },
402
- columns: {
403
- type: 'number',
404
- },
405
- imageCrop: {
406
- type: 'boolean',
407
- default: true,
408
- },
409
- linkTo: {
410
- type: 'string',
411
- default: 'none',
412
- },
201
+ sizeSlug: {
202
+ type: 'string',
203
+ default: 'large',
413
204
  },
414
- supports: {
415
- align: true,
416
- },
417
- save( { attributes } ) {
418
- const {
419
- images,
420
- columns = defaultColumnsNumberV1( attributes ),
421
- imageCrop,
422
- linkTo,
423
- } = attributes;
424
- return (
425
- <ul
426
- className={ `columns-${ columns } ${
427
- imageCrop ? 'is-cropped' : ''
428
- }` }
429
- >
205
+ },
206
+ supports: {
207
+ anchor: true,
208
+ align: true,
209
+ },
210
+ save( { attributes } ) {
211
+ const {
212
+ images,
213
+ columns = defaultColumnsNumberV1( attributes ),
214
+ imageCrop,
215
+ caption,
216
+ linkTo,
217
+ } = attributes;
218
+ const className = `columns-${ columns } ${
219
+ imageCrop ? 'is-cropped' : ''
220
+ }`;
221
+
222
+ return (
223
+ <figure { ...useBlockProps.save( { className } ) }>
224
+ <ul className="blocks-gallery-grid">
430
225
  { images.map( ( image ) => {
431
226
  let href;
432
227
 
433
228
  switch ( linkTo ) {
434
- case 'media':
229
+ case DEPRECATED_LINK_DESTINATION_MEDIA:
435
230
  href = image.fullUrl || image.url;
436
231
  break;
437
- case 'attachment':
232
+ case DEPRECATED_LINK_DESTINATION_ATTACHMENT:
438
233
  href = image.link;
439
234
  break;
440
235
  }
@@ -463,116 +258,159 @@ const deprecated = [
463
258
  ) : (
464
259
  img
465
260
  ) }
466
- { image.caption &&
467
- image.caption.length > 0 && (
468
- <RichText.Content
469
- tagName="figcaption"
470
- value={ image.caption }
471
- />
472
- ) }
261
+ { ! RichText.isEmpty( image.caption ) && (
262
+ <RichText.Content
263
+ tagName="figcaption"
264
+ className="blocks-gallery-item__caption"
265
+ value={ image.caption }
266
+ />
267
+ ) }
473
268
  </figure>
474
269
  </li>
475
270
  );
476
271
  } ) }
477
272
  </ul>
478
- );
479
- },
273
+ { ! RichText.isEmpty( caption ) && (
274
+ <RichText.Content
275
+ tagName="figcaption"
276
+ className="blocks-gallery-caption"
277
+ value={ caption }
278
+ />
279
+ ) }
280
+ </figure>
281
+ );
480
282
  },
481
- {
482
- attributes: {
483
- images: {
484
- type: 'array',
485
- default: [],
486
- source: 'query',
487
- selector: 'ul.wp-block-gallery .blocks-gallery-item',
488
- query: {
489
- url: {
490
- source: 'attribute',
491
- selector: 'img',
492
- attribute: 'src',
493
- },
494
- alt: {
495
- source: 'attribute',
496
- selector: 'img',
497
- attribute: 'alt',
498
- default: '',
499
- },
500
- id: {
501
- source: 'attribute',
502
- selector: 'img',
503
- attribute: 'data-id',
504
- },
505
- link: {
506
- source: 'attribute',
507
- selector: 'img',
508
- attribute: 'data-link',
509
- },
510
- caption: {
511
- type: 'array',
512
- source: 'children',
513
- selector: 'figcaption',
514
- },
283
+ migrate( attributes ) {
284
+ if ( isGalleryV2Enabled() ) {
285
+ return runV2Migration( attributes );
286
+ }
287
+
288
+ return attributes;
289
+ },
290
+ };
291
+ const v5 = {
292
+ attributes: {
293
+ images: {
294
+ type: 'array',
295
+ default: [],
296
+ source: 'query',
297
+ selector: '.blocks-gallery-item',
298
+ query: {
299
+ url: {
300
+ type: 'string',
301
+ source: 'attribute',
302
+ selector: 'img',
303
+ attribute: 'src',
304
+ },
305
+ fullUrl: {
306
+ type: 'string',
307
+ source: 'attribute',
308
+ selector: 'img',
309
+ attribute: 'data-full-url',
310
+ },
311
+ link: {
312
+ type: 'string',
313
+ source: 'attribute',
314
+ selector: 'img',
315
+ attribute: 'data-link',
316
+ },
317
+ alt: {
318
+ type: 'string',
319
+ source: 'attribute',
320
+ selector: 'img',
321
+ attribute: 'alt',
322
+ default: '',
323
+ },
324
+ id: {
325
+ type: 'string',
326
+ source: 'attribute',
327
+ selector: 'img',
328
+ attribute: 'data-id',
329
+ },
330
+ caption: {
331
+ type: 'string',
332
+ source: 'html',
333
+ selector: '.blocks-gallery-item__caption',
515
334
  },
516
335
  },
517
- columns: {
336
+ },
337
+ ids: {
338
+ type: 'array',
339
+ items: {
518
340
  type: 'number',
519
341
  },
520
- imageCrop: {
521
- type: 'boolean',
522
- default: true,
523
- },
524
- linkTo: {
525
- type: 'string',
526
- default: 'none',
527
- },
342
+ default: [],
528
343
  },
529
- isEligible( { images, ids } ) {
530
- return (
531
- images &&
532
- images.length > 0 &&
533
- ( ( ! ids && images ) ||
534
- ( ids && images && ids.length !== images.length ) ||
535
- some( images, ( id, index ) => {
536
- if ( ! id && ids[ index ] !== null ) {
537
- return true;
538
- }
539
- return parseInt( id, 10 ) !== ids[ index ];
540
- } ) )
541
- );
344
+ columns: {
345
+ type: 'number',
346
+ minimum: 1,
347
+ maximum: 8,
542
348
  },
543
- migrate( attributes ) {
544
- return {
545
- ...attributes,
546
- ids: map( attributes.images, ( { id } ) => {
547
- if ( ! id ) {
548
- return null;
549
- }
550
- return parseInt( id, 10 );
551
- } ),
552
- };
349
+ caption: {
350
+ type: 'string',
351
+ source: 'html',
352
+ selector: '.blocks-gallery-caption',
353
+ },
354
+ imageCrop: {
355
+ type: 'boolean',
356
+ default: true,
357
+ },
358
+ linkTo: {
359
+ type: 'string',
360
+ default: 'none',
553
361
  },
554
- supports: {
555
- align: true,
556
- },
557
- save( { attributes } ) {
558
- const {
559
- images,
560
- columns = defaultColumnsNumberV1( attributes ),
561
- imageCrop,
562
- linkTo,
563
- } = attributes;
564
- return (
565
- <ul
566
- className={ `columns-${ columns } ${
567
- imageCrop ? 'is-cropped' : ''
568
- }` }
569
- >
362
+ sizeSlug: {
363
+ type: 'string',
364
+ default: 'large',
365
+ },
366
+ },
367
+ supports: {
368
+ align: true,
369
+ },
370
+ isEligible( { linkTo } ) {
371
+ return ! linkTo || linkTo === 'attachment' || linkTo === 'media';
372
+ },
373
+ migrate( attributes ) {
374
+ if ( isGalleryV2Enabled() ) {
375
+ return runV2Migration( attributes );
376
+ }
377
+
378
+ let linkTo = attributes.linkTo;
379
+
380
+ if ( ! attributes.linkTo ) {
381
+ linkTo = 'none';
382
+ } else if ( attributes.linkTo === 'attachment' ) {
383
+ linkTo = 'post';
384
+ } else if ( attributes.linkTo === 'media' ) {
385
+ linkTo = 'file';
386
+ }
387
+ return {
388
+ ...attributes,
389
+ linkTo,
390
+ };
391
+ },
392
+ save( { attributes } ) {
393
+ const {
394
+ images,
395
+ columns = defaultColumnsNumberV1( attributes ),
396
+ imageCrop,
397
+ caption,
398
+ linkTo,
399
+ } = attributes;
400
+
401
+ return (
402
+ <figure
403
+ className={ `columns-${ columns } ${
404
+ imageCrop ? 'is-cropped' : ''
405
+ }` }
406
+ >
407
+ <ul className="blocks-gallery-grid">
570
408
  { images.map( ( image ) => {
571
409
  let href;
572
410
 
573
411
  switch ( linkTo ) {
574
412
  case 'media':
575
- href = image.url;
413
+ href = image.fullUrl || image.url;
576
414
  break;
577
415
  case 'attachment':
578
416
  href = image.link;
@@ -584,6 +422,7 @@ const deprecated = [
584
422
  src={ image.url }
585
423
  alt={ image.alt }
586
424
  data-id={ image.id }
425
+ data-full-url={ image.fullUrl }
587
426
  data-link={ image.link }
588
427
  className={
589
428
  image.id ? `wp-image-${ image.id }` : null
@@ -602,84 +441,133 @@ const deprecated = [
602
441
  ) : (
603
442
  img
604
443
  ) }
605
- { image.caption &&
606
- image.caption.length > 0 && (
607
- <RichText.Content
608
- tagName="figcaption"
609
- value={ image.caption }
610
- />
611
- ) }
444
+ { ! RichText.isEmpty( image.caption ) && (
445
+ <RichText.Content
446
+ tagName="figcaption"
447
+ className="blocks-gallery-item__caption"
448
+ value={ image.caption }
449
+ />
450
+ ) }
612
451
  </figure>
613
452
  </li>
614
453
  );
615
454
  } ) }
616
455
  </ul>
617
- );
618
- },
456
+ { ! RichText.isEmpty( caption ) && (
457
+ <RichText.Content
458
+ tagName="figcaption"
459
+ className="blocks-gallery-caption"
460
+ value={ caption }
461
+ />
462
+ ) }
463
+ </figure>
464
+ );
619
465
  },
620
- {
621
- attributes: {
622
- images: {
623
- type: 'array',
624
- default: [],
625
- source: 'query',
626
- selector:
627
- 'div.wp-block-gallery figure.blocks-gallery-image img',
628
- query: {
629
- url: {
630
- source: 'attribute',
631
- attribute: 'src',
632
- },
633
- alt: {
634
- source: 'attribute',
635
- attribute: 'alt',
636
- default: '',
637
- },
638
- id: {
639
- source: 'attribute',
640
- attribute: 'data-id',
641
- },
466
+ };
467
+
468
+ const v4 = {
469
+ attributes: {
470
+ images: {
471
+ type: 'array',
472
+ default: [],
473
+ source: 'query',
474
+ selector: '.blocks-gallery-item',
475
+ query: {
476
+ url: {
477
+ source: 'attribute',
478
+ selector: 'img',
479
+ attribute: 'src',
480
+ },
481
+ fullUrl: {
482
+ source: 'attribute',
483
+ selector: 'img',
484
+ attribute: 'data-full-url',
485
+ },
486
+ link: {
487
+ source: 'attribute',
488
+ selector: 'img',
489
+ attribute: 'data-link',
490
+ },
491
+ alt: {
492
+ source: 'attribute',
493
+ selector: 'img',
494
+ attribute: 'alt',
495
+ default: '',
496
+ },
497
+ id: {
498
+ source: 'attribute',
499
+ selector: 'img',
500
+ attribute: 'data-id',
501
+ },
502
+ caption: {
503
+ type: 'string',
504
+ source: 'html',
505
+ selector: '.blocks-gallery-item__caption',
642
506
  },
643
- },
644
- columns: {
645
- type: 'number',
646
- },
647
- imageCrop: {
648
- type: 'boolean',
649
- default: true,
650
- },
651
- linkTo: {
652
- type: 'string',
653
- default: 'none',
654
- },
655
- align: {
656
- type: 'string',
657
- default: 'none',
658
507
  },
659
508
  },
660
- supports: {
661
- align: true,
662
- },
663
- save( { attributes } ) {
664
- const {
665
- images,
666
- columns = defaultColumnsNumberV1( attributes ),
667
- align,
668
- imageCrop,
669
- linkTo,
670
- } = attributes;
671
- const className = classnames( `columns-${ columns }`, {
672
- alignnone: align === 'none',
673
- 'is-cropped': imageCrop,
674
- } );
675
- return (
676
- <div className={ className }>
509
+ ids: {
510
+ type: 'array',
511
+ default: [],
512
+ },
513
+ columns: {
514
+ type: 'number',
515
+ },
516
+ caption: {
517
+ type: 'string',
518
+ source: 'html',
519
+ selector: '.blocks-gallery-caption',
520
+ },
521
+ imageCrop: {
522
+ type: 'boolean',
523
+ default: true,
524
+ },
525
+ linkTo: {
526
+ type: 'string',
527
+ default: 'none',
528
+ },
529
+ },
530
+ supports: {
531
+ align: true,
532
+ },
533
+ isEligible( { ids } ) {
534
+ return ids && ids.some( ( id ) => typeof id === 'string' );
535
+ },
536
+ migrate( attributes ) {
537
+ if ( isGalleryV2Enabled() ) {
538
+ return runV2Migration( attributes );
539
+ }
540
+
541
+ return {
542
+ ...attributes,
543
+ ids: map( attributes.ids, ( id ) => {
544
+ const parsedId = parseInt( id, 10 );
545
+ return Number.isInteger( parsedId ) ? parsedId : null;
546
+ } ),
547
+ };
548
+ },
549
+ save( { attributes } ) {
550
+ const {
551
+ images,
552
+ columns = defaultColumnsNumberV1( attributes ),
553
+ imageCrop,
554
+ caption,
555
+ linkTo,
556
+ } = attributes;
557
+
558
+ return (
559
+ <figure
560
+ className={ `columns-${ columns } ${
561
+ imageCrop ? 'is-cropped' : ''
562
+ }` }
563
+ >
564
+ <ul className="blocks-gallery-grid">
677
565
  { images.map( ( image ) => {
678
566
  let href;
679
567
 
680
568
  switch ( linkTo ) {
681
569
  case 'media':
682
- href = image.url;
570
+ href = image.fullUrl || image.url;
683
571
  break;
684
572
  case 'attachment':
685
573
  href = image.link;
@@ -691,22 +579,406 @@ const deprecated = [
691
579
  src={ image.url }
692
580
  alt={ image.alt }
693
581
  data-id={ image.id }
582
+ data-full-url={ image.fullUrl }
583
+ data-link={ image.link }
584
+ className={
585
+ image.id ? `wp-image-${ image.id }` : null
586
+ }
694
587
  />
695
588
  );
696
589
 
697
590
  return (
698
- <figure
591
+ <li
699
592
  key={ image.id || image.url }
700
- className="blocks-gallery-image"
593
+ className="blocks-gallery-item"
701
594
  >
702
- { href ? <a href={ href }>{ img }</a> : img }
703
- </figure>
595
+ <figure>
596
+ { href ? (
597
+ <a href={ href }>{ img }</a>
598
+ ) : (
599
+ img
600
+ ) }
601
+ { ! RichText.isEmpty( image.caption ) && (
602
+ <RichText.Content
603
+ tagName="figcaption"
604
+ className="blocks-gallery-item__caption"
605
+ value={ image.caption }
606
+ />
607
+ ) }
608
+ </figure>
609
+ </li>
704
610
  );
705
611
  } ) }
706
- </div>
707
- );
612
+ </ul>
613
+ { ! RichText.isEmpty( caption ) && (
614
+ <RichText.Content
615
+ tagName="figcaption"
616
+ className="blocks-gallery-caption"
617
+ value={ caption }
618
+ />
619
+ ) }
620
+ </figure>
621
+ );
622
+ },
623
+ };
624
+ const v3 = {
625
+ attributes: {
626
+ images: {
627
+ type: 'array',
628
+ default: [],
629
+ source: 'query',
630
+ selector: 'ul.wp-block-gallery .blocks-gallery-item',
631
+ query: {
632
+ url: {
633
+ source: 'attribute',
634
+ selector: 'img',
635
+ attribute: 'src',
636
+ },
637
+ fullUrl: {
638
+ source: 'attribute',
639
+ selector: 'img',
640
+ attribute: 'data-full-url',
641
+ },
642
+ alt: {
643
+ source: 'attribute',
644
+ selector: 'img',
645
+ attribute: 'alt',
646
+ default: '',
647
+ },
648
+ id: {
649
+ source: 'attribute',
650
+ selector: 'img',
651
+ attribute: 'data-id',
652
+ },
653
+ link: {
654
+ source: 'attribute',
655
+ selector: 'img',
656
+ attribute: 'data-link',
657
+ },
658
+ caption: {
659
+ type: 'array',
660
+ source: 'children',
661
+ selector: 'figcaption',
662
+ },
663
+ },
664
+ },
665
+ ids: {
666
+ type: 'array',
667
+ default: [],
708
668
  },
669
+ columns: {
670
+ type: 'number',
671
+ },
672
+ imageCrop: {
673
+ type: 'boolean',
674
+ default: true,
675
+ },
676
+ linkTo: {
677
+ type: 'string',
678
+ default: 'none',
679
+ },
680
+ },
681
+ supports: {
682
+ align: true,
683
+ },
684
+ save( { attributes } ) {
685
+ const {
686
+ images,
687
+ columns = defaultColumnsNumberV1( attributes ),
688
+ imageCrop,
689
+ linkTo,
690
+ } = attributes;
691
+ return (
692
+ <ul
693
+ className={ `columns-${ columns } ${
694
+ imageCrop ? 'is-cropped' : ''
695
+ }` }
696
+ >
697
+ { images.map( ( image ) => {
698
+ let href;
699
+
700
+ switch ( linkTo ) {
701
+ case 'media':
702
+ href = image.fullUrl || image.url;
703
+ break;
704
+ case 'attachment':
705
+ href = image.link;
706
+ break;
707
+ }
708
+
709
+ const img = (
710
+ <img
711
+ src={ image.url }
712
+ alt={ image.alt }
713
+ data-id={ image.id }
714
+ data-full-url={ image.fullUrl }
715
+ data-link={ image.link }
716
+ className={
717
+ image.id ? `wp-image-${ image.id }` : null
718
+ }
719
+ />
720
+ );
721
+
722
+ return (
723
+ <li
724
+ key={ image.id || image.url }
725
+ className="blocks-gallery-item"
726
+ >
727
+ <figure>
728
+ { href ? <a href={ href }>{ img }</a> : img }
729
+ { image.caption && image.caption.length > 0 && (
730
+ <RichText.Content
731
+ tagName="figcaption"
732
+ value={ image.caption }
733
+ />
734
+ ) }
735
+ </figure>
736
+ </li>
737
+ );
738
+ } ) }
739
+ </ul>
740
+ );
741
+ },
742
+ migrate( attributes ) {
743
+ if ( isGalleryV2Enabled() ) {
744
+ return runV2Migration( attributes );
745
+ }
746
+ return attributes;
747
+ },
748
+ };
749
+ const v2 = {
750
+ attributes: {
751
+ images: {
752
+ type: 'array',
753
+ default: [],
754
+ source: 'query',
755
+ selector: 'ul.wp-block-gallery .blocks-gallery-item',
756
+ query: {
757
+ url: {
758
+ source: 'attribute',
759
+ selector: 'img',
760
+ attribute: 'src',
761
+ },
762
+ alt: {
763
+ source: 'attribute',
764
+ selector: 'img',
765
+ attribute: 'alt',
766
+ default: '',
767
+ },
768
+ id: {
769
+ source: 'attribute',
770
+ selector: 'img',
771
+ attribute: 'data-id',
772
+ },
773
+ link: {
774
+ source: 'attribute',
775
+ selector: 'img',
776
+ attribute: 'data-link',
777
+ },
778
+ caption: {
779
+ type: 'array',
780
+ source: 'children',
781
+ selector: 'figcaption',
782
+ },
783
+ },
784
+ },
785
+ columns: {
786
+ type: 'number',
787
+ },
788
+ imageCrop: {
789
+ type: 'boolean',
790
+ default: true,
791
+ },
792
+ linkTo: {
793
+ type: 'string',
794
+ default: 'none',
795
+ },
796
+ },
797
+ isEligible( { images, ids } ) {
798
+ return (
799
+ images &&
800
+ images.length > 0 &&
801
+ ( ( ! ids && images ) ||
802
+ ( ids && images && ids.length !== images.length ) ||
803
+ some( images, ( id, index ) => {
804
+ if ( ! id && ids[ index ] !== null ) {
805
+ return true;
806
+ }
807
+ return parseInt( id, 10 ) !== ids[ index ];
808
+ } ) )
809
+ );
810
+ },
811
+ migrate( attributes ) {
812
+ if ( isGalleryV2Enabled() ) {
813
+ return runV2Migration( attributes );
814
+ }
815
+ return {
816
+ ...attributes,
817
+ ids: map( attributes.images, ( { id } ) => {
818
+ if ( ! id ) {
819
+ return null;
820
+ }
821
+ return parseInt( id, 10 );
822
+ } ),
823
+ };
824
+ },
825
+ supports: {
826
+ align: true,
827
+ },
828
+ save( { attributes } ) {
829
+ const {
830
+ images,
831
+ columns = defaultColumnsNumberV1( attributes ),
832
+ imageCrop,
833
+ linkTo,
834
+ } = attributes;
835
+ return (
836
+ <ul
837
+ className={ `columns-${ columns } ${
838
+ imageCrop ? 'is-cropped' : ''
839
+ }` }
840
+ >
841
+ { images.map( ( image ) => {
842
+ let href;
843
+
844
+ switch ( linkTo ) {
845
+ case 'media':
846
+ href = image.url;
847
+ break;
848
+ case 'attachment':
849
+ href = image.link;
850
+ break;
851
+ }
852
+
853
+ const img = (
854
+ <img
855
+ src={ image.url }
856
+ alt={ image.alt }
857
+ data-id={ image.id }
858
+ data-link={ image.link }
859
+ className={
860
+ image.id ? `wp-image-${ image.id }` : null
861
+ }
862
+ />
863
+ );
864
+
865
+ return (
866
+ <li
867
+ key={ image.id || image.url }
868
+ className="blocks-gallery-item"
869
+ >
870
+ <figure>
871
+ { href ? <a href={ href }>{ img }</a> : img }
872
+ { image.caption && image.caption.length > 0 && (
873
+ <RichText.Content
874
+ tagName="figcaption"
875
+ value={ image.caption }
876
+ />
877
+ ) }
878
+ </figure>
879
+ </li>
880
+ );
881
+ } ) }
882
+ </ul>
883
+ );
884
+ },
885
+ };
886
+
887
+ const v1 = {
888
+ attributes: {
889
+ images: {
890
+ type: 'array',
891
+ default: [],
892
+ source: 'query',
893
+ selector: 'div.wp-block-gallery figure.blocks-gallery-image img',
894
+ query: {
895
+ url: {
896
+ source: 'attribute',
897
+ attribute: 'src',
898
+ },
899
+ alt: {
900
+ source: 'attribute',
901
+ attribute: 'alt',
902
+ default: '',
903
+ },
904
+ id: {
905
+ source: 'attribute',
906
+ attribute: 'data-id',
907
+ },
908
+ },
909
+ },
910
+ columns: {
911
+ type: 'number',
912
+ },
913
+ imageCrop: {
914
+ type: 'boolean',
915
+ default: true,
916
+ },
917
+ linkTo: {
918
+ type: 'string',
919
+ default: 'none',
920
+ },
921
+ align: {
922
+ type: 'string',
923
+ default: 'none',
924
+ },
925
+ },
926
+ supports: {
927
+ align: true,
928
+ },
929
+ save( { attributes } ) {
930
+ const {
931
+ images,
932
+ columns = defaultColumnsNumberV1( attributes ),
933
+ align,
934
+ imageCrop,
935
+ linkTo,
936
+ } = attributes;
937
+ const className = classnames( `columns-${ columns }`, {
938
+ alignnone: align === 'none',
939
+ 'is-cropped': imageCrop,
940
+ } );
941
+ return (
942
+ <div className={ className }>
943
+ { images.map( ( image ) => {
944
+ let href;
945
+
946
+ switch ( linkTo ) {
947
+ case 'media':
948
+ href = image.url;
949
+ break;
950
+ case 'attachment':
951
+ href = image.link;
952
+ break;
953
+ }
954
+
955
+ const img = (
956
+ <img
957
+ src={ image.url }
958
+ alt={ image.alt }
959
+ data-id={ image.id }
960
+ />
961
+ );
962
+
963
+ return (
964
+ <figure
965
+ key={ image.id || image.url }
966
+ className="blocks-gallery-image"
967
+ >
968
+ { href ? <a href={ href }>{ img }</a> : img }
969
+ </figure>
970
+ );
971
+ } ) }
972
+ </div>
973
+ );
974
+ },
975
+ migrate( attributes ) {
976
+ if ( isGalleryV2Enabled() ) {
977
+ return runV2Migration( attributes );
978
+ }
979
+
980
+ return attributes;
709
981
  },
710
- ];
982
+ };
711
983
 
712
- export default deprecated;
984
+ export default [ v6, v5, v4, v3, v2, v1 ];