@wordpress/block-library 6.0.11 → 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.
- package/build/cover/edit.js +1 -0
- package/build/cover/edit.js.map +1 -1
- package/build/gallery/deprecated.js +314 -26
- package/build/gallery/deprecated.js.map +1 -1
- package/build/gallery/edit-wrapper.js +10 -27
- package/build/gallery/edit-wrapper.js.map +1 -1
- package/build/gallery/edit.js +10 -12
- package/build/gallery/edit.js.map +1 -1
- package/build/gallery/save.js +3 -3
- package/build/gallery/save.js.map +1 -1
- package/build/gallery/shared.js +24 -0
- package/build/gallery/shared.js.map +1 -1
- package/build/gallery/transforms.js +8 -22
- package/build/gallery/transforms.js.map +1 -1
- package/build/gallery/use-mobile-warning.js +1 -1
- package/build/gallery/use-mobile-warning.js.map +1 -1
- package/build/gallery/v1/edit.js +2 -21
- package/build/gallery/v1/edit.js.map +1 -1
- package/build/navigation/edit/index.js +1 -0
- package/build/navigation/edit/index.js.map +1 -1
- package/build/navigation/edit/inner-blocks.js +0 -4
- package/build/navigation/edit/inner-blocks.js.map +1 -1
- package/build/navigation-submenu/edit.js +4 -0
- package/build/navigation-submenu/edit.js.map +1 -1
- package/build/query-pagination/index.js +1 -1
- package/build/query-pagination-next/index.js +1 -1
- package/build/query-pagination-numbers/index.js +1 -1
- package/build/query-pagination-previous/index.js +1 -1
- package/build/separator/separator-settings.js +1 -0
- package/build/separator/separator-settings.js.map +1 -1
- package/build/social-links/edit.js +1 -0
- package/build/social-links/edit.js.map +1 -1
- package/build-module/cover/edit.js +1 -0
- package/build-module/cover/edit.js.map +1 -1
- package/build-module/gallery/deprecated.js +309 -27
- package/build-module/gallery/deprecated.js.map +1 -1
- package/build-module/gallery/edit-wrapper.js +7 -27
- package/build-module/gallery/edit-wrapper.js.map +1 -1
- package/build-module/gallery/edit.js +10 -12
- package/build-module/gallery/edit.js.map +1 -1
- package/build-module/gallery/save.js +2 -3
- package/build-module/gallery/save.js.map +1 -1
- package/build-module/gallery/shared.js +22 -0
- package/build-module/gallery/shared.js.map +1 -1
- package/build-module/gallery/transforms.js +9 -21
- package/build-module/gallery/transforms.js.map +1 -1
- package/build-module/gallery/use-mobile-warning.js +1 -1
- package/build-module/gallery/use-mobile-warning.js.map +1 -1
- package/build-module/gallery/v1/edit.js +4 -22
- package/build-module/gallery/v1/edit.js.map +1 -1
- package/build-module/navigation/edit/index.js +1 -0
- package/build-module/navigation/edit/index.js.map +1 -1
- package/build-module/navigation/edit/inner-blocks.js +0 -4
- package/build-module/navigation/edit/inner-blocks.js.map +1 -1
- package/build-module/navigation-submenu/edit.js +4 -0
- package/build-module/navigation-submenu/edit.js.map +1 -1
- package/build-module/query-pagination/index.js +1 -1
- package/build-module/query-pagination-next/index.js +1 -1
- package/build-module/query-pagination-numbers/index.js +1 -1
- package/build-module/query-pagination-previous/index.js +1 -1
- package/build-module/separator/separator-settings.js +1 -0
- package/build-module/separator/separator-settings.js.map +1 -1
- package/build-module/social-links/edit.js +1 -0
- package/build-module/social-links/edit.js.map +1 -1
- package/build-style/columns/editor-rtl.css +1 -1
- package/build-style/columns/editor.css +1 -1
- package/build-style/editor-rtl.css +1 -1
- package/build-style/editor.css +1 -1
- package/build-style/navigation/style-rtl.css +4 -1
- package/build-style/navigation/style.css +4 -1
- package/build-style/style-rtl.css +4 -1
- package/build-style/style.css +4 -1
- package/package.json +8 -8
- package/src/columns/editor.scss +3 -2
- package/src/cover/edit.js +1 -0
- package/src/gallery/deprecated.js +831 -559
- package/src/gallery/edit-wrapper.js +7 -27
- package/src/gallery/edit.js +10 -12
- package/src/gallery/save.js +2 -1
- package/src/gallery/shared.js +24 -0
- package/src/gallery/transforms.js +9 -27
- package/src/gallery/use-mobile-warning.js +1 -1
- package/src/gallery/v1/edit.js +1 -28
- package/src/navigation/edit/index.js +1 -0
- package/src/navigation/edit/inner-blocks.js +0 -5
- package/src/navigation/index.php +149 -18
- package/src/navigation/style.scss +4 -1
- package/src/navigation-submenu/edit.js +6 -0
- package/src/navigation-submenu/index.php +30 -45
- package/src/page-list/index.php +5 -9
- package/src/query-pagination/block.json +1 -1
- package/src/query-pagination-next/block.json +1 -1
- package/src/query-pagination-numbers/block.json +1 -1
- package/src/query-pagination-previous/block.json +1 -1
- package/src/separator/separator-settings.js +1 -0
- package/src/social-links/edit.js +1 -0
- package/src/template-part/index.php +36 -0
- package/build/gallery/v1/update-gallery-modal.js +0 -114
- package/build/gallery/v1/update-gallery-modal.js.map +0 -1
- package/build-module/gallery/v1/update-gallery-modal.js +0 -97
- package/build-module/gallery/v1/update-gallery-modal.js.map +0 -1
- package/src/gallery/v1/update-gallery-modal.js +0 -97
|
@@ -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
|
|
37
|
+
return Math.min( 3, attributes?.images?.length );
|
|
23
38
|
}
|
|
24
39
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
119
|
-
|
|
57
|
+
href: image?.source_url || image?.url, // eslint-disable-line camelcase
|
|
58
|
+
linkDestination: LINK_DESTINATION_MEDIA,
|
|
120
59
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
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
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
columns: {
|
|
176
|
+
},
|
|
177
|
+
ids: {
|
|
178
|
+
type: 'array',
|
|
179
|
+
items: {
|
|
247
180
|
type: 'number',
|
|
248
181
|
},
|
|
249
|
-
|
|
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
|
-
|
|
264
|
-
|
|
184
|
+
columns: {
|
|
185
|
+
type: 'number',
|
|
186
|
+
minimum: 1,
|
|
187
|
+
maximum: 8,
|
|
265
188
|
},
|
|
266
|
-
|
|
267
|
-
|
|
189
|
+
caption: {
|
|
190
|
+
type: 'string',
|
|
191
|
+
source: 'html',
|
|
192
|
+
selector: '.blocks-gallery-caption',
|
|
268
193
|
},
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
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
|
-
|
|
279
|
-
|
|
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
|
-
|
|
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
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
|
229
|
+
case DEPRECATED_LINK_DESTINATION_MEDIA:
|
|
435
230
|
href = image.fullUrl || image.url;
|
|
436
231
|
break;
|
|
437
|
-
case
|
|
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
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
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
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
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
|
-
|
|
336
|
+
},
|
|
337
|
+
ids: {
|
|
338
|
+
type: 'array',
|
|
339
|
+
items: {
|
|
518
340
|
type: 'number',
|
|
519
341
|
},
|
|
520
|
-
|
|
521
|
-
type: 'boolean',
|
|
522
|
-
default: true,
|
|
523
|
-
},
|
|
524
|
-
linkTo: {
|
|
525
|
-
type: 'string',
|
|
526
|
-
default: 'none',
|
|
527
|
-
},
|
|
342
|
+
default: [],
|
|
528
343
|
},
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
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
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
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
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
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
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
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
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
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
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
-
<
|
|
591
|
+
<li
|
|
699
592
|
key={ image.id || image.url }
|
|
700
|
-
className="blocks-gallery-
|
|
593
|
+
className="blocks-gallery-item"
|
|
701
594
|
>
|
|
702
|
-
|
|
703
|
-
|
|
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
|
-
</
|
|
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
|
|
984
|
+
export default [ v6, v5, v4, v3, v2, v1 ];
|