-
Notifications
You must be signed in to change notification settings - Fork 4.2k
/
save.js
52 lines (46 loc) · 1.2 KB
/
save.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* External dependencies
*/
import classnames from 'classnames';
/**
* WordPress dependencies
*/
import {
RichText,
useBlockProps,
useInnerBlocksProps,
__experimentalGetElementClassName,
} from '@wordpress/block-editor';
/**
* Internal dependencies
*/
import saveWithoutInnerBlocks from './v1/save';
import { isGalleryV2Enabled } from './shared';
export default function saveWithInnerBlocks( { attributes } ) {
if ( ! isGalleryV2Enabled() ) {
return saveWithoutInnerBlocks( { attributes } );
}
const { caption, columns, imageCrop } = attributes;
const className = classnames( 'has-nested-images', {
[ `columns-${ columns }` ]: columns !== undefined,
[ `columns-default` ]: columns === undefined,
'is-cropped': imageCrop,
} );
const blockProps = useBlockProps.save( { className } );
const innerBlocksProps = useInnerBlocksProps.save( blockProps );
return (
<figure { ...innerBlocksProps }>
{ innerBlocksProps.children }
{ ! RichText.isEmpty( caption ) && (
<RichText.Content
tagName="figcaption"
className={ classnames(
'blocks-gallery-caption',
__experimentalGetElementClassName( 'caption' )
) }
value={ caption }
/>
) }
</figure>
);
}